-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwatch.js
50 lines (31 loc) · 805 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
42
43
44
45
46
47
48
49
50
const fs = require("fs");
const spawn = require('child_process').spawn;
let watch = (function(){
let directory = null;
let history = {};
let scheduled = null;
return function(_directory, callback){
directory = _directory;
fs.watch(directory, {recursive: true}, (type, filename) => {
if(scheduled === null){
setTimeout(() => {
callback(...scheduled);
scheduled = null;
}, 10);
}
scheduled = [type, filename];
});
};
})();
let node = null;
function restartServer(){
if(node){
node.kill();
}
let content = fs.readFileSync("./src/test.js", "utf8");
node = spawn('node', ['./src/potree_server.js'], {stdio: 'inherit'})
}
watch("./src", (type, filename) => {
restartServer();
});
restartServer();