mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import { existsSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { spawn } from "node:child_process";
|
|
|
|
const root = process.cwd();
|
|
const candidates = [
|
|
path.join(root, "lib", "nodecg"),
|
|
path.join(root, "lib", "nodecg", "workspaces", "database-adapter-sqlite-legacy"),
|
|
];
|
|
|
|
const moduleDirs = candidates.filter((dir) => existsSync(path.join(dir, "package.json")));
|
|
|
|
if (moduleDirs.length === 0) {
|
|
console.error("No NodeCG package folders found. Expected lib/nodecg and/or workspaces.");
|
|
process.exit(1);
|
|
}
|
|
|
|
function run(command, args, cwd) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn(command, args, {
|
|
cwd,
|
|
stdio: "inherit",
|
|
shell: process.platform === "win32",
|
|
env: {
|
|
...process.env,
|
|
npm_config_runtime: "electron",
|
|
npm_config_build_from_source: "false",
|
|
},
|
|
});
|
|
|
|
child.on("exit", (code) => {
|
|
if (code === 0) {
|
|
resolve();
|
|
} else {
|
|
reject(new Error(`${command} ${args.join(" ")} failed with code ${code}`));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
for (const dir of moduleDirs) {
|
|
console.log(`\n[rebuild-native] Rebuilding native modules in: ${dir}`);
|
|
await run("npx", ["electron-rebuild", "--force", "--only", "better-sqlite3"], dir);
|
|
}
|
|
|
|
console.log("\n[rebuild-native] Done.");
|