-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.js
35 lines (29 loc) · 888 Bytes
/
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
const gulp = require('gulp');
const ts = require('gulp-typescript');
const gutil = require('gulp-util');
const spawn = require('child_process').spawn;
let node;
// pull in the project TypeScript config
const tsProject = ts.createProject('tsconfig.json');
gulp.task('scripts', () => {
const tsResult = tsProject.src()
.pipe(tsProject());
return tsResult.js.pipe(gulp.dest('dist'));
});
gulp.task('watch', ['scripts'], () => {
gulp.watch('src/**/*.ts', ['scripts', 'server']);
});
gulp.task('server', ['scripts'], () => {
if (node) node.kill();
node = spawn('node', ['dist/index.js'], {stdio: 'inherit'});
node.on('close', code => {
if (code === 8) {
gutil.log('Error detected, waiting for changes...');
}
});
});
gulp.task('default', ['watch', 'server']);
// clean up if an error goes unhandled.
process.on('exit', () => {
if (node) node.kill()
});