@aravindc26/velu 0.11.19 → 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 +38 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aravindc26/velu",
3
- "version": "0.11.19",
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
@@ -233,6 +233,31 @@ async function generateProject(docsDir: string): Promise<string> {
233
233
  return outDir;
234
234
  }
235
235
 
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);
245
+ }
246
+ }
247
+ }
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
+ }
236
261
 
237
262
  async function buildStatic(outDir: string, docsDir: string) {
238
263
  await new Promise<void>((res, rej) => {
@@ -442,9 +467,17 @@ function addStaticRouteCompatibility(outDir: string) {
442
467
 
443
468
  async function buildSite(docsDir: string) {
444
469
  const docsOutDir = await generateProject(docsDir);
445
- await buildStatic(docsOutDir, docsDir);
446
- exportMarkdownRoutes(docsOutDir);
447
- 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
+ }
448
481
 
449
482
  const staticOutDir = join(docsOutDir, "dist");
450
483
  console.log(`\n📁 Static site output: ${staticOutDir}`);
@@ -468,7 +501,8 @@ function spawnServer(outDir: string, command: string, port: number, docsDir: str
468
501
 
469
502
  async function run(docsDir: string, port: number) {
470
503
  const docsOutDir = await generateProject(docsDir);
471
- spawnServer(docsOutDir, "dev", port, docsDir);
504
+ const runtimeOutDir = prepareRuntimeOutDir(docsOutDir);
505
+ spawnServer(runtimeOutDir, "dev", port, docsDir);
472
506
  }
473
507
 
474
508
  // ── Parse args ───────────────────────────────────────────────────────────────────