-
Notifications
You must be signed in to change notification settings - Fork 2
/
watch.js
41 lines (33 loc) · 913 Bytes
/
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
const cp = require('child_process');
const fs = require('fs');
const utf8 = { encoding: 'utf8' };
const buildES = () => run('build-es', true); // run forever
const buildJS = () => run('build-js', true); // run forever
const test = () => run('test');
buildES();
buildJS();
fs.watch('dist/redom-store.js', () => {
fs.readFile('dist/redom-store.js', utf8, (err, src) => {
if (err) {
throw new Error(err);
}
fs.writeFile('dist/redom-store.min.js', src.split('\n')[0], utf8, (err) => {
if (err) {
throw new Error(err);
}
console.log('Written dist/redom-store.min.js');
});
});
test();
});
function run (cmd, forever) {
const child = cp.spawn('npm', ['run', cmd]);
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
if (forever) {
child.on('exit', () => {
setTimeout(run, 5000, cmd, true);
});
}
return child;
}