| 1 | #!/usr/bin/env node |
| 2 | import { spawn } from "node:child_process"; |
| 3 | import { existsSync } from "node:fs"; |
| 4 | import { createRequire } from "node:module"; |
| 5 | import { dirname, resolve } from "node:path"; |
| 6 | import { fileURLToPath } from "node:url"; |
| 7 | |
| 8 | const root = dirname(dirname(fileURLToPath(import.meta.url))); |
| 9 | const dev = process.argv.includes("--dev"); |
| 10 | const env = { ...process.env }; |
| 11 | |
| 12 | if (!env.REASONIX_DESKTOP_SERVICE) { |
| 13 | env.REASONIX_DESKTOP_SERVICE = resolve(root, "../build/bin", process.platform === "win32" ? "reasonix-desktop-service.exe" : "reasonix-desktop-service"); |
| 14 | } |
| 15 | if (!existsSync(env.REASONIX_DESKTOP_SERVICE)) { |
| 16 | console.error("desktop service binary not found; check REASONIX_DESKTOP_SERVICE or build it with: cd desktop && go build -o build/bin/reasonix-desktop-service ."); |
| 17 | process.exit(1); |
| 18 | } |
| 19 | if (dev) { |
| 20 | env.REASONIX_DEV ??= "1"; |
| 21 | env.REASONIX_ELECTRON_DEV_URL ??= `http://127.0.0.1:${env.REASONIX_DESKTOP_VITE_PORT || "5173"}`; |
| 22 | } |
| 23 | |
| 24 | const electron = createRequire(import.meta.url)("electron"); |
| 25 | const child = spawn(electron, [root], { env, stdio: "inherit", windowsHide: false }); |
| 26 | child.on("exit", (code, signal) => process.exit(code ?? (signal ? 1 : 0))); |
| 27 |