32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
#!/usr/bin/env node
|
|||
|
|
// validate_game.js — CLI front door: check a game spec, print every problem
|
||
|
|
// at once. Exit 0 = valid (warnings allowed), 1 = invalid.
|
||
|
|
//
|
||
|
|
// node tools/validate_game.js example/game.json
|
||
|
|
|
||
|
|
import { readFileSync } from "node:fs";
|
||
|
|
import { validate } from "../src/core/loader.js";
|
||
|
|
|
||
|
|
const file = process.argv[2];
|
||
|
|
if (!file) {
|
||
|
|
console.error("usage: node tools/validate_game.js <game.json>");
|
||
|
|
process.exit(2);
|
||
|
|
}
|
||
|
|
let spec;
|
||
|
|
try {
|
||
|
|
spec = JSON.parse(readFileSync(file, "utf8"));
|
||
|
|
} catch (e) {
|
||
|
|
console.error(`ERROR: ${file} is not valid JSON: ${e.message}`);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
const { errors, warnings } = validate(spec);
|
||
|
|
for (const w of warnings) console.warn("WARNING:", w);
|
||
|
|
if (errors.length) {
|
||
|
|
console.error(`ERROR: ${file}: spec invalid:`);
|
||
|
|
for (const e of errors) console.error(" - " + e);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
console.log(`OK: ${file} (${spec.rooms.length} rooms, ${spec.objects?.length ?? 0} objects, ` +
|
||
|
|
`${spec.characters.length} characters, ${spec.interactions?.length ?? 0} interactions, ` +
|
||
|
|
`${Object.keys(spec.dialogues ?? {}).length} dialogues, ${Object.keys(spec.scenes ?? {}).length} scenes)`);
|