Skip to content

Commit beb4958

Browse files
committed
fix(docs): regenerate full text during development
1 parent 5b2f8cb commit beb4958

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

‎apps/docs/package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"private": true,
55
"license": "Apache-2.0",
66
"scripts": {
7-
"dev": "bun run dev:cache:cap && fumadocs-mdx && bun run llms-full:generate && next dev --port 3001",
7+
"dev": "bun run dev:cache:cap && bun run llms-full:generate && bunx concurrently --kill-others --names Next,LLMs \"next dev --port 3001\" \"bun scripts/watch-llms-full.ts\"",
88
"dev:cache:cap": "bun run ../../scripts/prune-turbopack-cache.ts",
99
"dev:clean": "rm -rf .next/dev/cache",
10-
"build": "fumadocs-mdx && bun run llms-full:generate && NODE_OPTIONS='--max-old-space-size=8192' next build",
10+
"build": "bun run llms-full:generate && NODE_OPTIONS='--max-old-space-size=8192' next build",
1111
"start": "next start",
1212
"postinstall": "fumadocs-mdx",
1313
"test": "vitest run",
@@ -16,7 +16,7 @@
1616
"lint:check": "biome check .",
1717
"format": "biome format --write .",
1818
"format:check": "biome format .",
19-
"llms-full:generate": "bun scripts/generate-llms-full.ts"
19+
"llms-full:generate": "fumadocs-mdx && bun scripts/generate-llms-full.ts"
2020
},
2121
"dependencies": {
2222
"@sim/db": "workspace:*",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { watch } from 'node:fs'
2+
import { createLogger } from '@sim/logger'
3+
import { spawn } from 'bun'
4+
import { OPENAPI_SPEC_FILES } from '@/lib/openapi-specs'
5+
6+
const logger = createLogger('DocsLlmsFullWatcher')
7+
const WATCHED_ROOT_FILES = new Set(['source.config.ts', ...OPENAPI_SPEC_FILES])
8+
9+
let debounceTimer: ReturnType<typeof setTimeout> | undefined
10+
let pending = false
11+
let running = false
12+
13+
async function regenerate(): Promise<void> {
14+
running = true
15+
try {
16+
while (pending) {
17+
pending = false
18+
const child = spawn(['bun', 'run', 'llms-full:generate'], {
19+
stdin: 'ignore',
20+
stdout: 'inherit',
21+
stderr: 'inherit',
22+
})
23+
const exitCode = await child.exited
24+
if (exitCode !== 0) {
25+
logger.warn('Documentation asset generation failed; retaining the previous asset', {
26+
exitCode,
27+
})
28+
}
29+
}
30+
} finally {
31+
running = false
32+
}
33+
}
34+
35+
function scheduleGeneration(): void {
36+
pending = true
37+
if (running) return
38+
if (debounceTimer) clearTimeout(debounceTimer)
39+
debounceTimer = setTimeout(() => {
40+
debounceTimer = undefined
41+
void regenerate()
42+
}, 250)
43+
}
44+
45+
for (const directory of ['content', 'lib']) {
46+
watch(directory, { recursive: true }, scheduleGeneration)
47+
}
48+
49+
watch('.', (_, changedPath) => {
50+
if (changedPath && WATCHED_ROOT_FILES.has(changedPath.toString())) scheduleGeneration()
51+
})

0 commit comments

Comments
 (0)