-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (82 loc) · 2.74 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
"use strict";
const build = require('./lib/build');
const gulp = require('gulp');
const gutil = require('gulp-util');
const path = require('path');
const startWatchServer = require('./lib/watch_server');
const watch = require('gulp-watch');
gulp.task('watch', function() {
let
s, // stream to return
running = new Set([]),
rerun = new Set([]),
rebuild = function(k, v, f) {
if(running.has(k)) {
rerun.add(k);
return;
} else {
running.add(k);
rerun.delete(k);
}
let
relpath = './' + path.relative(process.cwd(), v.path),
start = Date.now(),
onRebuildDone = () => {
gutil.log(`Rebuilt in`, gutil.colors.bold(gutil.colors.magenta(`${(Date.now()-start)/1000} sec`)));
running.delete(k);
if(rerun.has(k)) {
rebuild(k, v, f);
} else {
server.emit('serverRebuildDone', {});
}
}
;
server.emit('serverRebuildStart', {});
gutil.log(`Detected change in ${gutil.colors.cyan(relpath)}, rebuilding...`);
let s = f(v);
if(s && s.on) s.on('end', onRebuildDone);
else onRebuildDone();
},
defs = [
// [key, file glob to watch, build func]
['js', 'src/assets/js/**/*.js', build.js('./build/dev/assets/js', true)], // js
['less', 'src/assets/less/**/*.less', build.less('./build/dev/assets/css', true)], // less
['manifest', 'src/manifest/*.json', build.manifest('./build/dev', true)], // manifest
['assets', 'src/assets/{html,images,icons}/**/*', build.assets('./build/dev/assets')], // other assets
['locales', 'src/assets/_locales/**/*', build.locales('./build/dev/_locales')], // locales
]
;
// TODO: handle deleted files?
for(let def of defs) {
def[2]();
s = watch(def[1], function(v) {
rebuild(def[0], v, def[2]);
});
}
// Watch server
build.watchClient();
let server = startWatchServer(4321);
gutil.log("Started watch server on port", 4321);
server.on('connection', (socket) => {
gutil.log("Client connected to watch server");
});
server.on('clientReloading', (socket) => {
gutil.log("Extension is reloading...");
});
gutil.log("Project built in", gutil.colors.cyan('./build/dev'));
gutil.log("Watching for changes...");
return s
});
gulp.task('dist', function() {
let
start = Date.now(),
run = (l, f) => {
gutil.log(` --> ${l}`);
f();
}
;
gutil.log("Buildling distribution in", gutil.colors.cyan('./build/dist'));
run('javascripts', build.js('./build/dist/assets/js', false));
run('less', build.less('./build/dist/assets/less', false));
gutil.log("Finished in", gutil.colors.bold(gutil.colors.magenta(`${(Date.now()-start)/1000} sec`)));
});