/** * Start apps/api with venv python + PYTHONPATH (Win/Unix). */ import { spawn } from "node:child_process"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const api = path.join(root, "apps", "api"); const isWin = process.platform === "win32"; const py = isWin ? path.join(api, ".venv", "Scripts", "python.exe") : path.join(api, ".venv", "bin", "python"); if (!fs.existsSync(py)) { console.error( "[dev:api] missing venv. Run:\n cd apps/api && python -m venv .venv && .venv/Scripts/pip install -r requirements.txt", ); process.exit(1); } const env = { ...process.env, PYTHONPATH: [api, path.join(api, "services"), process.env.PYTHONPATH] .filter(Boolean) .join(path.delimiter), }; const child = spawn(py, ["run.py"], { cwd: api, env, stdio: "inherit", shell: false }); child.on("exit", (code) => process.exit(code ?? 0));