-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
72 lines (62 loc) · 1.85 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const pump = require('pump');
const gulp = require('gulp');
const browserify = require('browserify');
const minify = require('gulp-terser');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const staticFilesFn = async cb => {
const keys = [];
const locks = [
new Promise(r => keys.push(r)),
new Promise(r => keys.push(r)),
];
pump([
gulp.src('lib/*'),
gulp.dest('dist'),
], keys.pop());
pump([
gulp.src('node_modules/normalize.css/normalize.css'),
gulp.dest('dist'),
], keys.pop());
await Promise.all(locks);
cb();
};
const defaultFn = async (cb, browser, env) => {
const requestHandler = browserify({
entries: [`src/${browser}.js`],
});
const dialog = browserify({
entries: ['src/dialog.js'],
});
const keys = [];
const locks = [
new Promise(r => keys.push(r)),
new Promise(r => keys.push(r)),
];
pump([
requestHandler.bundle(),
source(`request-handler.js`),
buffer(),
...env === 'production' ? [minify()] : [],
gulp.dest('dist'),
], keys.pop());
pump([
dialog.bundle(),
source('dialog.js'),
buffer(),
...env === 'production' ? [minify()] : [],
gulp.dest('dist'),
], keys.pop());
await Promise.all(locks);
cb();
};
module.exports = {
'firefox-dev': gulp.series(staticFilesFn, cb => defaultFn(cb, 'firefox', 'dev')),
'firefox-prod': gulp.series(staticFilesFn, cb => defaultFn(cb, 'firefox', 'production')),
'firefox-watch': () => gulp.watch(['src/*', 'lib/*'], module.exports.firefoxDev),
'chrome-dev': gulp.series(staticFilesFn, cb => defaultFn(cb, 'chrome', 'dev')),
'chrome-prod': gulp.series(staticFilesFn, cb => defaultFn(cb, 'chrome', 'production')),
'chrome-watch': () => gulp.watch(['src/*', 'lib/*'], module.exports.chromeDev),
'static-files': staticFilesFn,
default: module.exports.firefoxDev,
};