gen-rfc-index.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Regenerate `docs/rfc/INDEX.md` — the fully generated RFC index — from the
  3. * RFC tree (see [rfc-index.ts](./rfc-index.ts) for the layout contract and
  4. * rendering rules). The whole file is generated state; the curated prose lives
  5. * in `docs/rfc/README.md`. Freshness is asserted by
  6. * `verify-rfc-classification.ts` (a `doc-sync` member), so a stale committed
  7. * index fails CI.
  8. *
  9. * Run: `pnpm run gen-rfc-index`.
  10. */
  11. import { readFileSync, writeFileSync } from 'node:fs'
  12. import { resolve } from 'node:path'
  13. import { renderIndex, rfcRoot, walkRfcTree } from './rfc-index.ts'
  14. const { rfcs, errors } = walkRfcTree()
  15. if (errors.length > 0) {
  16. console.error('gen-rfc-index: refusing to generate from a structurally invalid tree:')
  17. for (const e of errors) console.error(` ${e}`)
  18. process.exit(1)
  19. }
  20. const indexPath = resolve(rfcRoot, 'INDEX.md')
  21. const next = renderIndex(rfcs)
  22. let current: string | undefined
  23. try {
  24. current = readFileSync(indexPath, 'utf8')
  25. } catch {
  26. // Missing INDEX.md is the fresh-generation case, not an error: fall through and write it.
  27. }
  28. if (next === current) {
  29. console.log(`gen-rfc-index: docs/rfc/INDEX.md is up to date (${rfcs.length} RFCs).`)
  30. } else {
  31. writeFileSync(indexPath, next)
  32. console.log(`gen-rfc-index: docs/rfc/INDEX.md regenerated (${rfcs.length} RFCs).`)
  33. }