Initial commit
This commit is contained in:
29
backend/scripts/demo.js
Normal file
29
backend/scripts/demo.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const path = require("path");
|
||||
const { spawn } = require("child_process");
|
||||
|
||||
const run = (command, args) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const child = spawn(command, args, { stdio: "inherit" });
|
||||
child.on("close", (code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject(new Error(`Command failed: ${command} ${args.join(" ")}`));
|
||||
});
|
||||
});
|
||||
|
||||
const start = async () => {
|
||||
const seedPath = path.join(__dirname, "seed.js");
|
||||
const serverPath = path.join(__dirname, "..", "server.js");
|
||||
|
||||
await run("node", [seedPath]);
|
||||
|
||||
const server = spawn("node", [serverPath], { stdio: "inherit" });
|
||||
server.on("close", (code) => process.exit(code ?? 0));
|
||||
};
|
||||
|
||||
start().catch((error) => {
|
||||
console.error("Demo failed", error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user