-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.babel.js
More file actions
72 lines (66 loc) · 1.6 KB
/
gulpfile.babel.js
File metadata and controls
72 lines (66 loc) · 1.6 KB
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
import gulp from 'gulp';
import gutil, { colors } from 'gulp-util';
import watch from 'gulp-watch';
import async from 'async';
import { spawn } from 'child_process';
class NodeProcess {
constructor (name, props) {
this.name = name;
this.props = props;
this.instance = {};
}
start (next) {
this.instance = spawn ('node', [this.props.index], { stdio: 'inherit' });
if (next) next ();
}
stop (next) {
this.instance.kill ();
if (next) next ();
}
restart () {
gutil.log ('Restarting \'' + colors.cyan (this.name) + '\'');
async.series ([ ::this.stop, ::this.start ]);
}
watch () {
/** gulp-watch module is preferred to the built in gulp.watch
because the latter is intended for small projects and doesn't
respond to newly created or deleted files, requiring a manual restart **/
watch (this.props.watch, ::this.restart).on ('error', this.error);
}
error (error) {
gutil.log ('Error \'' + colors.red (error.code) + '\'');
}
}
const express = new NodeProcess ('express', {
index: './bin/express.js',
watch: [
'./bin/express.js',
'./server/**/*',
"!./server/webpack.js"
]
});
const webpack = new NodeProcess ('webpack', {
index: './bin/webpack.js',
watch: [
'./bin/webpack.js',
'./server/webpack.js',
'./webpack.config.babel.js',
'./.babelrc'
]
});
gulp.task ('express', () => {
return async.series ([
::express.start,
::express.watch
]);
});
gulp.task ('webpack', () => {
return async.series ([
::webpack.start,
::webpack.watch
]);
});
gulp.task ('default', [
'express',
'webpack'
]);