#!/usr/bin/env tsx // WRITE settings.json.example AND SETTINGS.md FROM THE SETTINGS SCHEMA. // // Usage (from the repo root): // pnpm --filter yt-dlp-transcript-common exec tsx bin/settings-example.ts // pnpm --filter yt-dlp-transcript-common exec tsx bin/settings-example.ts --check // // `--check` writes nothing and exits 1 if either committed file differs from // what the schema generates (the same claim common/lib/settingsDocs.test.ts // makes). `archilyzer settings example [--check]` calls main(). // // Reads no settings.json and writes no settings.json: both outputs are // functions of the schema alone. import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { renderSettingsExample, renderSettingsMarkdown, } from "../lib/settingsDocs"; import { parseFlags } from "./_parseFlags"; import { runIfEntryPoint } from "./_cli"; const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", ".."); const OUTPUTS: ReadonlyArray<[string, () => string]> = [ ["settings.json.example", renderSettingsExample], ["SETTINGS.md", renderSettingsMarkdown], ]; // `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 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" }), );