chore: better dev scripts
This commit is contained in:
@@ -9,8 +9,7 @@
|
|||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"server": "npm run dev --workspace=server",
|
"server": "npm run dev --workspace=server",
|
||||||
"client": "npm start --prefix client",
|
"client": "npm start --prefix client",
|
||||||
"dev": "concurrently \"npm run server\" \"npm run client\"",
|
"dev": "concurrently \"npm run server\" \"npm run client\""
|
||||||
"teardown": "npm run teardown --workspace=server"
|
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"client",
|
"client",
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
"hash": "ts-node src/scripts/hash.ts",
|
"hash": "ts-node src/scripts/hash.ts",
|
||||||
"verify-hash": "ts-node src/scripts/verify-hash.ts",
|
"verify-hash": "ts-node src/scripts/verify-hash.ts",
|
||||||
"create-user": "ts-node src/scripts/create-user.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": {
|
"dependencies": {
|
||||||
"bcrypt": "^6.0.0",
|
"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