Files
time/ventures/havre/tools/cast.mjs
T

13 lines
834 B
JavaScript

// tools/cast.mjs: write cast/index.js, the ES module the page imports, from the cast/*.havre.json files next to it.
// Edit the .havre.json files, then run this (tools/build.sh does, every build): node tools/cast.mjs
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
const dir = new URL("../cast/", import.meta.url);
const files = readdirSync(dir).filter((f) => f.endsWith(".havre.json")).sort();
const cards = files.map((f) => JSON.parse(readFileSync(new URL(f, dir), "utf8")));
writeFileSync(fileURLToPath(new URL("index.js", dir)),
"// Generated by tools/cast.mjs from the .havre.json files next to it. Edit those, then run it again.\nexport default " +
JSON.stringify(cards, null, 1) + ";\n");
console.log(`cast/index.js: ${cards.map((c) => c.name).join(", ")}`);