Spaces:
Sleeping
Sleeping
| import { spawn } from "node:child_process"; | |
| import path from "node:path"; | |
| import { fileURLToPath } from "node:url"; | |
| import { startApiWithReload, waitForApiReady } from "./api-reload.mjs"; | |
| const here = path.dirname(fileURLToPath(import.meta.url)); | |
| const frontendDir = path.resolve(here, ".."); | |
| const repoRoot = path.resolve(frontendDir, "../../../.."); | |
| const apiOnly = process.argv.includes("--api-only"); | |
| function run(command, args, options = {}) { | |
| return spawn(command, args, { | |
| stdio: "inherit", | |
| ...options, | |
| }); | |
| } | |
| const api = startApiWithReload(repoRoot); | |
| if (apiOnly) { | |
| process.on("SIGINT", () => { | |
| api.stop(); | |
| process.exit(0); | |
| }); | |
| process.on("SIGTERM", () => { | |
| api.stop(); | |
| process.exit(0); | |
| }); | |
| } else { | |
| console.log("[dev] Waiting for Python API on port 8765…"); | |
| await waitForApiReady(api.port); | |
| console.log("[dev] API ready — starting Vite"); | |
| const vite = run("npm", ["run", "dev:vite"], { cwd: frontendDir, shell: true }); | |
| const shutdown = () => { | |
| api.stop(); | |
| vite.kill("SIGTERM"); | |
| }; | |
| process.on("SIGINT", shutdown); | |
| process.on("SIGTERM", shutdown); | |
| Promise.all([ | |
| new Promise((resolve) => vite.on("exit", resolve)), | |
| ]).then(() => { | |
| api.stop(); | |
| process.exit(0); | |
| }); | |
| } | |