@aravindc26/velu 0.11.17 ā 0.11.19
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 +5 -63
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 } from "node:fs";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
@@ -233,55 +233,6 @@ async function generateProject(docsDir: string): Promise<string> {
|
|
|
233
233
|
return outDir;
|
|
234
234
|
}
|
|
235
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
|
-
|
|
257
|
-
try {
|
|
258
|
-
rmSync(runtimeOutDir, { recursive: true, force: true });
|
|
259
|
-
} catch {
|
|
260
|
-
// On Windows the directory may be locked by a previous dev-server process.
|
|
261
|
-
// Rename it aside so we can proceed; the stale copy is cleaned up later.
|
|
262
|
-
const stale = `${runtimeOutDir}-stale-${Date.now()}`;
|
|
263
|
-
try {
|
|
264
|
-
renameSync(runtimeOutDir, stale);
|
|
265
|
-
try { rmSync(stale, { recursive: true, force: true }); } catch {}
|
|
266
|
-
} catch {
|
|
267
|
-
// If even rename fails, clear contents so cpSync can work.
|
|
268
|
-
try {
|
|
269
|
-
for (const entry of readdirSync(runtimeOutDir)) {
|
|
270
|
-
rmSync(join(runtimeOutDir, entry), { recursive: true, force: true });
|
|
271
|
-
}
|
|
272
|
-
} catch {}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (existsSync(runtimeOutDir)) {
|
|
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;
|
|
284
|
-
}
|
|
285
236
|
|
|
286
237
|
async function buildStatic(outDir: string, docsDir: string) {
|
|
287
238
|
await new Promise<void>((res, rej) => {
|
|
@@ -491,17 +442,9 @@ function addStaticRouteCompatibility(outDir: string) {
|
|
|
491
442
|
|
|
492
443
|
async function buildSite(docsDir: string) {
|
|
493
444
|
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
|
-
}
|
|
445
|
+
await buildStatic(docsOutDir, docsDir);
|
|
446
|
+
exportMarkdownRoutes(docsOutDir);
|
|
447
|
+
addStaticRouteCompatibility(docsOutDir);
|
|
505
448
|
|
|
506
449
|
const staticOutDir = join(docsOutDir, "dist");
|
|
507
450
|
console.log(`\nš Static site output: ${staticOutDir}`);
|
|
@@ -525,8 +468,7 @@ function spawnServer(outDir: string, command: string, port: number, docsDir: str
|
|
|
525
468
|
|
|
526
469
|
async function run(docsDir: string, port: number) {
|
|
527
470
|
const docsOutDir = await generateProject(docsDir);
|
|
528
|
-
|
|
529
|
-
spawnServer(runtimeOutDir, "dev", port, docsDir);
|
|
471
|
+
spawnServer(docsOutDir, "dev", port, docsDir);
|
|
530
472
|
}
|
|
531
473
|
|
|
532
474
|
// āā Parse args āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
|