Refactor NodeCG runtime preparation and update handling

- Updated paths and configurations in doctor.mjs and prepare-nodecg-runtime.mjs to use new build-config.mjs imports.
- Enhanced runtime installation checks and permissions validation.
- Introduced new update configuration management in update-config.ts, including loading and validating update settings.
- Implemented update service for managing update checks and downloads in update-service.ts.
- Replaced update-utils.ts with update-schema.ts for better structure and clarity in update handling.
- Added comprehensive tests for update download and settings management.
- Ensured secure handling of download URLs and improved error handling in update processes.
This commit is contained in:
2026-05-24 23:20:59 +02:00
parent c8e2edc0c0
commit 865c3589bd
19 changed files with 723 additions and 240 deletions
+9 -10
View File
@@ -2,18 +2,17 @@ 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"));
import { electronCache, electronRoot, getNpmCommand, nodecgRuntimeRoot, runtimeNpmCache } from "./build-config.mjs";
const packageJson = JSON.parse(readFileSync(path.join(electronRoot, "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"))) {
if (!existsSync(path.join(nodecgRuntimeRoot, "package.json"))) {
console.error("No packaged NodeCG runtime found. Run npm run prepare:runtime first.");
process.exit(1);
}
@@ -30,8 +29,8 @@ function run(command, args, cwd) {
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"),
npm_config_cache: runtimeNpmCache,
ELECTRON_CACHE: electronCache,
},
});
@@ -45,13 +44,13 @@ function run(command, args, cwd) {
});
}
console.log(`\n[rebuild-native] Rebuilding better-sqlite3 for Electron ${electronVersion} in: ${nodecgDir}`);
await run(npmCommand, [
console.log(`\n[rebuild-native] Rebuilding better-sqlite3 for Electron ${electronVersion} in: ${nodecgRuntimeRoot}`);
await run(getNpmCommand(), [
"rebuild",
"better-sqlite3",
"--runtime=electron",
`--target=${electronVersion}`,
"--dist-url=https://electronjs.org/headers",
], nodecgDir);
], nodecgRuntimeRoot);
console.log("\n[rebuild-native] Done.");