#!/usr/bin/env tsx // WRITE SITE.md, CHANNEL.md, REPORT.md AND CITATIONS.md FROM THE FILE SCHEMAS. // // Usage (from the repo root): // pnpm --filter yt-dlp-transcript-common exec tsx bin/file-schemas-docs.ts // pnpm --filter yt-dlp-transcript-common exec tsx bin/file-schemas-docs.ts --check // // `--check` writes nothing and exits 1 if any committed file differs from // what the schemas generate (the same claim common/lib/fileSchemaDocs.test.ts // and lib/report/docs.test.ts make). The sibling of settings-example.ts // (SETTINGS.md). // // Reads no site.json, config.json or report.json: every output is a function of // the schemas' docs records alone. import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { renderChannelMarkdown, renderSiteMarkdown, } from "../lib/fileSchemaDocs"; import { renderCitationsMarkdown } from "../lib/citations/docs"; import { renderReportMarkdown } from "../lib/report/docs"; import { parseFlags } from "./_parseFlags"; import { runIfEntryPoint } from "./_cli"; const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".."); const FILE_SCHEMA_OUTPUTS: ReadonlyArray<[string, () => string]> = [ ["SITE.md", renderSiteMarkdown], ["CHANNEL.md", renderChannelMarkdown], ["REPORT.md", renderReportMarkdown], ["CITATIONS.md", renderCitationsMarkdown], ]; // `check` writes nothing and returns 1 when a committed file is stale. export async function main(opts: { check?: boolean } = {}): Promise { const check = opts.check === true; let stale = 0; for (const [name, render] of FILE_SCHEMA_OUTPUTS) { const file = path.join(REPO, name); const want = render(); if (check) { const have = await readFile(file, "utf8").catch(() => ""); if (have !== want) { console.error(`${name} is stale — regenerate it`); stale++; } continue; } await writeFile(file, want); console.log(`wrote ${name}`); } return stale > 0 ? 1 : 0; } runIfEntryPoint(import.meta.url, () => main({ check: parseFlags(process.argv.slice(2)).check === "true" }), );