chore: better dev scripts

This commit is contained in:
eneller
2026-08-02 12:39:29 +02:00
parent f708b2e84f
commit 787eed80b0
3 changed files with 35 additions and 3 deletions

View File

@@ -9,8 +9,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"server": "npm run dev --workspace=server",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"teardown": "npm run teardown --workspace=server"
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"workspaces": [
"client",

View File

@@ -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
View 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);
});