PRA-only-demo/scripts/dev-safe.mjs

30 lines
1.1 KiB
JavaScript
Raw Permalink 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.

/**
* 本地开发启动器。
*
* Electron 在本工作区(D:\RPA)下会因工作区 ACL/沙箱限制无法直接启动,
* 因此允许通过 RPA_ELECTRON_DIST 指向一个可用的 Electron 运行时目录。
* 例如:set RPA_ELECTRON_DIST=C:\electron-rpa\dist
*/
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 指向包含 electron.exe 的目录。");
process.exit(1);
}
const env = { ...process.env, ELECTRON_OVERRIDE_DIST_PATH: dist };
delete env.ELECTRON_RUN_AS_NODE;
console.log(`[dev] electron dist: ${dist}`);
const child = spawn("npx.cmd", ["electron-vite", "dev"], { stdio: "inherit", env, shell: true });
child.on("exit", (code) => process.exit(code ?? 0));