2017-10-29 03:14:14 +01:00
|
|
|
const gulp = require('gulp'),
|
|
|
|
gulpif = require('gulp-if'),
|
2017-11-08 21:17:09 +01:00
|
|
|
filter = require('gulp-filter'),
|
2017-10-29 03:14:14 +01:00
|
|
|
replace = require('gulp-replace'),
|
2017-02-08 06:18:26 +01:00
|
|
|
googleWebFonts = require('gulp-google-webfonts'),
|
2017-08-31 21:07:39 +02:00
|
|
|
jeditor = require("gulp-json-editor"),
|
2017-08-31 21:55:39 +02:00
|
|
|
child = require('child_process'),
|
2017-09-07 16:42:25 +02:00
|
|
|
zip = require('gulp-zip'),
|
|
|
|
manifest = require('./src/manifest.json'),
|
2017-11-16 03:39:48 +01:00
|
|
|
xmlpoke = require('gulp-xmlpoke'),
|
2019-01-25 21:05:18 +01:00
|
|
|
del = require('del'),
|
|
|
|
fs = require('fs');
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2017-11-08 03:45:18 +01:00
|
|
|
const paths = {
|
2017-11-16 17:23:53 +01:00
|
|
|
build: './build/',
|
2017-11-08 03:45:18 +01:00
|
|
|
dist: './dist/',
|
2017-11-22 20:42:44 +01:00
|
|
|
coverage: './coverage/',
|
2019-01-25 21:05:18 +01:00
|
|
|
node_modules: './node_modules/',
|
2017-11-08 03:45:18 +01:00
|
|
|
popupDir: './src/popup/',
|
2019-08-22 14:51:08 +02:00
|
|
|
cssDir: './src/popup/css/',
|
|
|
|
safari: './src/safari/'
|
2017-11-08 03:45:18 +01:00
|
|
|
};
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2018-01-11 23:33:13 +01:00
|
|
|
const filters = {
|
|
|
|
fonts: [
|
|
|
|
'!build/popup/fonts/*',
|
|
|
|
'build/popup/fonts/Open_Sans*.woff',
|
2018-04-18 20:08:29 +02:00
|
|
|
'build/popup/fonts/fontawesome*.woff2',
|
2018-01-11 23:33:13 +01:00
|
|
|
'build/popup/fonts/fontawesome*.woff'
|
|
|
|
],
|
|
|
|
safari: [
|
2019-08-21 22:50:15 +02:00
|
|
|
'!build/safari/**/*'
|
|
|
|
],
|
2018-01-16 04:13:06 +01:00
|
|
|
webExt: [
|
2018-01-11 23:33:13 +01:00
|
|
|
'!build/manifest.json'
|
|
|
|
],
|
2018-01-16 04:13:06 +01:00
|
|
|
edge: [
|
2018-01-11 23:33:13 +01:00
|
|
|
'!build/edge/**/*'
|
2019-08-02 22:09:59 +02:00
|
|
|
],
|
|
|
|
nonSafariApp: [
|
|
|
|
'!build/background.html',
|
|
|
|
'!build/popup/index.html'
|
|
|
|
],
|
2018-01-11 23:33:13 +01:00
|
|
|
};
|
2017-11-16 03:39:48 +01:00
|
|
|
|
2017-11-22 22:51:33 +01:00
|
|
|
function buildString() {
|
2017-11-18 19:29:42 +01:00
|
|
|
var build = '';
|
2017-11-18 04:04:34 +01:00
|
|
|
if (process.env.APPVEYOR_BUILD_NUMBER && process.env.APPVEYOR_BUILD_NUMBER !== '') {
|
2017-11-18 19:29:42 +01:00
|
|
|
build = `-${process.env.APPVEYOR_BUILD_NUMBER}`;
|
2017-11-18 04:04:34 +01:00
|
|
|
}
|
2017-11-22 22:51:33 +01:00
|
|
|
return build;
|
|
|
|
}
|
2017-11-18 04:04:34 +01:00
|
|
|
|
2017-11-22 22:51:33 +01:00
|
|
|
function distFileName(browserName, ext) {
|
|
|
|
return `dist-${browserName}${buildString()}.${ext}`;
|
2017-11-18 04:04:34 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 03:14:14 +01:00
|
|
|
function dist(browserName, manifest) {
|
2017-11-16 17:23:53 +01:00
|
|
|
return gulp.src(paths.build + '**/*')
|
2018-01-16 04:13:06 +01:00
|
|
|
.pipe(filter(['**'].concat(filters.edge).concat(filters.fonts).concat(filters.safari)))
|
2018-04-14 04:29:31 +02:00
|
|
|
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'browser_' + browserName)))
|
2017-10-29 03:14:14 +01:00
|
|
|
.pipe(gulpif('manifest.json', jeditor(manifest)))
|
2017-11-18 04:04:34 +01:00
|
|
|
.pipe(zip(distFileName(browserName, 'zip')))
|
2017-11-16 17:23:53 +01:00
|
|
|
.pipe(gulp.dest(paths.dist));
|
2017-10-29 03:14:14 +01:00
|
|
|
}
|
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distFirefox() {
|
2017-11-08 21:42:13 +01:00
|
|
|
return dist('firefox', (manifest) => {
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest['-ms-preload'];
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2018-05-09 20:52:22 +02:00
|
|
|
removeShortcuts(manifest);
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distOpera() {
|
2017-11-08 21:42:13 +01:00
|
|
|
return dist('opera', (manifest) => {
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest['-ms-preload'];
|
|
|
|
delete manifest.applications;
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2018-05-09 20:52:22 +02:00
|
|
|
removeShortcuts(manifest);
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distChrome() {
|
2017-11-08 21:42:13 +01:00
|
|
|
return dist('chrome', (manifest) => {
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest['-ms-preload'];
|
|
|
|
delete manifest.applications;
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest.sidebar_action;
|
2017-12-04 15:15:28 +01:00
|
|
|
delete manifest.commands._execute_sidebar_action;
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2018-05-09 20:52:22 +02:00
|
|
|
function removeShortcuts(manifest) {
|
|
|
|
if (manifest.content_scripts && manifest.content_scripts.length > 1) {
|
|
|
|
const shortcutsScript = manifest.content_scripts[1];
|
|
|
|
if (shortcutsScript.js.indexOf('content/shortcuts.js') > -1) {
|
|
|
|
manifest.content_scripts.splice(1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-29 03:14:14 +01:00
|
|
|
// Since Edge extensions require makeappx to be run we temporarily store it in a folder.
|
2018-11-27 18:36:59 +01:00
|
|
|
function distEdge(cb) {
|
2017-11-16 17:23:53 +01:00
|
|
|
const edgePath = paths.dist + 'Edge/';
|
2017-10-29 03:14:14 +01:00
|
|
|
const extensionPath = edgePath + 'Extension/';
|
2017-11-18 04:04:34 +01:00
|
|
|
const fileName = distFileName('edge', 'appx');
|
|
|
|
const appxPath = paths.dist + fileName;
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2017-11-16 03:39:48 +01:00
|
|
|
return del([edgePath, appxPath])
|
2017-11-16 17:23:53 +01:00
|
|
|
.then(() => edgeCopyBuild(paths.build + '**/*', extensionPath))
|
2017-11-16 03:39:48 +01:00
|
|
|
.then(() => edgeCopyAssets('./store/windows/**/*', edgePath))
|
2017-11-08 21:42:13 +01:00
|
|
|
.then(() => {
|
2017-10-29 03:14:14 +01:00
|
|
|
// makeappx.exe must be in your system's path already
|
2019-08-26 18:15:52 +02:00
|
|
|
const proc = child.spawn('makeappx.exe', [
|
|
|
|
'pack',
|
|
|
|
'/h',
|
|
|
|
'SHA256',
|
|
|
|
'/d',
|
|
|
|
edgePath,
|
|
|
|
'/p',
|
|
|
|
appxPath]);
|
|
|
|
stdOutProc(proc);
|
|
|
|
return new Promise((resolve) => proc.on('close', resolve));
|
|
|
|
}).then(() => {
|
2017-11-08 21:42:13 +01:00
|
|
|
return cb;
|
|
|
|
}, () => {
|
|
|
|
return cb;
|
2017-10-29 03:14:14 +01:00
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2017-11-16 17:23:53 +01:00
|
|
|
function edgeCopyBuild(source, dest) {
|
2017-10-29 03:39:38 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
gulp.src(source)
|
|
|
|
.on('error', reject)
|
2018-01-11 23:33:13 +01:00
|
|
|
.pipe(filter(['**'].concat(filters.fonts).concat(filters.safari)))
|
2018-04-14 04:29:31 +02:00
|
|
|
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'browser_edge')))
|
2017-11-08 21:42:13 +01:00
|
|
|
.pipe(gulpif('manifest.json', jeditor((manifest) => {
|
2017-11-15 22:40:24 +01:00
|
|
|
delete manifest.applications;
|
|
|
|
delete manifest.sidebar_action;
|
2017-12-04 15:15:28 +01:00
|
|
|
delete manifest.commands._execute_sidebar_action;
|
2018-04-13 22:03:37 +02:00
|
|
|
delete manifest.content_security_policy;
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
})))
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-16 03:39:48 +01:00
|
|
|
function edgeCopyAssets(source, dest) {
|
2017-10-29 03:39:38 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
gulp.src(source)
|
|
|
|
.on('error', reject)
|
|
|
|
.pipe(gulpif('AppxManifest.xml', xmlpoke({
|
|
|
|
replacements: [{
|
|
|
|
xpath: '/p:Package/p:Identity/@Version',
|
|
|
|
value: manifest.version + '.0',
|
|
|
|
namespaces: {
|
|
|
|
'p': 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
})))
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
function distSafariMas(cb) {
|
|
|
|
return distSafariApp(cb, 'mas');
|
|
|
|
}
|
|
|
|
|
2019-10-02 15:30:56 +02:00
|
|
|
function distSafariMasDev(cb) {
|
|
|
|
return distSafariApp(cb, 'masdev');
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
function distSafariDmg(cb) {
|
|
|
|
return distSafariApp(cb, 'dmg');
|
|
|
|
}
|
|
|
|
|
|
|
|
function distSafariApp(cb, subBuildPath) {
|
|
|
|
const buildPath = paths.dist + 'Safari/' + subBuildPath + '/';
|
|
|
|
const builtAppexPath = buildPath + 'build/Release/safari.appex';
|
|
|
|
const builtAppexFrameworkPath = buildPath + 'build/Release/safari.appex/Contents/Frameworks/';
|
|
|
|
const entitlementsPath = paths.safari + 'safari/safari.entitlements';
|
2019-10-14 16:47:53 +02:00
|
|
|
var args = [
|
2019-10-02 15:30:56 +02:00
|
|
|
'--verbose',
|
|
|
|
'--force',
|
|
|
|
'-o',
|
|
|
|
'runtime',
|
|
|
|
'--sign',
|
2019-10-14 16:47:53 +02:00
|
|
|
'Developer ID Application: 8bit Solutions LLC',
|
2019-10-02 15:30:56 +02:00
|
|
|
'--entitlements',
|
|
|
|
entitlementsPath
|
|
|
|
];
|
2019-10-14 16:47:53 +02:00
|
|
|
if (subBuildPath !== 'dmg') {
|
|
|
|
args = [
|
|
|
|
'--verbose',
|
|
|
|
'--force',
|
|
|
|
'--sign',
|
|
|
|
subBuildPath === 'mas' ? '3rd Party Mac Developer Application: 8bit Solutions LLC' :
|
|
|
|
'C12A12E8595453C8B57028790FADB6AD426165AE',
|
|
|
|
'--entitlements',
|
|
|
|
entitlementsPath
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:28:12 +02:00
|
|
|
return del([buildPath + '**/*'])
|
|
|
|
.then(() => safariCopyAssets(paths.safari + '**/*', buildPath))
|
|
|
|
.then(() => safariCopyBuild(paths.build + '**/*', buildPath + 'safari/app'))
|
|
|
|
.then(() => {
|
|
|
|
const proc = child.spawn('xcodebuild', [
|
|
|
|
'-project',
|
|
|
|
buildPath + 'desktop.xcodeproj',
|
|
|
|
'-alltargets',
|
|
|
|
'-configuration',
|
|
|
|
'Release']);
|
|
|
|
stdOutProc(proc);
|
|
|
|
return new Promise((resolve) => proc.on('close', resolve));
|
|
|
|
}).then(() => {
|
|
|
|
const libs = fs.readdirSync(builtAppexFrameworkPath).filter((p) => p.endsWith('.dylib'))
|
|
|
|
.map((p) => builtAppexFrameworkPath + p);
|
|
|
|
const libPromises = [];
|
|
|
|
libs.forEach((i) => {
|
2019-10-14 16:47:53 +02:00
|
|
|
const proc = child.spawn('codesign', args.concat([i]));
|
2019-10-01 23:28:12 +02:00
|
|
|
stdOutProc(proc);
|
|
|
|
libPromises.push(new Promise((resolve) => proc.on('close', resolve)));
|
|
|
|
});
|
|
|
|
return Promise.all(libPromises);
|
|
|
|
}).then(() => {
|
2019-10-14 16:47:53 +02:00
|
|
|
const proc = child.spawn('codesign', args.concat([builtAppexPath]));
|
2019-10-01 23:28:12 +02:00
|
|
|
stdOutProc(proc);
|
|
|
|
return new Promise((resolve) => proc.on('close', resolve));
|
|
|
|
}).then(() => {
|
|
|
|
return cb;
|
|
|
|
}, () => {
|
|
|
|
return cb;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-22 16:39:42 +02:00
|
|
|
function safariCopyAssets(source, dest) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp.src(source)
|
|
|
|
.on('error', reject)
|
|
|
|
.pipe(gulpif('safari/Info.plist', replace('0.0.1', manifest.version)))
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-16 15:41:59 +01:00
|
|
|
function safariCopyBuild(source, dest) {
|
2018-01-11 23:33:13 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp.src(source)
|
|
|
|
.on('error', reject)
|
2019-08-22 14:51:08 +02:00
|
|
|
.pipe(filter(['**'].concat(filters.edge).concat(filters.fonts)
|
2019-08-02 22:09:59 +02:00
|
|
|
.concat(filters.webExt).concat(filters.nonSafariApp)))
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-26 18:13:08 +02:00
|
|
|
function stdOutProc(proc) {
|
|
|
|
proc.stdout.on('data', (data) => console.log(data.toString()));
|
2019-08-26 18:15:52 +02:00
|
|
|
proc.stderr.on('data', (data) => console.error(data.toString()));
|
|
|
|
}
|
2019-08-26 18:13:08 +02:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function webfonts() {
|
2018-01-16 15:58:18 +01:00
|
|
|
return gulp.src('./webfonts.list')
|
|
|
|
.pipe(googleWebFonts({
|
|
|
|
fontsDir: 'webfonts',
|
|
|
|
cssFilename: 'webfonts.css'
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest(paths.cssDir));
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2018-01-16 15:58:18 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function ciCoverage(cb) {
|
2018-01-16 15:58:18 +01:00
|
|
|
return gulp.src(paths.coverage + '**/*')
|
|
|
|
.pipe(filter(['**', '!coverage/coverage*.zip']))
|
|
|
|
.pipe(zip(`coverage${buildString()}.zip`))
|
|
|
|
.pipe(gulp.dest(paths.coverage));
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2018-01-16 15:58:18 +01:00
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
exports['dist:firefox'] = distFirefox;
|
|
|
|
exports['dist:chrome'] = distChrome;
|
|
|
|
exports['dist:opera'] = distOpera;
|
|
|
|
exports['dist:edge'] = distEdge;
|
2019-10-22 21:30:23 +02:00
|
|
|
exports['dist:safari'] = gulp.parallel(distSafariMas, distSafariMasDev, distSafariDmg);
|
2019-09-04 19:29:31 +02:00
|
|
|
exports.dist = gulp.parallel(distFirefox, distChrome, distOpera, distEdge);
|
2018-11-27 18:36:59 +01:00
|
|
|
exports['ci:coverage'] = ciCoverage;
|
|
|
|
exports.ci = ciCoverage;
|
|
|
|
exports.webfonts = webfonts;
|
|
|
|
exports.build = webfonts;
|