chore: fix dev script
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
//Runs `npm run dev-bg` and listens for interrupts to execute `npm run teardown`
|
//Runs `npm run dev-bg` and listens for interrupts to execute `npm run teardown`
|
||||||
import { spawn } from "node:child_process";
|
import { spawn } from "node:child_process";
|
||||||
|
|
||||||
|
let isShuttingDown = false;
|
||||||
|
|
||||||
const child = spawn("npm", ["run", "dev-bg"], {
|
const child = spawn("npm", ["run", "dev-bg"], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
shell: true,
|
shell: true,
|
||||||
@@ -12,12 +14,15 @@ async function teardown() {
|
|||||||
const teardownProcess = spawn("npm", ["run", "teardown"], {
|
const teardownProcess = spawn("npm", ["run", "teardown"], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
shell: true,
|
shell: true,
|
||||||
|
detached: true
|
||||||
});
|
});
|
||||||
|
|
||||||
await new Promise((resolve) => teardownProcess.on("exit", resolve));
|
await new Promise((resolve) => teardownProcess.on("exit", resolve));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function shutdown(signal: any) {
|
async function shutdown(signal: any) {
|
||||||
|
if(isShuttingDown) return;
|
||||||
|
isShuttingDown = true;
|
||||||
child.kill(signal);
|
child.kill(signal);
|
||||||
await teardown();
|
await teardown();
|
||||||
process.exit();
|
process.exit();
|
||||||
@@ -27,6 +32,5 @@ process.on("SIGINT", () => shutdown("SIGINT"));
|
|||||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||||
|
|
||||||
child.on("exit", async (code) => {
|
child.on("exit", async (code) => {
|
||||||
await teardown();
|
|
||||||
process.exit(code ?? 0);
|
process.exit(code ?? 0);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user