1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-09 09:51:02 +01:00
bitwarden-browser/gulpfile.js

360 lines
11 KiB
JavaScript
Raw Normal View History

var gulp = require('gulp'),
rimraf = require('rimraf'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
less = require('gulp-less'),
preprocess = require('gulp-preprocess'),
runSequence = require('run-sequence'),
jshint = require('gulp-jshint'),
merge = require('merge-stream'),
browserify = require('browserify'),
2016-10-26 03:13:59 +02:00
source = require('vinyl-source-stream'),
2017-02-08 06:18:26 +01:00
googleWebFonts = require('gulp-google-webfonts'),
2017-08-31 21:07:39 +02:00
webpack = require('webpack-stream'),
jeditor = require("gulp-json-editor"),
gulpUtil = require('gulp-util'),
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'),
xmlpoke = require('gulp-xmlpoke');
var paths = {};
2016-09-08 03:43:15 +02:00
paths.dist = './dist/';
paths.libDir = './src/lib/';
paths.npmDir = './node_modules/';
2016-09-08 03:43:15 +02:00
paths.popupDir = './src/popup/';
paths.lessDir = paths.popupDir + 'less/';
paths.cssDir = paths.popupDir + 'css/';
2016-10-26 03:13:59 +02:00
paths.webfontsDir = './src/webfonts/';
gulp.task('lint', function () {
2017-07-14 21:34:05 +02:00
return gulp.src([
paths.popupDir + '**/*.js',
'./src/services/**/*.js',
'./src/notification/**/*.js',
'./src/models/**/*.js',
'./src/scripts/**/*.js',
//'./src/content/**/*.js',
'./src/overlay/**/*.js',
'./src/background.js'
])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('build', function (cb) {
return runSequence(
'clean',
2017-02-08 06:18:26 +01:00
['browserify', 'webpack', 'lib', 'less', 'lint', 'webfonts'],
cb);
});
gulp.task('clean:css', function (cb) {
return rimraf(paths.cssDir, cb);
});
gulp.task('clean:lib', function (cb) {
return rimraf(paths.libDir, cb);
});
2016-10-26 03:13:59 +02:00
gulp.task('clean:fonts', function (cb) {
return rimraf(paths.webfontsDir, cb);
});
gulp.task('clean', ['clean:css', 'clean:lib', 'clean:fonts']);
gulp.task('lib', ['clean:lib'], function () {
var libs = [
{
src: [
paths.npmDir + 'bootstrap/dist/**/*',
'!' + paths.npmDir + 'bootstrap/dist/**/npm.js',
2016-10-18 02:25:57 +02:00
'!' + paths.npmDir + 'bootstrap/dist/**/css/*theme*',
'!' + paths.npmDir + 'bootstrap/**/*.min*'
],
dest: paths.libDir + 'bootstrap'
},
{
2016-10-18 02:25:57 +02:00
src: paths.npmDir + 'font-awesome/css/font-awesome.css',
dest: paths.libDir + 'font-awesome/css'
},
{
src: paths.npmDir + 'font-awesome/fonts/*',
dest: paths.libDir + 'font-awesome/fonts'
},
{
2016-10-18 02:25:57 +02:00
src: paths.npmDir + 'jquery/dist/jquery.js',
dest: paths.libDir + 'jquery'
},
{
2016-10-18 02:25:57 +02:00
src: paths.npmDir + 'angular/angular.js',
dest: paths.libDir + 'angular'
},
{
src: paths.npmDir + 'angular-animate/angular-animate.js',
dest: paths.libDir + 'angular-animate'
},
{
2016-10-18 02:25:57 +02:00
src: paths.npmDir + 'angular-ui-router/release/angular-ui-router.js',
dest: paths.libDir + 'angular-ui-router'
},
{
2016-09-22 19:15:42 +02:00
src: [paths.npmDir + 'angular-toastr/dist/angular-toastr.tpls.js',
2017-06-05 20:26:17 +02:00
paths.npmDir + 'angular-toastr/dist/angular-toastr.css'],
dest: paths.libDir + 'angular-toastr'
},
{
src: paths.npmDir + 'ngclipboard/dist/ngclipboard.js',
dest: paths.libDir + 'ngclipboard'
},
{
src: paths.npmDir + 'clipboard/dist/clipboard.js',
dest: paths.libDir + 'clipboard'
},
{
src: paths.npmDir + 'q/q.js',
dest: paths.libDir + 'q'
},
{
2016-10-18 02:25:57 +02:00
src: [paths.npmDir + 'sweetalert/dist/sweetalert.css', paths.npmDir + 'sweetalert/dist/sweetalert-dev.js',
2017-06-05 20:26:17 +02:00
paths.npmDir + 'angular-sweetalert/SweetAlert.js'],
dest: paths.libDir + 'sweetalert'
},
{
src: [paths.npmDir + 'angulartics-google-analytics/lib/angulartics*.js',
2017-06-05 20:26:17 +02:00
paths.npmDir + 'angulartics/src/angulartics.js'
],
dest: paths.libDir + 'angulartics'
2016-12-08 05:01:02 +01:00
},
{
src: paths.npmDir + 'ng-infinite-scroll/build/ng-infinite-scroll.js',
dest: paths.libDir + 'ng-infinite-scroll'
2017-04-12 14:45:31 +02:00
},
{
src: paths.npmDir + 'papaparse/papaparse.js',
2017-04-12 14:45:31 +02:00
dest: paths.libDir + 'papaparse'
}
];
var tasks = libs.map(function (lib) {
return gulp.src(lib.src).pipe(gulp.dest(lib.dest));
});
return merge(tasks);
});
2017-02-08 06:18:26 +01:00
gulp.task('browserify', ['browserify:tldjs']);
gulp.task('browserify:tldjs', function () {
return browserify(paths.npmDir + 'tldjs/index.js', { standalone: 'tldjs' })
.bundle()
.pipe(source('tld.js'))
.pipe(gulp.dest(paths.libDir + 'tldjs'));
});
2017-02-08 06:18:26 +01:00
gulp.task('webpack', ['webpack:forge']);
gulp.task('webpack:forge', function () {
var forgeDir = paths.npmDir + '/node-forge/lib/';
return gulp.src([
forgeDir + 'pbkdf2.js',
forgeDir + 'aes.js',
forgeDir + 'hmac.js',
forgeDir + 'sha256.js',
forgeDir + 'random.js',
forgeDir + 'forge.js'
]).pipe(webpack({
output: {
filename: 'forge.js',
library: 'forge',
libraryTarget: 'umd'
},
node: {
Buffer: false,
process: false,
crypto: false,
setImmediate: false
}
})).pipe(gulp.dest(paths.libDir + 'forge'));
});
gulp.task('less', function () {
return gulp.src(paths.lessDir + 'popup.less')
.pipe(less())
.pipe(gulp.dest(paths.cssDir));
});
gulp.task('watch', function () {
gulp.watch(paths.lessDir + '*.less', ['less']);
});
gulp.task('dist:clean', function (cb) {
return rimraf(paths.dist, cb);
});
gulp.task('dist:move', function () {
var moves = [
{
2017-06-05 20:26:17 +02:00
src: ['src/**/*', '!src/popup/less{,/**/*}', '!src/edge{,/**/*}'],
dest: paths.dist
}
];
var tasks = moves.map(function (move) {
return gulp.src(move.src).pipe(gulp.dest(move.dest));
});
return merge(tasks);
});
gulp.task('dist', ['build'], function (cb) {
return runSequence(
'dist:clean',
'dist:move',
cb);
});
2016-10-26 03:13:59 +02:00
gulp.task('dist-firefox', ['dist'], function (cb) {
gulp.src(paths.dist + 'manifest.json')
2017-06-05 20:26:17 +02:00
.pipe(jeditor(function (manifest) {
manifest.applications = {
gecko: {
id: '{446900e4-71c2-419f-a6a7-df9c091e268b}',
strict_min_version: '42.0'
}
};
return manifest;
}))
.pipe(gulp.dest(paths.dist));
2017-08-31 21:55:39 +02:00
return zipDist('dist-firefox');
2017-06-05 20:26:17 +02:00
});
gulp.task('dist-edge', ['dist'], function (cb) {
// move dist to temp extension folder
new Promise(function (resolve, reject) {
gulp.src(paths.dist + '**/*')
.on('error', reject)
.pipe(gulp.dest('temp/Extension/'))
.on('end', resolve);
}).then(function () {
// move windows store files to temp folder
return new Promise(function (resolve, reject) {
gulp.src('store/windows/**/*')
.on('error', reject)
.pipe(gulp.dest('temp/'))
.on('end', resolve);
});
}).then(function () {
// delete dist folder
return new Promise(function (resolve, reject) {
rimraf(paths.dist, function () {
resolve();
})
});
}).then(function () {
// move temp back to dist
return new Promise(function (resolve, reject) {
gulp.src('temp/**/*')
.on('error', reject)
.pipe(gulp.dest(paths.dist))
.on('end', resolve);
});
}).then(function () {
// delete temp folder
return new Promise(function (resolve, reject) {
rimraf('temp', function () {
resolve();
})
});
2017-09-02 05:17:37 +02:00
}).then(function () {
// move custom angular build to dist libs
return new Promise(function (resolve, reject) {
gulp.src('src/edge/angular.js')
.on('error', reject)
.pipe(gulp.dest(paths.dist + 'Extension/lib/angular'))
.on('end', resolve);
});
}).then(function () {
// move src edge folder to dist
return new Promise(function (resolve, reject) {
2017-09-02 05:17:37 +02:00
gulp.src(['src/edge/**/*', '!src/edge/angular.js'])
.on('error', reject)
.pipe(gulp.dest(paths.dist + 'Extension/edge'))
.on('end', resolve);
});
}).then(function () {
// modify manifest with edge preload stuff
return new Promise(function (resolve, reject) {
gulp.src(paths.dist + 'Extension/manifest.json')
.pipe(jeditor(function (manifest) {
manifest['-ms-preload'] = {
backgroundScript: 'edge/backgroundScriptsAPIBridge.js',
contentScript: 'edge/contentScriptsAPIBridge.js'
};
return manifest;
}))
.on('error', reject)
.pipe(gulp.dest(paths.dist + 'Extension'))
.on('end', resolve);
});
2017-09-07 16:42:25 +02:00
}).then(function () {
// modify appxmanifest
return new Promise(function (resolve, reject) {
gulp.src(paths.dist + '/AppxManifest.xml')
.pipe(xmlpoke({
replacements: [{
xpath: '/p:Package/p:Identity/@Version',
value: manifest.version + '.0',
namespaces: {
'p': 'http://schemas.microsoft.com/appx/manifest/foundation/windows10'
}
}]
}))
.on('error', reject)
.pipe(gulp.dest(paths.dist))
.on('end', resolve);
});
}).then(function () {
// makeappx.exe must be in your system's path already
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', paths.dist, '/p', paths.dist + 'bitwarden.appx']);
cb();
}, function () {
cb();
});
});
2017-08-31 21:55:39 +02:00
gulp.task('dist-other', ['dist'], function (cb) {
return zipDist('dist-other');
});
function zipDist(fileName) {
return gulp.src(paths.dist + '**/*')
.pipe(zip(fileName + '.zip'))
.pipe(gulp.dest(paths.dist));
}
2016-10-26 03:13:59 +02:00
gulp.task('webfonts', function () {
return gulp.src('./webfonts.list')
.pipe(googleWebFonts({}))
2017-08-31 21:07:39 +02:00
.pipe(gulp.dest(paths.webfontsDir));
});
function npmCommand(commands, cb) {
var npmLogger = (buffer) => {
buffer.toString()
.split(/\n/)
.forEach((message) => gulpUtil.log(message));
};
var npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
var npmChild = child.spawn(npmCommand, commands);
npmChild.stdout.on('data', npmLogger);
npmChild.stderr.on('data', npmLogger);
npmChild.stderr.on('close', cb);
return npmChild;
}
gulp.task('webext:firefox', function (cb) {
return npmCommand(['run', 'start:firefox'], cb);
2016-10-26 03:13:59 +02:00
});