105 lines
3.1 KiB
JavaScript
105 lines
3.1 KiB
JavaScript
// Syncs the Nitro/Octane runtime config URLs from environment variables into the
|
|
// renderer-config.json / renderer-config.jsonc / ui-config.json files.
|
|
//
|
|
// Uses jsonc-parser so JSONC (with // and /* */ comments) is handled safely —
|
|
// unlike a naive JSON.parse/json.load this never corrupts URLs that contain
|
|
// "https://". After this runs the files are written back as strict JSON (which
|
|
// is still valid JSONC), so downstream validation passes.
|
|
//
|
|
// Env:
|
|
// NITRO_SRC_DIR e.g. /var/www/Octane/public/configuration
|
|
// NITRO_DIST_CONFIG_DIR e.g. /var/www/Octane/dist/configuration
|
|
// NITRO_GAMEDATA_CONF_DIR e.g. /var/www/Gamedata/config
|
|
// NITRO_IMAGE_LIBRARY_URL, NITRO_HOF_FURNITURE_URL, NITRO_API_URL,
|
|
// NITRO_SOCKET_URL, NITRO_GAMEDATA_URL, NITRO_ASSET_URL,
|
|
// NITRO_FURNI_ASSET_ICON_URL
|
|
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const { parse, modify } = require("jsonc-parser");
|
|
|
|
const FILES = [
|
|
"renderer-config.json",
|
|
"renderer-config.jsonc",
|
|
"ui-config.json",
|
|
];
|
|
|
|
function env(name) {
|
|
return process.env[name]?.length ? process.env[name] : null;
|
|
}
|
|
|
|
function applyOverrides(data) {
|
|
const image = env("NITRO_IMAGE_LIBRARY_URL");
|
|
const hof = env("NITRO_HOF_FURNITURE_URL");
|
|
const api = env("NITRO_API_URL");
|
|
const socket = env("NITRO_SOCKET_URL");
|
|
const gamedata = env("NITRO_GAMEDATA_URL");
|
|
const asset = env("NITRO_ASSET_URL");
|
|
const icon = env("NITRO_FURNI_ASSET_ICON_URL");
|
|
|
|
const set = (key, value) => {
|
|
if (value && !(key in data)) data[key] = value;
|
|
if (value) data[key] = value;
|
|
};
|
|
|
|
set("image.library.url", image);
|
|
set("hof.furni.url", hof);
|
|
set("api.url", api);
|
|
set("socket.url", socket);
|
|
set("gamedata.url", gamedata);
|
|
set("asset.url", asset);
|
|
set("furni.asset.icon.url", icon);
|
|
|
|
if (gamedata) {
|
|
data["radio.url"] = `${gamedata}/config/radio-stations.jsonc?t=%timestamp%`;
|
|
data["soundboard.url"] =
|
|
`${gamedata}/config/soundboard-sounds.jsonc?t=%timestamp%`;
|
|
}
|
|
if ("show.google.ads" in data) data["show.google.ads"] = false;
|
|
return data;
|
|
}
|
|
|
|
const dirs = [
|
|
env("NITRO_SRC_DIR"),
|
|
env("NITRO_DIST_CONFIG_DIR"),
|
|
env("NITRO_GAMEDATA_CONF_DIR"),
|
|
].filter(Boolean);
|
|
|
|
let changed = 0;
|
|
for (const dir of dirs) {
|
|
if (!fs.existsSync(dir)) continue;
|
|
for (const file of FILES) {
|
|
const full = path.join(dir, file);
|
|
if (!fs.existsSync(full)) continue;
|
|
let content;
|
|
try {
|
|
content = fs.readFileSync(full, "utf-8");
|
|
} catch {
|
|
continue;
|
|
}
|
|
let data;
|
|
try {
|
|
data = parse(content, [], {
|
|
allowTrailingComma: true,
|
|
allowEmptyContent: true,
|
|
});
|
|
} catch (e) {
|
|
console.error(`[sync-nitro-urls] parse error in ${full}: ${e}`);
|
|
continue;
|
|
}
|
|
if (!data || typeof data !== "object") continue;
|
|
const before = JSON.stringify(data);
|
|
const updated = applyOverrides(data);
|
|
if (JSON.stringify(updated) === before) continue;
|
|
try {
|
|
fs.writeFileSync(full, `${JSON.stringify(updated, null, 4)}\n`);
|
|
changed++;
|
|
console.log(` [OK] Synced URLs: ${file} (${dir})`);
|
|
} catch (e) {
|
|
console.error(`[sync-nitro-urls] write error ${full}: ${e}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(` [OK] URL sync complete (${changed} file(s) updated)`);
|
|
process.exit(0);
|