// Rebuild `../fixtures/pinned-documents.ts` from the documents themselves. // // bun skills/iso-24495-5/tests/reference/build-pinned-documents.ts // // It prints the line counts and rewrites the fixture in place. Run it from the // repository root, in the same commit as any edit to a document it covers. // // The fixture holds these documents whole rather than in pieces. Reviews taught // that lesson twice over. First inside the text: a pinned phrase leaves every // other phrase of its sentence deletable, so the expectations became whole // blocks. Then around it: a whole block says nothing about the lines either // side of it, and a review wrapped a pinned paragraph in image syntax so that // it rendered as alternative text. The text was intact, the gate was green, and // a browser showed neither. // // This script is checked in because the last generator was not. A reviewer // twice said a claim about a script nobody could run was unsupported, and was // right both times. A test runs this command, because the reviewer then found // it broken by a missing import while the gate stayed green. import { readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { SHIPPED_DOCUMENTS } from "./shipped-documents.ts"; const REPOSITORY_ROOT = join(import.meta.dir, "..", "..", "..", ".."); // Written where told, so a check can rebuild without touching the fixture // it is checking. A test ran this command against the fixture itself, and a // failing run then adopted the change it had just rejected. const FIXTURE = process.argv[2] ?? join(import.meta.dir, "..", "fixtures", "pinned-documents.ts"); const entries = SHIPPED_DOCUMENTS.map((file) => { const lines = readFileSync(join(REPOSITORY_ROOT, file), "utf8").split(/\r?\n/); console.log(`${file}: ${lines.length} lines`); const body = lines.map((line) => ` ${JSON.stringify(line)},`).join("\n"); return ` ${JSON.stringify(file)}: [\n${body}\n ],`; }).join("\n"); const contents = `// Generated by ../reference/build-pinned-documents.ts. Do not edit by hand. // // Every line of every document this repository pins. Run the builder in the // same commit as any edit to one of them, and read the diff here as the record // of what a reader's page gained or lost. export const PINNED_DOCUMENT_TEXT: Record = { ${entries} }; `; writeFileSync(FIXTURE, contents, "utf8"); console.log(`wrote ${FIXTURE}`);