mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-05 21:22:07 +00:00
41e4e91c4b
- Update .gitignore and .prettierignore to exclude additional cache and configuration files. - Revise README.md for clarity on build processes and runtime behavior. - Improve architecture documentation to reflect changes in startup flow and module responsibilities. - Modify troubleshooting guide to address common runtime issues and installation steps. - Enhance ESLint configuration to ignore more directories. - Update package.json scripts for better build and distribution processes. - Introduce build-scoreko-bundle.mjs for building the Scoreko bundle. - Implement prepare-nodecg-runtime.mjs for managing NodeCG runtime installation and updates. - Add runtime-provisioner.ts to handle user-specific NodeCG runtime provisioning. - Create tests for runtime provisioning to ensure correct behavior. - Refactor process-manager.ts and main.ts to integrate new runtime management logic.
58 lines
1.9 KiB
JavaScript
58 lines
1.9 KiB
JavaScript
import { existsSync, readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { spawn } from "node:child_process";
|
|
|
|
const root = process.cwd();
|
|
const nodecgDir = path.join(root, "lib", "nodecg");
|
|
const packageJson = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
|
|
const electronVersion = packageJson.devDependencies?.electron ?? packageJson.dependencies?.electron;
|
|
const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
|
|
if (!electronVersion) {
|
|
console.error("Could not determine Electron version from package.json.");
|
|
process.exit(1);
|
|
}
|
|
|
|
if (!existsSync(path.join(nodecgDir, "package.json"))) {
|
|
console.error("No packaged NodeCG runtime found. Run npm run prepare:runtime first.");
|
|
process.exit(1);
|
|
}
|
|
|
|
/** @returns {Promise<void>} */
|
|
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_target: electronVersion,
|
|
npm_config_disturl: "https://electronjs.org/headers",
|
|
npm_config_cache: process.env.npm_config_cache ?? path.join(root, ".npm-runtime-cache"),
|
|
ELECTRON_CACHE: process.env.ELECTRON_CACHE ?? path.join(root, ".electron-cache"),
|
|
},
|
|
});
|
|
|
|
child.on("exit", (code) => {
|
|
if (code === 0) {
|
|
resolve();
|
|
} else {
|
|
reject(new Error(`${command} ${args.join(" ")} failed with code ${code}`));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
console.log(`\n[rebuild-native] Rebuilding better-sqlite3 for Electron ${electronVersion} in: ${nodecgDir}`);
|
|
await run(npmCommand, [
|
|
"rebuild",
|
|
"better-sqlite3",
|
|
"--runtime=electron",
|
|
`--target=${electronVersion}`,
|
|
"--dist-url=https://electronjs.org/headers",
|
|
], nodecgDir);
|
|
|
|
console.log("\n[rebuild-native] Done.");
|