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
|
- name: Install dependencies
|
||||||
run: bun install --frozen-lockfile
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Generate docs content from repo-root docs/
|
||||||
|
run: node ./scripts/generate-docs-content.mjs
|
||||||
|
|
||||||
- name: Format check
|
- name: Format check
|
||||||
run: bun run format:check
|
run: bun run format:check
|
||||||
|
|
||||||
|
|||||||
@@ -53,3 +53,4 @@ next-env.d.ts
|
|||||||
/playwright-report/
|
/playwright-report/
|
||||||
/blob-report/
|
/blob-report/
|
||||||
/playwright/.cache/
|
/playwright/.cache/
|
||||||
|
lib/docs-content.generated.ts
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ import { loadDocSource } from "@/lib/docs-source"
|
|||||||
export default async function DocsPage() {
|
export default async function DocsPage() {
|
||||||
const t = await getTranslations("docs")
|
const t = await getTranslations("docs")
|
||||||
|
|
||||||
const sectionsWithSource = await Promise.all(
|
const sectionsWithSource = DOC_SECTIONS.map((section) => ({
|
||||||
DOC_SECTIONS.map(async (section) => ({
|
...section,
|
||||||
...section,
|
source: loadDocSource(section.file),
|
||||||
source: await loadDocSource(section.file),
|
}))
|
||||||
})),
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocsShell
|
<DocsShell
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { readFile } from "node:fs/promises"
|
import { DOC_SOURCES } from "./docs-content.generated"
|
||||||
import path from "node:path"
|
|
||||||
|
|
||||||
const DOCS_ROOT = path.resolve(process.cwd(), "..", "docs")
|
export function loadDocSource(file: string): string {
|
||||||
|
const source = DOC_SOURCES[file]
|
||||||
export async function loadDocSource(file: string): Promise<string> {
|
if (source === undefined) {
|
||||||
const fullPath = path.join(DOCS_ROOT, file)
|
throw new Error(`Unknown doc file: ${file}`)
|
||||||
return readFile(fullPath, "utf8")
|
}
|
||||||
|
return source
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"prepare": "node ./scripts/generate-docs-content.mjs",
|
||||||
"prebuild": "node ./scripts/prepare-build.mjs",
|
"prebuild": "node ./scripts/prepare-build.mjs",
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"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 { rmSync } from "node:fs"
|
||||||
|
import { execSync } from "node:child_process"
|
||||||
|
|
||||||
const buildCachePaths = [".next/cache/fetch-cache"]
|
const buildCachePaths = [".next/cache/fetch-cache"]
|
||||||
|
|
||||||
for (const filePath of buildCachePaths) {
|
for (const filePath of buildCachePaths) {
|
||||||
rmSync(filePath, { force: true, recursive: true })
|
rmSync(filePath, { force: true, recursive: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
execSync("node ./scripts/generate-docs-content.mjs", { stdio: "inherit" })
|
||||||
|
|||||||
Reference in New Issue
Block a user