PRA-only-demo/scripts/start.mjs

28 lines
971 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 启动已构建的应用(out/ 已存在)。
* 用法:node scripts/start.mjs [--no-sandbox] [--remote-debugging-port=9223]
*/
import { spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
const candidates = [
process.env.RPA_ELECTRON_DIST,
"C:/electron-rpa/dist",
path.join(process.cwd(), "node_modules", "electron", "dist")
].filter(Boolean);
const dist = candidates.find((candidate) => fs.existsSync(path.join(candidate, "electron.exe")));
if (!dist) {
console.error("找不到可用的 Electron 运行时。请设置 RPA_ELECTRON_DIST。");
process.exit(1);
}
const env = { ...process.env };
delete env.ELECTRON_RUN_AS_NODE;
const args = [path.resolve("."), ...process.argv.slice(2)];
console.log(`[start] ${path.join(dist, "electron.exe")} ${args.join(" ")}`);
const child = spawn(path.join(dist, "electron.exe"), args, { stdio: "inherit", env });
child.on("exit", (code) => process.exit(code ?? 0));