-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeamon.cjs
More file actions
30 lines (24 loc) · 813 Bytes
/
deamon.cjs
File metadata and controls
30 lines (24 loc) · 813 Bytes
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
const { spawn } = require("child_process");
let childProcess;
function runDev() {
childProcess = spawn("pnpm", ["dev"], {
stdio: "inherit",
shell: true,
});
childProcess.on("exit", (code) => {
console.log(`\n\x1b[104m\x1b[30m DEAMON \x1b[0m Nuxt dev exited with code ${code}, restarting in 2s...\n`);
setTimeout(runDev, 2000);
});
}
// 捕捉 Ctrl+C / kill 命令
process.on("SIGINT", () => {
console.log("\n\x1b[104m\x1b[30m DEAMON \x1b[0m Received SIGINT. Cleaning up...");
if (childProcess) childProcess.kill("SIGINT");
process.exit();
});
process.on("SIGTERM", () => {
console.log("\n\x1b[104m\x1b[30m DEAMON \x1b[0m Received SIGTERM. Cleaning up...");
if (childProcess) childProcess.kill("SIGTERM");
process.exit();
});
runDev();