forked from web-padawan/aybolit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatcher.js
43 lines (38 loc) · 1014 Bytes
/
watcher.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
const watch = require('node-watch');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const watchOptions = {
recursive: true,
filter: path => {
if (path.indexOf('node_modules') > -1) {
return false;
}
if (path.indexOf('scss') === -1) {
return false;
}
return /.(?:scss)$/.test(path);
}
};
let updating = false;
async function addToQueue(fileName) {
if (updating) {
return;
}
console.log(`saw change to ${fileName}`);
updating = true;
console.log('building styles');
const execPromise = exec(`node packages/sass-render/bin/sass-render.js -s "${fileName}"`);
try {
const { stdout } = await execPromise;
console.log(stdout);
} catch ({ stdout, stderr }) {
console.log(stdout);
console.log('ERROR:', stderr);
}
console.log('watcher build complete!');
updating = false;
}
watch('packages', watchOptions, (_event, fileName) => {
addToQueue(fileName);
});
console.log('watcher started!');