-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
127 lines (106 loc) · 3.51 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*jshint node:true */
const gulp = require('gulp');
const del = require('del');
const exec = require('child_process').exec;
const streamqueue = require('streamqueue');
const $ = require('gulp-load-plugins')();
const src = {
assets: ['lib/{fonts,images}/**/*', 'src/{fonts,images}/**/*'],
chrome: ['src/chrome/**/*'],
css: ['lib/**/*.css', 'src/**/*.css'],
js: ['src/**/*.js', '!src/common/**/*'],
html: ['src/**/*.html', '!src/common/**/*'],
commonTemplates: ['src/common/**/*.html'],
commonJs: ['src/common/**/*.js'],
libJs: ['lib/**/*.js']
};
const outputdir = 'build';
const htmlminOptions = {
removeComments: true,
collapseWhitespace: true,
conservativeCollapse: true,
removeTagWhitespace: true
};
const uglifyOptions = {
// The resulting value of injected scripts is important, negating IIFEs breaks this.
compress: { negate_iife: false }
};
gulp.task('lib', function () {
gulp.src(src.libJs)
.pipe($.concat('lib.js'))
.pipe(gulp.dest(outputdir));
});
// Merge common
gulp.task('common', function () {
const commonJs = gulp.src(src.commonJs);
const templates = gulp.src(src.commonTemplates)
.pipe($.htmlmin(htmlminOptions))
.pipe($.angularTemplatecache({ module: 'templates', standalone: true }));
streamqueue({ objectMode: true }, commonJs, templates)
.pipe($.sourcemaps.init())
.pipe($.concat('common.js'))
.pipe($.babel())
.pipe($.uglify(uglifyOptions))
.pipe($.sourcemaps.write('maps'))
.pipe(gulp.dest(outputdir));
});
gulp.task('html', function () {
gulp.src(src.html)
.pipe($.htmlmin(htmlminOptions))
.pipe(gulp.dest(outputdir));
});
gulp.task('scripts', ['lib', 'common'], function () {
gulp.src(src.js)
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.uglify(uglifyOptions))
.pipe($.sourcemaps.write('maps'))
.pipe(gulp.dest(outputdir));
});
gulp.task('css', function () {
gulp.src(src.css)
.pipe($.concat('styles.css'))
.pipe(gulp.dest(outputdir));
});
gulp.task('chrome', function () {
gulp.src(src.chrome)
.pipe(gulp.dest(outputdir));
});
gulp.task('assets', function () {
gulp.src(src.assets)
.pipe(gulp.dest(outputdir));
});
const allTasks = ['scripts', 'html', 'css', 'assets', 'chrome'];
gulp.task('clean', function () {
del([outputdir, 'dist']);
});
gulp.task('reload', function (cb) {
const reloadCmd = 'node_modules/chrome-extensions-reloader/bin/chrome-extensions-reloader --single-run';
exec(reloadCmd, (err, stdout, stderr) => {
if (stdout.length > 0) {
console.log(stdout);
}
if (stderr.length > 0) {
console.error(stderr);
}
cb(err);
});
});
gulp.task('watch', allTasks, function () {
gulp.watch(src.commonJs, ['common', 'reload']);
gulp.watch(src.commonTemplates, ['common', 'reload']);
gulp.watch(src.libJs, ['lib', 'reload']);
gulp.watch(src.html, ['html', 'reload']);
gulp.watch(src.js, ['scripts', 'reload']);
gulp.watch(src.css, ['css', 'reload']);
gulp.watch(src.chrome, ['chrome', 'reload']);
gulp.watch(src.assets, ['assets', 'reload']);
});
gulp.task('package', allTasks, function () {
const manifest = require(`./${outputdir}/manifest.json`);
gulp.src([`${outputdir}/**`, `!${outputdir}/maps{,/**}`])
.pipe($.zip(`hashword-${manifest.version}.zip`))
.pipe(gulp.dest('dist'));
});
// Regular build
gulp.task('default', allTasks);