Files
oh-my-opencode/packages/web/scripts/generate-docs-content.mjs
T
YeonGyu-Kim 68b80e0343 perf(web): optimize CI + build pipeline
- web-ci.yml: cache .next/cache via actions/cache; drop duplicate
  next build (was running twice — typecheck + main); workflow now
  short-circuits on cache hits.
- scripts/prepare-build.mjs: gate fetch-cache purge behind
  PREPARE_BUILD_PURGE_CACHE env (default off). preview/deploy npm
  scripts no longer invoke it.
- scripts/generate-docs-content.mjs: skip write when content
  unchanged (idempotent); avoids "file mtime changed" cache busts.
- eslint.config.mjs: strip rules already enforced by Biome
  (formatting, import order, unused vars) — removes redundant
  passes, halves lint time on cold runs.
- playwright.config.ts: 2 workers in CI (was 1); webServer command
  uses already-built artifacts via 'bun run build'.

Cold build: 16.2s → 8.7s (-46%). Recompile 1.45s.
2026-05-20 14:26:08 +09:00

73 lines
2.4 KiB
JavaScript

import { readFile, writeFile } from "node:fs/promises"
import path from "node:path"
import { Marked } from "marked"
const SECTIONS = [
{ id: "overview", file: "guide/overview.md" },
{ id: "installation", file: "guide/installation.md" },
{ id: "orchestration", file: "guide/orchestration.md" },
{ id: "agent-model-matching", file: "guide/agent-model-matching.md" },
{ id: "team-mode", file: "guide/team-mode.md" },
{ id: "cli", file: "reference/cli.md" },
{ id: "configuration", file: "reference/configuration.md" },
{ id: "features", file: "reference/features.md" },
{ id: "manifesto", file: "manifesto.md" },
]
const DOCS_ROOT = path.resolve(process.cwd(), "..", "..", "docs")
const OUTPUT = path.resolve(process.cwd(), "lib", "docs-content.generated.ts")
const sectionIdByFile = new Map(SECTIONS.map((section) => [section.file, section.id]))
function rewriteDocsLink(sourceFile, href) {
if (!href || href.startsWith("#") || href.startsWith("//")) return href
if (/^[a-z][a-z0-9+.-]*:/i.test(href)) return href
const [hrefPath] = href.split("#", 1)
if (!hrefPath) return href
const sourceDirectory = path.posix.dirname(sourceFile)
const targetFile = path.posix.normalize(path.posix.join(sourceDirectory, hrefPath))
const sectionId = sectionIdByFile.get(targetFile)
return sectionId ? `#${sectionId}` : href
}
function createMarked(sourceFile) {
const marked = new Marked({ gfm: true, breaks: false })
marked.use({
walkTokens(token) {
if (token.type !== "link") return
token.href = rewriteDocsLink(sourceFile, token.href)
},
})
return marked
}
const sources = {}
for (const s of SECTIONS) {
const md = await readFile(path.join(DOCS_ROOT, s.file), "utf8")
sources[s.file] = await createMarked(s.file).parse(md)
}
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"
async function outputIsCurrent(content) {
try {
const { readFile } = await import("node:fs/promises")
return (await readFile(OUTPUT, "utf8")) === content
} catch {
return false
}
}
if (await outputIsCurrent(out)) {
process.stdout.write("Docs content already current with " + SECTIONS.length + " HTML-compiled docs\n")
} else {
await writeFile(OUTPUT, out)
process.stdout.write("Generated " + OUTPUT + " with " + SECTIONS.length + " HTML-compiled docs\n")
}