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'),
|
|
|
|
del = require('del');
|
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/',
|
2017-11-08 03:45:18 +01:00
|
|
|
npmDir: './node_modules/',
|
|
|
|
popupDir: './src/popup/',
|
2018-04-11 04:20:50 +02:00
|
|
|
cssDir: './src/popup/css/'
|
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: [
|
2018-01-16 15:41:59 +01:00
|
|
|
'!build/safari/**/*',
|
2018-01-18 20:40:23 +01:00
|
|
|
'!build/downloader/**/*',
|
|
|
|
'!build/2fa/**/*'
|
2018-01-11 23:33:13 +01:00
|
|
|
],
|
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/**/*'
|
|
|
|
]
|
|
|
|
};
|
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
|
2017-11-16 03:39:48 +01:00
|
|
|
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', edgePath, '/p', appxPath]);
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-11-27 18:36:59 +01:00
|
|
|
function distSafari(cb) {
|
2018-01-16 16:16:12 +01:00
|
|
|
const buildPath = paths.dist + 'Safari/';
|
|
|
|
const extBuildPath = buildPath + 'bitwarden.safariextension/';
|
|
|
|
const extAssetsBuildPath = extBuildPath + 'safari/';
|
2018-01-11 23:33:13 +01:00
|
|
|
|
|
|
|
return del([buildPath + '**/*'])
|
2018-01-16 16:16:12 +01:00
|
|
|
.then(() => safariCopyBuild(paths.build + '**/*', extBuildPath))
|
|
|
|
.then(() => copy(extAssetsBuildPath + '**/*', extBuildPath))
|
|
|
|
.then(() => del([extAssetsBuildPath]))
|
|
|
|
.then(() => safariZip(buildPath))
|
2018-01-11 23:33:13 +01:00
|
|
|
.then(() => {
|
|
|
|
return cb;
|
|
|
|
}, () => {
|
|
|
|
return cb;
|
|
|
|
});
|
2018-11-27 18:36:59 +01:00
|
|
|
}
|
2018-01-11 23:33:13 +01:00
|
|
|
|
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)
|
2018-01-16 04:13:06 +01:00
|
|
|
.pipe(filter(['**'].concat(filters.edge).concat(filters.fonts).concat(filters.webExt)))
|
2018-04-14 04:29:31 +02:00
|
|
|
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'browser_safari')))
|
2018-01-16 15:41:59 +01:00
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-16 16:16:12 +01:00
|
|
|
function safariZip(buildPath) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp.src(buildPath + '**/*')
|
|
|
|
.on('error', reject)
|
|
|
|
.pipe(zip(distFileName('safari', 'zip')))
|
|
|
|
.pipe(gulp.dest(paths.dist))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-01-16 15:41:59 +01:00
|
|
|
function copy(source, dest) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
gulp.src(source)
|
|
|
|
.on('error', reject)
|
2018-01-11 23:33:13 +01:00
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
2018-11-27 18:36:59 +01:00
|
|
|
|
|
|
|
exports['dist:firefox'] = distFirefox;
|
|
|
|
exports['dist:chrome'] = distChrome;
|
|
|
|
exports['dist:opera'] = distOpera;
|
|
|
|
exports['dist:edge'] = distEdge;
|
|
|
|
exports['dist:safari'] = distSafari;
|
|
|
|
exports.dist = gulp.parallel(distFirefox, distChrome, distOpera, distEdge, distSafari);
|
|
|
|
exports['ci:coverage'] = ciCoverage;
|
|
|
|
exports.ci = ciCoverage;
|
|
|
|
exports.webfonts = webfonts;
|
|
|
|
exports.build = webfonts;
|