@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.
- package/package.json +1 -1
- package/src/cli.ts +37 -17
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, rmSync, readFileSync, statSync
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
504
|
+
const runtimeOutDir = prepareRuntimeOutDir(docsOutDir);
|
|
505
|
+
spawnServer(runtimeOutDir, "dev", port, docsDir);
|
|
486
506
|
}
|
|
487
507
|
|
|
488
508
|
// ── Parse args ───────────────────────────────────────────────────────────────────
|