-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgulpfile.js
More file actions
51 lines (42 loc) · 1.38 KB
/
gulpfile.js
File metadata and controls
51 lines (42 loc) · 1.38 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
/* eslint strict: [0, "global"] */
'use strict';
// node still doesnt have built-in support for `import` :(
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const forever = require('forever-monitor');
const globs = ['src/**/*.js', 'server.js', 'gulpfile.js'];
const server = new forever.Monitor('./index.js');
let isRunning = false;
process.env.NODE_ENV = 'development';
process.env.PGSSLMODE = 'require';
server.on('start', () => {
console.log(`DEV: starting server at ${Date.now()}`);
});
server.on('exit', () => {
console.log(`DEV: exiting server at ${Date.now()}`);
});
gulp.task('lint', () => {
return gulp.src(globs)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// TODO: this task is awkward and i dont like it. Fix it, eventually
gulp.task('watch:run', () => {
gulp.watch(globs, ['run']);
});
gulp.task('run', ['lint'], () => {
if (isRunning) {
server.stop();
// setTimeout is necessary here because server.stop, for whatever reason,
// is async without providing a callback for completion. 100ms should generally
// be enough time to let the server stop before trying to start it again
setTimeout(() => {
server.start();
}, 100);
} else {
server.start();
isRunning = true;
}
});
gulp.task('serve', ['run', 'watch:run']);