@aravindc26/velu 0.12.14 → 0.12.15
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,52 +1,7 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync, statSync } from 'node:fs';
|
|
3
|
-
import { resolve } from 'node:path';
|
|
4
2
|
import { generateSessionContent } from '@/lib/preview-content';
|
|
5
3
|
import { verifyApiSecret, unauthorizedResponse } from '@/lib/preview-auth';
|
|
6
4
|
|
|
7
|
-
const RELOAD_MARKER = '\n// __RELOAD_TRIGGER__\n';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Modify source.config.ts content to trigger fumadocs-mdx rescan,
|
|
11
|
-
* then wait for the .source output to regenerate.
|
|
12
|
-
*
|
|
13
|
-
* Just touching mtime is not enough — chokidar detects content changes,
|
|
14
|
-
* not mtime changes. We toggle a comment to force a real content change.
|
|
15
|
-
*/
|
|
16
|
-
async function triggerMdxRegeneration(): Promise<void> {
|
|
17
|
-
const configPath = resolve(process.cwd(), 'source.config.ts');
|
|
18
|
-
const sourceDir = resolve(process.cwd(), '.source');
|
|
19
|
-
|
|
20
|
-
// Record current .source mtime (if it exists)
|
|
21
|
-
const beforeMtime = existsSync(sourceDir)
|
|
22
|
-
? statSync(sourceDir).mtimeMs
|
|
23
|
-
: 0;
|
|
24
|
-
|
|
25
|
-
// Toggle a comment in source.config.ts to force a real content change.
|
|
26
|
-
// chokidar detects this on local filesystem via inotify, which triggers
|
|
27
|
-
// fumadocs-mdx to fully re-scan the content directory (even on NFS).
|
|
28
|
-
const content = readFileSync(configPath, 'utf-8');
|
|
29
|
-
const newContent = content.includes(RELOAD_MARKER)
|
|
30
|
-
? content.replace(RELOAD_MARKER, '\n')
|
|
31
|
-
: content + RELOAD_MARKER;
|
|
32
|
-
writeFileSync(configPath, newContent, 'utf-8');
|
|
33
|
-
|
|
34
|
-
console.log('[PREVIEW] Triggered source.config.ts content change, waiting for MDX regeneration...');
|
|
35
|
-
|
|
36
|
-
// Wait for .source directory to be updated (up to 30s)
|
|
37
|
-
for (let i = 0; i < 300; i++) {
|
|
38
|
-
await new Promise((r) => setTimeout(r, 100));
|
|
39
|
-
if (existsSync(sourceDir)) {
|
|
40
|
-
const currentMtime = statSync(sourceDir).mtimeMs;
|
|
41
|
-
if (currentMtime > beforeMtime) {
|
|
42
|
-
console.log(`[PREVIEW] MDX regeneration detected after ${(i + 1) * 100}ms`);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
console.warn('[PREVIEW] MDX regeneration timed out after 30s');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
5
|
export async function POST(
|
|
51
6
|
request: NextRequest,
|
|
52
7
|
{ params }: { params: Promise<{ sessionId: string }> },
|
|
@@ -58,9 +13,6 @@ export async function POST(
|
|
|
58
13
|
try {
|
|
59
14
|
const result = generateSessionContent(sessionId);
|
|
60
15
|
|
|
61
|
-
// Trigger fumadocs-mdx to discover the new content files
|
|
62
|
-
await triggerMdxRegeneration();
|
|
63
|
-
|
|
64
16
|
return Response.json({
|
|
65
17
|
status: 'ready',
|
|
66
18
|
url: `/${sessionId}/`,
|