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'),
|
2016-09-08 00:51:36 +02:00
|
|
|
jshint = require('gulp-jshint'),
|
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-08 21:17:09 +01:00
|
|
|
xmlpoke = require('gulp-xmlpoke');
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2017-11-08 03:45:18 +01:00
|
|
|
const paths = {
|
|
|
|
releases: './releases/',
|
|
|
|
dist: './dist/',
|
|
|
|
libDir: './src/lib/',
|
|
|
|
npmDir: './node_modules/',
|
|
|
|
popupDir: './src/popup/',
|
|
|
|
cssDir: './src/popup/css/'
|
|
|
|
};
|
2016-09-08 00:51:36 +02:00
|
|
|
|
2017-10-29 03:14:14 +01:00
|
|
|
const sidebarActionManifestObj = {
|
|
|
|
"default_title": "bitwarden",
|
|
|
|
"default_panel": "popup/index.html?uilocation=sidebar",
|
|
|
|
"default_icon": "images/icon19.png"
|
|
|
|
};
|
|
|
|
|
|
|
|
function dist(browserName, manifest) {
|
|
|
|
return gulp.src(paths.dist + '**/*')
|
2017-11-10 14:29:40 +01:00
|
|
|
.pipe(gulpif(browserName !== 'edge', filter(['**', '!dist/edge/**/*', '!dist/popup/fonts/glyphicons*'])))
|
2017-10-29 03:14:14 +01:00
|
|
|
.pipe(gulpif('popup/index.html', replace('__BROWSER__', browserName)))
|
|
|
|
.pipe(gulpif('manifest.json', jeditor(manifest)))
|
|
|
|
.pipe(zip(`dist-${browserName}.zip`))
|
|
|
|
.pipe(gulp.dest(paths.releases));
|
|
|
|
}
|
|
|
|
|
2017-11-08 16:22:26 +01:00
|
|
|
gulp.task('dist', ['dist:firefox', 'dist:chrome', 'dist:opera', 'dist:edge']);
|
|
|
|
|
2017-11-08 21:42:13 +01:00
|
|
|
gulp.task('dist:firefox', (cb) => {
|
|
|
|
return dist('firefox', (manifest) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
manifest.applications = {
|
|
|
|
gecko: {
|
|
|
|
id: '{446900e4-71c2-419f-a6a7-df9c091e268b}',
|
|
|
|
strict_min_version: '42.0'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
manifest['sidebar_action'] = sidebarActionManifestObj;
|
|
|
|
return manifest;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-08 21:42:13 +01:00
|
|
|
gulp.task('dist:opera', (cb) => {
|
|
|
|
return dist('opera', (manifest) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
manifest['sidebar_action'] = sidebarActionManifestObj;
|
|
|
|
return manifest;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-08 21:42:13 +01:00
|
|
|
gulp.task('dist:chrome', (cb) => {
|
|
|
|
return dist('chrome', (manifest) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
return manifest;
|
|
|
|
});
|
2017-11-08 16:22:26 +01:00
|
|
|
});
|
2017-10-29 03:14:14 +01:00
|
|
|
|
|
|
|
// Since Edge extensions require makeappx to be run we temporarily store it in a folder.
|
2017-11-08 21:42:13 +01:00
|
|
|
gulp.task('dist:edge', (cb) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
const edgePath = paths.releases + 'Edge/';
|
|
|
|
const extensionPath = edgePath + 'Extension/';
|
|
|
|
|
2017-11-08 21:42:13 +01:00
|
|
|
return copyDistEdge(paths.dist + '**/*', extensionPath)
|
2017-10-29 03:14:14 +01:00
|
|
|
.then(copyAssetsEdge('./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-08 16:22:26 +01:00
|
|
|
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', edgePath, '/p', paths.releases + 'dist-edge.appx']);
|
2017-11-08 21:42:13 +01:00
|
|
|
return cb;
|
|
|
|
}, () => {
|
|
|
|
return cb;
|
2017-10-29 03:14:14 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function copyDistEdge(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)
|
2017-11-10 14:29:40 +01:00
|
|
|
.pipe(filter(['**', '!dist/popup/fonts/glyphicons*']))
|
2017-10-29 03:14:14 +01:00
|
|
|
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'edge')))
|
2017-11-08 21:42:13 +01:00
|
|
|
.pipe(gulpif('manifest.json', jeditor((manifest) => {
|
2017-10-29 03:14:14 +01:00
|
|
|
manifest['-ms-preload'] = {
|
|
|
|
backgroundScript: 'edge/backgroundScriptsAPIBridge.js',
|
|
|
|
contentScript: 'edge/contentScriptsAPIBridge.js'
|
|
|
|
};
|
|
|
|
return manifest;
|
|
|
|
})))
|
|
|
|
.pipe(gulp.dest(dest))
|
|
|
|
.on('end', resolve);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyAssetsEdge(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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-08 16:22:26 +01:00
|
|
|
gulp.task('build', ['lint', 'webfonts']);
|
2017-10-29 03:14:14 +01:00
|
|
|
|
2017-11-08 21:42:13 +01:00
|
|
|
gulp.task('webfonts', () => {
|
2017-10-29 03:14:14 +01:00
|
|
|
return gulp.src('./webfonts.list')
|
|
|
|
.pipe(googleWebFonts({
|
|
|
|
fontsDir: 'webfonts',
|
|
|
|
cssFilename: 'webfonts.css'
|
|
|
|
}))
|
|
|
|
.pipe(gulp.dest(paths.cssDir));
|
|
|
|
});
|
|
|
|
|
|
|
|
// LEGACY CODE!
|
|
|
|
|
2017-11-08 21:42:13 +01:00
|
|
|
gulp.task('lint', () => {
|
2017-07-14 21:34:05 +02:00
|
|
|
return gulp.src([
|
|
|
|
paths.popupDir + '**/*.js',
|
|
|
|
'./src/services/**/*.js',
|
|
|
|
'./src/notification/**/*.js',
|
|
|
|
'./src/scripts/**/*.js',
|
|
|
|
//'./src/content/**/*.js',
|
|
|
|
'./src/overlay/**/*.js',
|
|
|
|
'./src/background.js'
|
|
|
|
])
|
2017-10-29 03:14:14 +01:00
|
|
|
.pipe(jshint({
|
|
|
|
esversion: 6
|
|
|
|
}))
|
2016-09-08 00:51:36 +02:00
|
|
|
.pipe(jshint.reporter('default'));
|
|
|
|
});
|