Files
oh-my-pi/packages/coding-agent/scripts/generate-docs-index.ts
T

31 lines
1.1 KiB
TypeScript

#!/usr/bin/env bun
import { Glob } from "bun";
import * as path from "node:path";
const docsDir = new URL("../../../docs/", import.meta.url).pathname;
const outputPath = new URL("../src/internal-urls/docs-index.generated.ts", import.meta.url).pathname;
const glob = new Glob("**/*.md");
const entries: string[] = [];
for await (const relativePath of glob.scan(docsDir)) {
entries.push(relativePath.split(path.sep).join("/"));
}
entries.sort();
const docs = [...entries];
const mapEntries = await Promise.all(
docs.map(async (relativePath) => {
const content = await Bun.file(path.join(docsDir, relativePath)).text();
return `\t"${relativePath}": ${JSON.stringify(content)},`;
}),
);
const output = `// Auto-generated by scripts/generate-docs-index.ts - DO NOT EDIT\n\nexport const EMBEDDED_DOCS: Readonly<Record<string, string>> = {\n${mapEntries.join("\n")}\n};\n\nexport const EMBEDDED_DOC_FILENAMES = Object.keys(EMBEDDED_DOCS).sort();\n`;
await Bun.write(outputPath, output);
console.log(`Generated ${path.relative(process.cwd(), outputPath)} (${docs.length} docs)`);