vehicle-generator/scripts/check-docs.ts
CRT d8f3a6e3df Vehicle Generator 0.1.0 (alpha)
Procedural, game-ready vehicles for three.js: 13 body styles, blending, seeded
random vehicles, three LODs, colliders, 13 parametric mods, paint and livery,
a rig that drives, and GLB export that a game can load and drive. Ships with a
studio (browser or Tauri desktop app) and a Play mode.
2026-10-11 00:22:23 +00:00

48 lines
2.2 KiB
TypeScript

/**
* Checks that the README still describes the generator that exists.
*
* Numbers in a README go stale the day something changes, and a confident
* wrong number is worse than none. So the ones it quotes — how many body
* styles, how many mods, the sedan's triangle counts per LOD — are checked
* against the code, and every style and mod has to be named.
*
* bun scripts/check-docs.ts
*/
import { readFileSync } from 'node:fs'
import { BODY_STYLES, generateVehicle, MOD_KINDS, preset } from '../src/generator/index.ts'
const failures: string[] = []
function expect(label: string, ok: boolean, detail = ''): void {
console.log(` ${ok ? 'PASS' : 'FAIL'} ${label}${!ok && detail ? ` — ${detail}` : ''}`)
if (!ok) failures.push(label)
}
const hasNumber = (text: string, value: number): boolean =>
new RegExp(`\\b${String(value).replace(/\B(?=(\d{3})+(?!\d))/g, '[ ,]?')}\\b`).test(text)
const sedan = generateVehicle(preset('sedan'))
const lods = sedan.lods.map((l) => l.triangles)
sedan.dispose()
const readme = readFileSync('README.md', 'utf8')
console.log('README.md')
expect('body style count', new RegExp(`\\b${BODY_STYLES.length} body styles\\b`).test(readme), `expected "${BODY_STYLES.length} body styles"`)
expect('mod count', new RegExp(`\\b${MOD_KINDS.length} (composable )?mods\\b`).test(readme), `expected "${MOD_KINDS.length} mods"`)
const missingStyles = BODY_STYLES.filter((s) => !readme.includes(`\`${s}\``))
expect('every body style named', missingStyles.length === 0, missingStyles.join(', '))
const missingMods = MOD_KINDS.filter((m) => !readme.includes(`\`${m}\``))
expect('every mod named', missingMods.length === 0, missingMods.join(', '))
for (const [i, n] of lods.entries()) expect(`sedan LOD${i} triangle count (${n})`, hasNumber(readme, n))
expect('no absolute user paths', !/[A-Z]:\\Users\\|\/Users\/|\/home\//.test(readme))
for (const image of [...readme.matchAll(/!\[[^\]]*\]\(([^)]+)\)/g)].map((m) => m[1]!)) {
let ok = true
try { readFileSync(image) } catch { ok = false }
expect(`image exists: ${image}`, ok)
}
if (failures.length) {
console.log(`${failures.length} documentation check(s) FAILED.`)
process.exit(1)
}
console.log('Documentation matches the generator.')