-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwatch.js
42 lines (36 loc) · 1.02 KB
/
watch.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
/**
* @file watch.js
* @author alienzhou
* @description
* File Created 2018-09-23 22:45:56, Sunday
* -----
* Last Modified 2018-09-23 22:45:56, Sunday
* Modified By alienzhou
* -----
*/
const chalk = require('chalk');
const chokidar = require('chokidar');
const childProcess = require('child_process');
const chalkCtx = new chalk.constructor({level: 3});
function runInChildProcess() {
const cp = childProcess.exec('node run.js', {
stdio: 'inherit'
});
cp.stdout.on('data', (data) => {
console.log(data);
});
cp.stderr.on('data', err => {
console.error(chalkCtx.red('encounter some errors:'));
console.error(chalkCtx.red(err));
});
cp.on('close', code => {
if (code !== 0) {
console.log(chalkCtx.red(`child process exited with code ${code}`));
}
});
}
require('./index')();
chokidar.watch(['./lib', 'index.js', 'config/color.json']).on('change', p => {
console.log(chalkCtx.green(`file ${p} changed`));
runInChildProcess();
});