Merge pull request #3860 from code-yeongyu/fix/web-docs-bundle-at-build
fix(web): bundle docs at build time, worker has no fs to call
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -53,3 +53,4 @@ next-env.d.ts
|
||||
/playwright-report/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
lib/docs-content.generated.ts
|
||||
|
||||
@@ -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 (
|
||||
<DocsShell
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { readFile } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
import { DOC_SOURCES } from "./docs-content.generated"
|
||||
|
||||
const DOCS_ROOT = path.resolve(process.cwd(), "..", "docs")
|
||||
|
||||
export async function loadDocSource(file: string): Promise<string> {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<string, string> = " +
|
||||
JSON.stringify(sources, null, 2) +
|
||||
"\n"
|
||||
|
||||
await writeFile(OUTPUT, out)
|
||||
console.log("Generated " + OUTPUT + " with " + SECTIONS.length + " docs sources")
|
||||
@@ -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" })
|
||||
|
||||
Reference in New Issue
Block a user