chore: better dev scripts
This commit is contained in:
@@ -18,7 +18,8 @@
|
||||
"hash": "ts-node src/scripts/hash.ts",
|
||||
"verify-hash": "ts-node src/scripts/verify-hash.ts",
|
||||
"create-user": "ts-node src/scripts/create-user.ts",
|
||||
"dev": "npm run setup && npm run node; npm run teardown"
|
||||
"dev-bg": "npm run setup && npm run node",
|
||||
"dev": "ts-node src/scripts/dev.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"bcrypt": "^6.0.0",
|
||||
|
||||
32
server/src/scripts/dev.ts
Normal file
32
server/src/scripts/dev.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
//Dev-Script
|
||||
//Runs `npm run dev-bg` and listens for interrupts to execute `npm run teardown`
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
const child = spawn("npm", ["run", "dev-bg"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
});
|
||||
|
||||
async function teardown() {
|
||||
console.log("Running teardown...");
|
||||
const teardownProcess = spawn("npm", ["run", "teardown"], {
|
||||
stdio: "inherit",
|
||||
shell: true,
|
||||
});
|
||||
|
||||
await new Promise((resolve) => teardownProcess.on("exit", resolve));
|
||||
}
|
||||
|
||||
async function shutdown(signal: any) {
|
||||
child.kill(signal);
|
||||
await teardown();
|
||||
process.exit();
|
||||
}
|
||||
|
||||
process.on("SIGINT", () => shutdown("SIGINT"));
|
||||
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
||||
|
||||
child.on("exit", async (code) => {
|
||||
await teardown();
|
||||
process.exit(code ?? 0);
|
||||
});
|
||||
Reference in New Issue
Block a user