Files
healer-man/scripts/coa-reference/baseline.mjs
T

29 lines
1.2 KiB
JavaScript

import fs from "node:fs";
import path from "node:path";
import { gzipSync, gunzipSync } from "node:zlib";
export const julyBaselinePath = "data/coa-reference/baselines/coa-july-2026-07-25.json.gz";
export const activeCatalogPath = "src/game/coaLiveData.generated.json";
export function resolveBaselinePath(projectRoot) {
return fs.existsSync(path.join(projectRoot, julyBaselinePath)) ? julyBaselinePath : activeCatalogPath;
}
export function decodeJsonBytes(bytes, filePath) {
return filePath.endsWith(".gz") ? gunzipSync(bytes) : bytes;
}
/** Preserve the original capture once; never replace it with a promoted catalog. */
export function freezeJulyBaseline(projectRoot) {
const destination = path.join(projectRoot, julyBaselinePath);
if (fs.existsSync(destination)) return destination;
const bytes = fs.readFileSync(path.join(projectRoot, activeCatalogPath));
const capture = JSON.parse(bytes.toString("utf8"));
if (capture.source?.synchronizedAt !== "2026-07-25T05:24:40.596Z") {
throw new Error("Cannot freeze July baseline: active catalog is not the original July capture");
}
fs.mkdirSync(path.dirname(destination), { recursive: true });
fs.writeFileSync(destination, gzipSync(bytes, { level: 9 }), { flag: "wx" });
return destination;
}