-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
executable file
·90 lines (79 loc) · 2.26 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const gulp = require('gulp');
const log = require('fancy-log');
const source = require('vinyl-source-stream');
const browserify = require('browserify');
const babelify = require("babelify");
const del = require('del');
const zip = require('gulp-zip');
const replace = require('gulp-replace');
const pkg = require('./package.json');
const OUTPUT_DIR = 'buzz-star';
let debug = true;
gulp.task('clean', () => del(OUTPUT_DIR, {force: true}));
gulp.task('copy', gulp.series('clean', () => {
return gulp.src([
'src/*.js',
'src/*.html',
'src/css/**',
'src/fonts/**',
'src/img/**'
], {'base': 'src'})
.pipe(gulp.dest(OUTPUT_DIR));
}));
gulp.task('manifest', gulp.series('copy', (cb) => {
log('pkg.version: ' + pkg.version);
gulp.src(['src/manifest.json'])
.pipe(replace('$$version$$', pkg.version))
.pipe(gulp.dest(OUTPUT_DIR));
cb();
}));
function compileJS(src, dst) {
return browserify({
entries: [src],
debug: debug
})
.transform(babelify.configure({
"presets": [
[
"env",
{
"targets": {
"chrome": "109"
}
}
]
]
}))
.bundle().on('error', (e) => {
log(e);
})
.pipe(source(dst))
.pipe(replace('$$version$$', pkg.version))
.pipe(gulp.dest(OUTPUT_DIR));
}
gulp.task('bundle', gulp.series('manifest',
() => compileJS('src/lib/BuzzWorker.js','buzz-worker.js'),
() => compileJS('src/lib/BuzzOffscreen.js','buzz-offscreen.js'),
() => compileJS('src/lib/BuzzPopup.js','buzz-popup.js'),
() => compileJS('src/lib/BuzzOptions.js','buzz-options.js'),
(done) => done()
));
gulp.task('default', gulp.series('bundle', (cb) => {
log('complete!');
cb();
}));
gulp.task('debug-off', (cb) => {
log('Turn debug off');
debug = false;
cb();
});
gulp.task('zip', gulp.series('bundle', () => {
return gulp.src(OUTPUT_DIR + '/**', {dot: true})
.pipe(zip('buzz-star.zip'))
.pipe(gulp.dest("."));
}));
gulp.task('prod', gulp.series('debug-off', 'zip', (cb) => {
log('complete!');
cb();
}));