-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
53 lines (45 loc) · 1.13 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
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const { spawn } = require('child_process');
const paths = {
allSrcJs: 'src/**/*.js',
gulpFile: 'gulpfile.js',
srcDir: 'src',
executable: 'src/quiver2jekyll'
};
let server;
// clear the terminal
gulp.task('clear', (callback) => {
process.stdout.write('\u001B[2J\u001B[0;0f');
callback();
});
// check the code is well structured
gulp.task('lint', () => {
return gulp.src([
paths.allSrcJs,
paths.gulpFile
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
// run node
gulp.task('main', ['lint'], () => {
// kill the server if it's running
if (server) {
server.kill();
server = undefined;
}
// spawn a new node process
server = spawn('node', [`${paths.executable}`]);
server.stdout.on('data', (data) => console.log(data.toString()));
server.stderr.on('data', (data) => console.log(data.toString()));
});
// watch files to restart the server
gulp.task('watch', () => {
gulp.watch([
paths.allSrcJs,
paths.gulpFile
], ['clear', 'main']);
});
gulp.task('default', ['clear', 'watch', 'main']);