-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
55 lines (47 loc) · 1.43 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
var gulp = require('gulp'),
spawn = require('child_process').spawn,
connect = require('gulp-connect'),
argv = require('minimist')(process.argv.slice(2)),
serverDir = argv.serverDir,
nodeFile = argv.nodeFile || 'server.js',
staticDir = argv.staticDir,
node
;
gulp.task('default', function () {
if (serverDir) {
console.log("\n Starting up " + serverDir + '/' + nodeFile);
gulp.start('server');
gulp.watch('../' + serverDir + '/*.js', ['server']);
} else if (staticDir) {
console.log("\n Watching static files in " + staticDir + '/' );
gulp.start('static');
}
});
gulp.task('server', function () {
if (node) {
node.kill()
console.log('\n Bouncing server..... \n');
};
node = spawn('node', [argv.debug? 'debug' : '', ('../' + serverDir + '/' + nodeFile)], {stdio: 'inherit'});
node.on('close', function (code) {
if (code === 8) {
console.log('Error detected, waiting for changes...');
}
});
});
gulp.task('static', function () {
connect.server({
root: staticDir,
livereload: true
});
gulp.watch(['../' + staticDir + '/**/*.html'], ['static:html']);
gulp.watch(['../' + staticDir + '/**/*.css'], ['static:html']);
gulp.watch(['../' + staticDir + '/**/*.js'], ['static:html']);
});
gulp.task('static:html', function () {
gulp.src('../' + staticDir + '/*.html')
.pipe(connect.reload());
});
process.on('exit', function () {
if (node) { node.kill() }
});