-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwatch.js
25 lines (23 loc) · 816 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
/* eslint-disable */
const watch = require('node-watch');
const spawn = require('child_process').spawn;
const path = require('path');
const debounceTime = 300;
let timeoutId;
watch('./src', {recursive: true}, function (event, name) {
if(timeoutId){
clearTimeout(timeoutId);
}
timeoutId = setTimeout(runBuildProcess, debounceTime);
});
function runBuildProcess(){
const timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
console.log(timestamp + ' start build process');
const ls = spawn(path.join(__dirname, 'build.sh'));
ls.on('close', (code) => {
if (code === 0) {
const timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
console.log(timestamp + ' finished build process, dist directory was successfully updated');
}
});
}