@aravindc26/velu 0.12.12 → 0.12.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
|
+
import { existsSync, utimesSync, statSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
2
4
|
import { generateSessionContent } from '@/lib/preview-content';
|
|
3
5
|
import { verifyApiSecret, unauthorizedResponse } from '@/lib/preview-auth';
|
|
4
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Touch source.config.ts to trigger fumadocs-mdx rescan,
|
|
9
|
+
* then wait for the .source output to regenerate.
|
|
10
|
+
*/
|
|
11
|
+
async function triggerMdxRegeneration(): Promise<void> {
|
|
12
|
+
const configPath = resolve(process.cwd(), 'source.config.ts');
|
|
13
|
+
const sourceDir = resolve(process.cwd(), '.source');
|
|
14
|
+
|
|
15
|
+
// Record current .source mtime (if it exists)
|
|
16
|
+
const beforeMtime = existsSync(sourceDir)
|
|
17
|
+
? statSync(sourceDir).mtimeMs
|
|
18
|
+
: 0;
|
|
19
|
+
|
|
20
|
+
// Touch source.config.ts to trigger chokidar → fumadocs-mdx full reload
|
|
21
|
+
const now = new Date();
|
|
22
|
+
utimesSync(configPath, now, now);
|
|
23
|
+
|
|
24
|
+
// Wait for .source directory to be updated (up to 30s)
|
|
25
|
+
for (let i = 0; i < 300; i++) {
|
|
26
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
27
|
+
if (existsSync(sourceDir)) {
|
|
28
|
+
const currentMtime = statSync(sourceDir).mtimeMs;
|
|
29
|
+
if (currentMtime > beforeMtime) return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
console.warn('[PREVIEW] MDX regeneration timed out after 30s');
|
|
33
|
+
}
|
|
34
|
+
|
|
5
35
|
export async function POST(
|
|
6
36
|
request: NextRequest,
|
|
7
37
|
{ params }: { params: Promise<{ sessionId: string }> },
|
|
@@ -12,6 +42,10 @@ export async function POST(
|
|
|
12
42
|
|
|
13
43
|
try {
|
|
14
44
|
const result = generateSessionContent(sessionId);
|
|
45
|
+
|
|
46
|
+
// Trigger fumadocs-mdx to discover the new content files
|
|
47
|
+
await triggerMdxRegeneration();
|
|
48
|
+
|
|
15
49
|
return Response.json({
|
|
16
50
|
status: 'ready',
|
|
17
51
|
url: `/${sessionId}/`,
|