-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
52 lines (47 loc) · 1.33 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
const {
parallel,
src,
watch,
} = require('gulp');
const cache = require('gulp-cached');
const eslint = require('gulp-eslint');
const log = require('fancy-log');
const {
green,
magenta,
cyan,
red,
} = require('chalk');
const { spawn } = require('child_process');
let isFirstRun = true;
let node;
const server = async () => {
if (node) node.kill();
isFirstRun = false;
node = await spawn('node', ['src/index.js'], { stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
node.on('close', (code, signal) => {
const exited = [];
if (code) exited.push(`code ${magenta(code)}`);
if (signal) exited.push(`signal ${magenta(signal)}`);
log(`Process ${green('exited')} with ${exited.join(' ')}`);
});
};
const lintScripts = () => src(['src/**/*.js'])
.pipe(cache('lint'))
.pipe(eslint())
.pipe(eslint.format());
const serve = () => {
const watcher = watch(
['src/**/*.js'],
{ queue: false, ignoreInitial: false },
parallel(lintScripts, server),
);
watcher.on('add', (path) => {
if (!isFirstRun) log(`File ${green(path)} was ${green('added')}`);
});
watcher.on('change', path => log(`File ${green(path)} was ${cyan('changed')}`));
watcher.on('unlink', path => log(`File ${green(path)} was ${red('removed')}.`));
};
exports.default = serve;
exports.serve = serve;
exports['lint:js'] = lintScripts;