// Regenerates everything derived from the rules registry// (packages/cli/src/rules/registry.js):// - docs/rules.md every v1 code, as `tsus explain` prints it// - docs/v2/rules.md every v2 code, with why it stays, and what became of v1 rules// - the code table in AGENTS.md (the template `tsus init` copies, and the repo copy)// `node scripts/docs.mjs --check` fails instead of writing when anything is// stale, fails when a TSUS4xx, 5xx or 6xx rule has no rejection example, and runs every v2// registry example through the v2 checker.import fs from "node:fs";import path from "node:path";import { fileURLToPath } from "node:url";import { REGISTRY } from "../packages/cli/src/rules/registry.js";import { renderRulesDoc, renderCodeTable, renderV2RulesDoc } from "../packages/cli/src/explain.js";import { V2_REGISTRY } from "../packages/cli/src/v2/registry.js";import { testV2Registry } from "./v2-registry-test.mjs";const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");const check = process.argv.includes("--check");const template = path.join(repoRoot, "packages/cli/templates/AGENTS.md");const withTable = (text) => text.replace( /<!-- tsus:codes:start -->[\s\S]*?<!-- tsus:codes:end -->/, `<!-- tsus:codes:start -->\n${renderCodeTable()}\n<!-- tsus:codes:end -->`, );const agents = withTable(fs.readFileSync(template, "utf8"));const outputs = [ [template, agents], [path.join(repoRoot, "AGENTS.md"), agents], [path.join(repoRoot, "docs/rules.md"), renderRulesDoc()], [path.join(repoRoot, "docs/v2/rules.md"), renderV2RulesDoc()],];const problems = [];for (const [file, content] of outputs) { const current = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : ""; if (current === content) { continue; } if (check) { problems.push(`${path.relative(repoRoot, file)} is stale; run npm run docs`); } else { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, content); console.log(`wrote ${path.relative(repoRoot, file)}`); }}// Every strictness rule needs an example that is rejected with its code.const exampleCodes = new Set();const examplesDir = path.join(repoRoot, "examples");for (const name of fs.readdirSync(examplesDir)) { const manifest = path.join(examplesDir, name, "example.json"); if (fs.existsSync(manifest)) { for (const code of JSON.parse(fs.readFileSync(manifest, "utf8")).codes ?? []) { exampleCodes.add(code); } }}for (const rule of [...REGISTRY, ...V2_REGISTRY]) { if (/^TSUS(4|5|6)\d\d$/.test(rule.code) && !exampleCodes.has(rule.code)) { problems.push(`${rule.code} has no rejection example under examples/`); }}// Every v2 registry example runs through the v2 checker: bad ones rejected with their own code,// good ones accepted.problems.push(...testV2Registry());if (problems.length > 0) { console.error(problems.join("\n")); process.exit(1);}if (check) { console.log("docs are in sync with the rules registry");}