#!/usr/bin/env node // Build a writer's packet: everything a writer may see, and nothing else, in a folder OUTSIDE the repository (so a // writer started there sees no project instructions, no app code and no other split). // node budgetbench/writers/make-packet.mjs import fs from "node:fs"; import path from "node:path"; import {fileURLToPath} from "node:url"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const [hh, persona, out] = process.argv.slice(2); if (!out) { console.error("usage: make-packet.mjs "); process.exit(2); } fs.rmSync(out, {recursive: true, force: true}); fs.mkdirSync(path.join(out, "household/truth"), {recursive: true}); fs.mkdirSync(path.join(out, "tools"), {recursive: true}); for (const f of ["ledger.csv", "setup.json", "merchants.json"]) fs.copyFileSync(path.join(hh, "truth", f), path.join(out, "household/truth", f)); // (the setup's load list names the source files, which are not in the packet: drop it) const setup = JSON.parse(fs.readFileSync(path.join(out, "household/truth/setup.json"), "utf8")); delete setup.load; delete setup.shape; delete setup.region; fs.writeFileSync(path.join(out, "household/truth/setup.json"), JSON.stringify(setup, null, 1) + "\n"); fs.copyFileSync(path.join(HERE, "BRIEF.md"), path.join(out, "BRIEF.md")); fs.copyFileSync(path.join(HERE, "../help/HELP.md"), path.join(out, "HELP.md")); fs.copyFileSync(persona, path.join(out, "PERSONA.md")); fs.copyFileSync(path.join(HERE, "validate.mjs"), path.join(out, "tools/validate.mjs")); fs.copyFileSync(path.join(HERE, "../households/csv.mjs"), path.join(out, "tools/csv.mjs")); fs.writeFileSync(path.join(out, "tools/oracle.mjs"), fs.readFileSync(path.join(HERE, "../oracle/oracle.mjs"), "utf8").replace('"../households/csv.mjs"', '"./csv.mjs"')); console.log(`packet ready: ${out}`);