-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (84 loc) · 2.45 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
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
shell = require('gulp-shell'),
spawn = require('child_process').spawn,
watch = require('gulp-watch'),
enb = require('enb'),
isInBuildProcess = false,
needReRun = false,
isBuildFailed = false;
gulp.task('clean', shell.task([
'enb make clean && rm -rf ./.enb/tmp'
]));
gulp.task('test', shell.task([
'enb make specs'
]));
gulp.task('build', function () {
isBuildFailed = false;
return enb.make().fail(function (err) {
console.error(err);
isBuildFailed = true;
});
});
var enbServerProcess;
process.on('SIGINT', function () {
if (enbServerProcess) {
enbServerProcess.kill();
}
process.exit(0);
});
var nodemonInstance;
gulp.task('run', ['build'], function () {
if (!enbServerProcess) {
enbServerProcess = spawn('node', [
'./node_modules/.bin/enb',
'server',
'-p',
'8080'
]);
enbServerProcess.stderr.on('data', function (data) {
console.warn('' + data);
process.exit();
});
enbServerProcess.stdout.on('data', function (data) {
console.log('' + data);
});
}
if (!isBuildFailed) {
if (!nodemonInstance) {
nodemonInstance = nodemon({
script: 'bundles/index/_index.node.js',
watch: '__manual__',
ext: '__manual__'
}).on('restart', function () {
console.log('~~~ restart server ~~~');
});
} else {
nodemonInstance.emit('restart');
}
}
if (needReRun) { // it seems that something changed during the build process
setTimeout(function () {
needReRun = false;
gulp.start('run');
}, 0); // lets run it again
} else {
isInBuildProcess = false; // end of build process
}
});
gulp.task('watch', function () {
watch([
'blocks/**/*',
'bundles/index/*.{yml,bemdecl.js}'
], {
// usePolling: true // use this option if watch didn't catch your changes
}, function () {
if (isInBuildProcess) { // if something is changed during the build process
needReRun = true; // we will need to run it again
} else {
isInBuildProcess = true; // build process started
gulp.start('run');
}
});
});
gulp.task('default', ['run', 'watch']);