diff --git a/.github/workflows/web-ci.yml b/.github/workflows/web-ci.yml index f3c0c9d3e..9007b399d 100644 --- a/.github/workflows/web-ci.yml +++ b/.github/workflows/web-ci.yml @@ -34,6 +34,9 @@ jobs: - name: Install dependencies run: bun install --frozen-lockfile + - name: Generate docs content from repo-root docs/ + run: node ./scripts/generate-docs-content.mjs + - name: Format check run: bun run format:check diff --git a/web/.gitignore b/web/.gitignore index 769e3b67e..e542d48b5 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -53,3 +53,4 @@ next-env.d.ts /playwright-report/ /blob-report/ /playwright/.cache/ +lib/docs-content.generated.ts diff --git a/web/app/[locale]/docs/page.tsx b/web/app/[locale]/docs/page.tsx index 0cf27cba0..cda0c62b7 100644 --- a/web/app/[locale]/docs/page.tsx +++ b/web/app/[locale]/docs/page.tsx @@ -8,12 +8,10 @@ import { loadDocSource } from "@/lib/docs-source" export default async function DocsPage() { const t = await getTranslations("docs") - const sectionsWithSource = await Promise.all( - DOC_SECTIONS.map(async (section) => ({ - ...section, - source: await loadDocSource(section.file), - })), - ) + const sectionsWithSource = DOC_SECTIONS.map((section) => ({ + ...section, + source: loadDocSource(section.file), + })) return ( { - const fullPath = path.join(DOCS_ROOT, file) - return readFile(fullPath, "utf8") +export function loadDocSource(file: string): string { + const source = DOC_SOURCES[file] + if (source === undefined) { + throw new Error(`Unknown doc file: ${file}`) + } + return source } diff --git a/web/package.json b/web/package.json index 716d184c9..56d1c9583 100644 --- a/web/package.json +++ b/web/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { + "prepare": "node ./scripts/generate-docs-content.mjs", "prebuild": "node ./scripts/prepare-build.mjs", "dev": "next dev", "build": "next build", diff --git a/web/scripts/generate-docs-content.mjs b/web/scripts/generate-docs-content.mjs new file mode 100644 index 000000000..65dc884d6 --- /dev/null +++ b/web/scripts/generate-docs-content.mjs @@ -0,0 +1,31 @@ +import { readFile, writeFile } from "node:fs/promises" +import path from "node:path" + +const SECTIONS = [ + { file: "guide/overview.md" }, + { file: "guide/installation.md" }, + { file: "guide/orchestration.md" }, + { file: "guide/agent-model-matching.md" }, + { file: "guide/team-mode.md" }, + { file: "reference/cli.md" }, + { file: "reference/configuration.md" }, + { file: "reference/features.md" }, + { file: "manifesto.md" }, +] + +const DOCS_ROOT = path.resolve(process.cwd(), "..", "docs") +const OUTPUT = path.resolve(process.cwd(), "lib", "docs-content.generated.ts") + +const sources = {} +for (const s of SECTIONS) { + sources[s.file] = await readFile(path.join(DOCS_ROOT, s.file), "utf8") +} + +const out = + "// Generated by scripts/generate-docs-content.mjs - DO NOT EDIT\n" + + "export const DOC_SOURCES: Record = " + + JSON.stringify(sources, null, 2) + + "\n" + +await writeFile(OUTPUT, out) +console.log("Generated " + OUTPUT + " with " + SECTIONS.length + " docs sources") diff --git a/web/scripts/prepare-build.mjs b/web/scripts/prepare-build.mjs index d6980f982..49d5e8330 100644 --- a/web/scripts/prepare-build.mjs +++ b/web/scripts/prepare-build.mjs @@ -1,7 +1,10 @@ import { rmSync } from "node:fs" +import { execSync } from "node:child_process" const buildCachePaths = [".next/cache/fetch-cache"] for (const filePath of buildCachePaths) { rmSync(filePath, { force: true, recursive: true }) } + +execSync("node ./scripts/generate-docs-content.mjs", { stdio: "inherit" })