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
+23 -35
View File
@@ -3,28 +3,17 @@ import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } fr
import path from "node:path";
import { spawnSync } from "node:child_process";
const electronRoot = process.cwd();
const bundleRoot = path.resolve(electronRoot, "..");
const runtimeRoot = path.join(electronRoot, "lib", "nodecg");
const runtimeNodeModules = path.join(runtimeRoot, "node_modules");
const bundleName = process.env.NODECG_BUNDLE_NAME?.trim() || "scoreko-dev";
const runtimeBundleRoot = path.join(runtimeRoot, "bundles", bundleName);
const bundleEntries = [
"assets",
"dashboard",
"extension",
"graphics",
"nodecg",
"schemas",
"shared",
"configschema.json",
"LICENSE",
"package.json",
"README.md",
];
const requiredBundleEntries = ["dashboard", "extension", "graphics", "nodecg", "schemas", "shared", "package.json"];
import {
bundleName,
bundleRoot,
getNpmCommand,
nodecgRuntimeNodeModules,
nodecgRuntimeRoot,
preparedBundleEntries,
requiredPreparedBundleEntries,
runtimeBundleRoot,
runtimeNpmCache,
} from "./build-config.mjs";
function readJson(filePath) {
return JSON.parse(readFileSync(filePath, "utf8"));
@@ -51,7 +40,7 @@ function run(command, args, cwd) {
shell: process.platform === "win32",
env: {
...process.env,
npm_config_cache: process.env.npm_config_cache ?? path.join(electronRoot, ".npm-runtime-cache"),
npm_config_cache: runtimeNpmCache,
},
});
@@ -81,7 +70,7 @@ function getInstalledNodecgVersion() {
}
function assertBundleBuildExists() {
for (const entry of requiredBundleEntries) {
for (const entry of requiredPreparedBundleEntries) {
const source = path.join(bundleRoot, entry);
if (!existsSync(source)) {
throw new Error(
@@ -103,7 +92,7 @@ function createRuntimePackageJson() {
};
writeFileSync(
path.join(runtimeRoot, "package.json"),
path.join(nodecgRuntimeRoot, "package.json"),
`${JSON.stringify(
{
private: true,
@@ -121,23 +110,23 @@ function createRuntimePackageJson() {
)}\n`,
);
writeFileSync(path.join(runtimeRoot, "index.js"), 'require("nodecg");\n');
writeFileSync(path.join(nodecgRuntimeRoot, "index.js"), 'require("nodecg");\n');
}
function copyBundle() {
mkdirSync(runtimeBundleRoot, { recursive: true });
for (const entry of bundleEntries) {
for (const entry of preparedBundleEntries) {
copyIfExists(path.join(bundleRoot, entry), path.join(runtimeBundleRoot, entry));
}
}
function writeManifest() {
const bundlePackageJson = readJson(path.join(bundleRoot, "package.json"));
const runtimePackageJson = readJson(path.join(runtimeRoot, "package.json"));
const runtimePackageJson = readJson(path.join(nodecgRuntimeRoot, "package.json"));
writeFileSync(
path.join(runtimeRoot, ".scoreko-runtime.json"),
path.join(nodecgRuntimeRoot, ".scoreko-runtime.json"),
`${JSON.stringify(
{
bundleName,
@@ -157,23 +146,22 @@ function installRuntimeDependencies() {
return;
}
const npmCommand = process.platform === "win32" ? "npm.cmd" : "npm";
run(npmCommand, ["install", "--omit=dev", "--no-audit", "--no-fund"], runtimeRoot);
run(getNpmCommand(), ["install", "--omit=dev", "--no-audit", "--no-fund"], nodecgRuntimeRoot);
}
function main() {
assertBundleBuildExists();
rmSync(runtimeRoot, { recursive: true, force: true });
mkdirSync(runtimeNodeModules, { recursive: true });
mkdirSync(path.join(runtimeRoot, "bundles"), { recursive: true });
rmSync(nodecgRuntimeRoot, { recursive: true, force: true });
mkdirSync(nodecgRuntimeNodeModules, { recursive: true });
mkdirSync(path.join(nodecgRuntimeRoot, "bundles"), { recursive: true });
createRuntimePackageJson();
copyBundle();
installRuntimeDependencies();
writeManifest();
console.log(`[prepare-runtime] NodeCG runtime ready at ${runtimeRoot}`);
console.log(`[prepare-runtime] NodeCG runtime ready at ${nodecgRuntimeRoot}`);
}
try {