merge-config.cjs loaded json5 (not installed, and unable to parse JSONC comments), so sync_configs crashed mid-update and do_restart never ran — leaving the emulator running the old JAR. - merge-config.cjs: switch from json5 to jsonc-parser (already a dependency) to parse .jsonc configs including comments - update-Nitrov3.sh: always run renderer/client parallel builds instead of gating them on the emulator's update status - update-Nitrov3.sh: isolate each repo's yarn cache (--cache-folder) so parallel installs can't corrupt a shared cache and silently drop vite/pixi.js; replace invalid --no-cache flag with per-repo cache reset - update-Nitrov3.sh: fix misleading [DRY-RUN] label on real updates
73 lines
1.4 KiB
JavaScript
73 lines
1.4 KiB
JavaScript
const fs = require("node:fs");
|
|
const { parse, printParseErrorCode } = require("jsonc-parser");
|
|
|
|
const exampleFile = process.argv[2];
|
|
const targetFile = process.argv[3];
|
|
|
|
if (!exampleFile || !targetFile) {
|
|
process.exit(1);
|
|
}
|
|
|
|
function deepMerge(target, source) {
|
|
const result = { ...target };
|
|
for (const key of Object.keys(source)) {
|
|
if (
|
|
source[key] !== null &&
|
|
typeof source[key] === "object" &&
|
|
!Array.isArray(source[key])
|
|
) {
|
|
result[key] = deepMerge(target[key] || {}, source[key]);
|
|
} else {
|
|
if (!(key in result)) {
|
|
result[key] = source[key];
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function parseJsonc(file) {
|
|
if (!fs.existsSync(file)) {
|
|
return undefined;
|
|
}
|
|
const content = fs.readFileSync(file, "utf-8");
|
|
const errors = [];
|
|
const value = parse(content, errors, {
|
|
allowTrailingComma: true,
|
|
allowEmptyContent: true,
|
|
});
|
|
if (errors.length > 0) {
|
|
console.error(
|
|
`[merge-config] parse error in ${file}: ${errors
|
|
.map((e) => printParseErrorCode(e.error))
|
|
.join(", ")}`,
|
|
);
|
|
return undefined;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
let example;
|
|
try {
|
|
example = parseJsonc(exampleFile);
|
|
} catch {
|
|
process.exit(1);
|
|
}
|
|
|
|
if (example === undefined) {
|
|
process.exit(1);
|
|
}
|
|
|
|
let current = {};
|
|
try {
|
|
const parsed = parseJsonc(targetFile);
|
|
if (parsed !== undefined && parsed !== null) {
|
|
current = parsed;
|
|
}
|
|
} catch {
|
|
current = {};
|
|
}
|
|
|
|
const merged = deepMerge(current, example);
|
|
fs.writeFileSync(targetFile, `${JSON.stringify(merged, null, 4)}\n`);
|