@aravindc26/velu 0.11.17 ā 0.11.20
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 +1 -1
- package/src/cli.ts +15 -59
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve, join, dirname, delimiter } from "node:path";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync, readdirSync, copyFileSync,
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync, readdirSync, copyFileSync, rmSync, readFileSync, statSync, symlinkSync } from "node:fs";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
@@ -230,59 +230,24 @@ async function generateProject(docsDir: string): Promise<string> {
|
|
|
230
230
|
// Generate into the active docs project directory.
|
|
231
231
|
const outDir = join(docsDir, ".velu-out");
|
|
232
232
|
build(docsDir, outDir);
|
|
233
|
-
return outDir;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function samePath(a: string, b: string): boolean {
|
|
237
|
-
return resolve(a).replace(/\\/g, "/").toLowerCase() === resolve(b).replace(/\\/g, "/").toLowerCase();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function copyDirMerge(src: string, dest: string): void {
|
|
241
|
-
mkdirSync(dest, { recursive: true });
|
|
242
|
-
for (const entry of readdirSync(src)) {
|
|
243
|
-
const srcPath = join(src, entry);
|
|
244
|
-
const destPath = join(dest, entry);
|
|
245
|
-
if (statSync(srcPath).isDirectory()) {
|
|
246
|
-
copyDirMerge(srcPath, destPath);
|
|
247
|
-
} else {
|
|
248
|
-
copyFileSync(srcPath, destPath);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function prepareRuntimeOutDir(docsOutDir: string): string {
|
|
254
|
-
const runtimeOutDir = join(PACKAGE_ROOT, ".velu-out");
|
|
255
|
-
if (samePath(docsOutDir, runtimeOutDir)) return runtimeOutDir;
|
|
256
233
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const stale = `${runtimeOutDir}-stale-${Date.now()}`;
|
|
234
|
+
// Symlink the package's node_modules into the output directory so ESM imports
|
|
235
|
+
// (e.g. fumadocs-mdx in next.config.mjs) resolve correctly when building
|
|
236
|
+
// from a temp directory outside the package root.
|
|
237
|
+
const outNodeModules = join(outDir, "node_modules");
|
|
238
|
+
if (!existsSync(outNodeModules)) {
|
|
263
239
|
try {
|
|
264
|
-
|
|
265
|
-
try { rmSync(stale, { recursive: true, force: true }); } catch {}
|
|
240
|
+
symlinkSync(NODE_MODULES_PATH, outNodeModules, "junction");
|
|
266
241
|
} catch {
|
|
267
|
-
//
|
|
268
|
-
try {
|
|
269
|
-
for (const entry of readdirSync(runtimeOutDir)) {
|
|
270
|
-
rmSync(join(runtimeOutDir, entry), { recursive: true, force: true });
|
|
271
|
-
}
|
|
272
|
-
} catch {}
|
|
242
|
+
// Fall back to dir symlink on Linux if junction is unsupported
|
|
243
|
+
try { symlinkSync(NODE_MODULES_PATH, outNodeModules, "dir"); } catch {}
|
|
273
244
|
}
|
|
274
245
|
}
|
|
275
246
|
|
|
276
|
-
|
|
277
|
-
// cpSync fails with EEXIST when the destination directory exists (Node 20).
|
|
278
|
-
// Fall back to a manual recursive copy that handles existing directories.
|
|
279
|
-
copyDirMerge(docsOutDir, runtimeOutDir);
|
|
280
|
-
} else {
|
|
281
|
-
cpSync(docsOutDir, runtimeOutDir, { recursive: true, force: true });
|
|
282
|
-
}
|
|
283
|
-
return runtimeOutDir;
|
|
247
|
+
return outDir;
|
|
284
248
|
}
|
|
285
249
|
|
|
250
|
+
|
|
286
251
|
async function buildStatic(outDir: string, docsDir: string) {
|
|
287
252
|
await new Promise<void>((res, rej) => {
|
|
288
253
|
const child = spawn("node", ["_server.mjs", "build"], {
|
|
@@ -491,17 +456,9 @@ function addStaticRouteCompatibility(outDir: string) {
|
|
|
491
456
|
|
|
492
457
|
async function buildSite(docsDir: string) {
|
|
493
458
|
const docsOutDir = await generateProject(docsDir);
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
addStaticRouteCompatibility(runtimeOutDir);
|
|
498
|
-
|
|
499
|
-
if (!samePath(docsOutDir, runtimeOutDir)) {
|
|
500
|
-
const docsDistDir = join(docsOutDir, "dist");
|
|
501
|
-
const runtimeDistDir = join(runtimeOutDir, "dist");
|
|
502
|
-
rmSync(docsDistDir, { recursive: true, force: true });
|
|
503
|
-
cpSync(runtimeDistDir, docsDistDir, { recursive: true, force: true });
|
|
504
|
-
}
|
|
459
|
+
await buildStatic(docsOutDir, docsDir);
|
|
460
|
+
exportMarkdownRoutes(docsOutDir);
|
|
461
|
+
addStaticRouteCompatibility(docsOutDir);
|
|
505
462
|
|
|
506
463
|
const staticOutDir = join(docsOutDir, "dist");
|
|
507
464
|
console.log(`\nš Static site output: ${staticOutDir}`);
|
|
@@ -525,8 +482,7 @@ function spawnServer(outDir: string, command: string, port: number, docsDir: str
|
|
|
525
482
|
|
|
526
483
|
async function run(docsDir: string, port: number) {
|
|
527
484
|
const docsOutDir = await generateProject(docsDir);
|
|
528
|
-
|
|
529
|
-
spawnServer(runtimeOutDir, "dev", port, docsDir);
|
|
485
|
+
spawnServer(docsOutDir, "dev", port, docsDir);
|
|
530
486
|
}
|
|
531
487
|
|
|
532
488
|
// āā Parse args āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|