@aravindc26/velu 0.11.20 → 0.11.21

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.ts +37 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aravindc26/velu",
3
- "version": "0.11.20",
3
+ "version": "0.11.21",
4
4
  "description": "A modern documentation site generator powered by Markdown and JSON configuration",
5
5
  "type": "module",
6
6
  "license": "MIT",
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, rmSync, readFileSync, statSync, symlinkSync } from "node:fs";
2
+ import { existsSync, mkdirSync, writeFileSync, readdirSync, copyFileSync, rmSync, readFileSync, statSync } from "node:fs";
3
3
  import { spawn } from "node:child_process";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
@@ -230,23 +230,34 @@ 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
+ }
233
235
 
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)) {
239
- try {
240
- symlinkSync(NODE_MODULES_PATH, outNodeModules, "junction");
241
- } catch {
242
- // Fall back to dir symlink on Linux if junction is unsupported
243
- try { symlinkSync(NODE_MODULES_PATH, outNodeModules, "dir"); } catch {}
236
+ function copyDirMerge(src: string, dest: string): void {
237
+ mkdirSync(dest, { recursive: true });
238
+ for (const entry of readdirSync(src)) {
239
+ const srcPath = join(src, entry);
240
+ const destPath = join(dest, entry);
241
+ if (statSync(srcPath).isDirectory()) {
242
+ copyDirMerge(srcPath, destPath);
243
+ } else {
244
+ copyFileSync(srcPath, destPath);
244
245
  }
245
246
  }
246
-
247
- return outDir;
248
247
  }
249
248
 
249
+ function prepareRuntimeOutDir(docsOutDir: string): string {
250
+ const runtimeOutDir = join(PACKAGE_ROOT, ".velu-out");
251
+ if (resolve(docsOutDir) === resolve(runtimeOutDir)) return runtimeOutDir;
252
+
253
+ // Remove previous output — best effort
254
+ try { rmSync(runtimeOutDir, { recursive: true, force: true }); } catch {}
255
+
256
+ // Always use manual copy — cpSync throws EEXIST on Node 20 if the
257
+ // directory cannot be fully removed (permissions, concurrent builds).
258
+ copyDirMerge(docsOutDir, runtimeOutDir);
259
+ return runtimeOutDir;
260
+ }
250
261
 
251
262
  async function buildStatic(outDir: string, docsDir: string) {
252
263
  await new Promise<void>((res, rej) => {
@@ -456,9 +467,17 @@ function addStaticRouteCompatibility(outDir: string) {
456
467
 
457
468
  async function buildSite(docsDir: string) {
458
469
  const docsOutDir = await generateProject(docsDir);
459
- await buildStatic(docsOutDir, docsDir);
460
- exportMarkdownRoutes(docsOutDir);
461
- addStaticRouteCompatibility(docsOutDir);
470
+ const runtimeOutDir = prepareRuntimeOutDir(docsOutDir);
471
+ await buildStatic(runtimeOutDir, docsDir);
472
+ exportMarkdownRoutes(runtimeOutDir);
473
+ addStaticRouteCompatibility(runtimeOutDir);
474
+
475
+ if (resolve(docsOutDir) !== resolve(runtimeOutDir)) {
476
+ const docsDistDir = join(docsOutDir, "dist");
477
+ const runtimeDistDir = join(runtimeOutDir, "dist");
478
+ try { rmSync(docsDistDir, { recursive: true, force: true }); } catch {}
479
+ copyDirMerge(runtimeDistDir, docsDistDir);
480
+ }
462
481
 
463
482
  const staticOutDir = join(docsOutDir, "dist");
464
483
  console.log(`\n📁 Static site output: ${staticOutDir}`);
@@ -482,7 +501,8 @@ function spawnServer(outDir: string, command: string, port: number, docsDir: str
482
501
 
483
502
  async function run(docsDir: string, port: number) {
484
503
  const docsOutDir = await generateProject(docsDir);
485
- spawnServer(docsOutDir, "dev", port, docsDir);
504
+ const runtimeOutDir = prepareRuntimeOutDir(docsOutDir);
505
+ spawnServer(runtimeOutDir, "dev", port, docsDir);
486
506
  }
487
507
 
488
508
  // ── Parse args ───────────────────────────────────────────────────────────────────