-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
39 lines (33 loc) · 975 Bytes
/
index.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
console.clear()
import path from "path";
import { spawn } from "child_process";
import { watchFile, unwatchFile } from "fs";
import treeKill from "./system/lib/treekill.js";
let activeProcess = null;
async function start(file) {
if (activeProcess) {
await treeKill(activeProcess.pid, 'SIGTERM');
activeProcess = null;
}
const args = [path.join(process.cwd(), file), ...process.argv.slice(2)];
const p = spawn(process.argv[0], args, { stdio: 'inherit' });
activeProcess = p;
p.on('message', data => {
switch (data) {
case 'reset':
start(file);
break;
case 'uptime':
p.send(process.uptime());
break;
}
});
p.on('exit', code => {
if (Number(code) && code === 0) return;
watchFile(args[0], () => {
unwatchFile(args[0]);
start(file);
});
});
}
start("./system/main.js")