1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-09 09:40:07 +01:00
bitwarden-desktop/gulpfile.js

215 lines
6.2 KiB
JavaScript
Raw Normal View History

const gulp = require('gulp'),
gulpif = require('gulp-if'),
replace = require('gulp-replace'),
rimraf = require('rimraf'),
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"),
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');
const paths = {};
paths.releases = './releases/';
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.cssDir = paths.popupDir + 'css/';
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 + '**/*')
.pipe(gulpif('popup/index.html', replace('__BROWSER__', browserName)))
.pipe(gulpif('manifest.json', jeditor(manifest)))
.pipe(zip(`dist-${browserName}.zip`))
.pipe(gulp.dest(paths.releases));
}
gulp.task('dist:firefox', function (cb) {
return dist('firefox', function (manifest) {
manifest.applications = {
gecko: {
id: '{446900e4-71c2-419f-a6a7-df9c091e268b}',
strict_min_version: '42.0'
}
};
manifest['sidebar_action'] = sidebarActionManifestObj;
return manifest;
});
});
gulp.task('dist:opera', function (cb) {
return dist('opera', function (manifest) {
manifest['sidebar_action'] = sidebarActionManifestObj;
return manifest;
});
});
gulp.task('dist:chrome', function (cb) {
return dist('chrome', function (manifest) {
return manifest;
});
})
// Since Edge extensions require makeappx to be run we temporarily store it in a folder.
gulp.task('dist:edge', function (cb) {
const edgePath = paths.releases + 'Edge/';
const extensionPath = edgePath + 'Extension/';
copyDistEdge(paths.dist + '**/*', extensionPath)
.then(copyAssetsEdge('./store/windows/**/*', edgePath))
.then(function () {
// makeappx.exe must be in your system's path already
child.spawn('makeappx.exe', ['pack', '/h', 'SHA256', '/d', edgePath, '/p', paths.releases + 'bitwarden.appx']);
cb();
}, function () {
cb();
});
});
function copyDistEdge(source, dest) {
2017-10-29 03:39:38 +01:00
return new Promise((resolve, reject) => {
gulp.src(source)
.on('error', reject)
.pipe(gulpif('popup/index.html', replace('__BROWSER__', 'edge')))
.pipe(gulpif('manifest.json', jeditor(function (manifest) {
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) => {
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);
});
}
gulp.task('build', function (cb) {
return runSequence(
'clean',
['browserify', 'webpack', 'lib', 'lint', 'webfonts'],
cb);
});
gulp.task('webfonts', function () {
return gulp.src('./webfonts.list')
.pipe(googleWebFonts({
fontsDir: 'webfonts',
cssFilename: 'webfonts.css'
}))
.pipe(gulp.dest(paths.cssDir));
});
// LEGACY CODE!
//
2017-10-29 03:39:38 +01:00
// Needed until background.js is converted into a proper webpack compatible file.
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({
esversion: 6
}))
.pipe(jshint.reporter('default'));
});
gulp.task('clean:lib', function (cb) {
return rimraf(paths.libDir, cb);
});
gulp.task('clean', ['clean:lib']);
gulp.task('lib', ['clean:lib'], function () {
var libs = [
{
2016-10-18 02:25:57 +02:00
src: paths.npmDir + 'jquery/dist/jquery.js',
dest: paths.libDir + 'jquery'
},
{
src: paths.npmDir + 'q/q.js',
dest: paths.libDir + 'q'
}
];
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'));
});