#!/usr/bin/env node /** * Build-time docs renderer (spec: markdown -> immutable static HTML; marked * is a devDep, the service serves only static output). * Writes docs/dist/.html plus a manifest.json for /api/docs. */ import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { Marked } from 'marked' const root = join(dirname(fileURLToPath(import.meta.url)), '..') const srcDir = join(root, 'docs') const outDir = join(root, 'docs/dist') const marked = new Marked() const page = (title, body) => ` ${title} ยท will docs
${body}
` const pages = [] await mkdir(outDir, { recursive: true }) for (const file of (await readdir(srcDir)).filter((f) => f.endsWith('.md')).sort()) { const name = file.replace(/\.md$/, '') const raw = await readFile(join(srcDir, file), 'utf8') const body = await marked.parse(raw) await writeFile(join(outDir, `${name}.html`), page(name, body), 'utf8') pages.push(name) } await writeFile( join(outDir, 'index.html'), page('docs', ``), 'utf8', ) await writeFile(join(outDir, 'manifest.json'), JSON.stringify({ pages }, null, 2), 'utf8') console.log(`docs: rendered ${pages.length} pages -> docs/dist`)