@aravindc26/velu 0.11.13 โ†’ 0.11.15

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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/build.ts +61 -18
  3. package/src/cli.ts +25 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aravindc26/velu",
3
- "version": "0.11.13",
3
+ "version": "0.11.15",
4
4
  "description": "A modern documentation site generator powered by Markdown and JSON configuration",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/build.ts CHANGED
@@ -9,11 +9,12 @@ import { normalizeConfigNavigation } from "./navigation-normalize.js";
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
  const PACKAGED_ENGINE_DIR = join(__dirname, "engine");
12
- const DEV_ENGINE_DIR = join(__dirname, "..", "src", "engine");
13
- const ENGINE_DIR = existsSync(DEV_ENGINE_DIR) ? DEV_ENGINE_DIR : PACKAGED_ENGINE_DIR;
14
- const PRIMARY_CONFIG_NAME = "docs.json";
15
- const LEGACY_CONFIG_NAME = "velu.json";
16
- const SOURCE_MIRROR_DIR = "velu-imports";
12
+ const DEV_ENGINE_DIR = join(__dirname, "..", "src", "engine");
13
+ const ENGINE_DIR = existsSync(DEV_ENGINE_DIR) ? DEV_ENGINE_DIR : PACKAGED_ENGINE_DIR;
14
+ const CLI_PACKAGE_JSON_PATH = join(__dirname, "..", "package.json");
15
+ const PRIMARY_CONFIG_NAME = "docs.json";
16
+ const LEGACY_CONFIG_NAME = "velu.json";
17
+ const SOURCE_MIRROR_DIR = "velu-imports";
17
18
 
18
19
  const SOURCE_MIRROR_EXTENSIONS = new Set([
19
20
  ".md", ".mdx", ".jsx", ".js", ".tsx", ".ts",
@@ -137,6 +138,9 @@ interface VeluRedirect {
137
138
 
138
139
  interface VeluConfig {
139
140
  $schema?: string;
141
+ name?: string;
142
+ title?: string;
143
+ description?: string;
140
144
  theme?: string;
141
145
  variables?: Record<string, string>;
142
146
  colors?: VeluColors;
@@ -587,7 +591,7 @@ const STATIC_EXTENSIONS = new Set([
587
591
  ".zip",
588
592
  ]);
589
593
 
590
- function copyStaticAssets(docsDir: string, publicDir: string) {
594
+ function copyStaticAssets(docsDir: string, publicDir: string) {
591
595
  function walk(dir: string) {
592
596
  const entries = readdirSync(dir, { withFileTypes: true });
593
597
  for (const entry of entries) {
@@ -611,12 +615,49 @@ function copyStaticAssets(docsDir: string, publicDir: string) {
611
615
  }
612
616
  }
613
617
 
614
- walk(docsDir);
615
- }
616
-
617
- function toPosixPath(value: string): string {
618
- return value.replace(/\\/g, "/");
619
- }
618
+ walk(docsDir);
619
+ }
620
+
621
+ function resolveProjectName(config: VeluConfig): string {
622
+ const fromName = typeof config.name === "string" ? config.name.trim() : "";
623
+ if (fromName) return fromName;
624
+ const fromTitle = typeof config.title === "string" ? config.title.trim() : "";
625
+ if (fromTitle) return fromTitle;
626
+ return "Documentation";
627
+ }
628
+
629
+ function resolveProjectDescription(config: VeluConfig): string {
630
+ if (typeof config.description === "string") return config.description.trim();
631
+ return "";
632
+ }
633
+
634
+ function resolveCliVersion(): string {
635
+ try {
636
+ const raw = readFileSync(CLI_PACKAGE_JSON_PATH, "utf-8");
637
+ const parsed = JSON.parse(raw) as { version?: unknown };
638
+ if (typeof parsed.version === "string" && parsed.version.trim().length > 0) {
639
+ return parsed.version.trim();
640
+ }
641
+ } catch {
642
+ // ignore and fallback
643
+ }
644
+ return "unknown";
645
+ }
646
+
647
+ function writeProjectConstFile(config: VeluConfig, outDir: string) {
648
+ const constPayload = {
649
+ name: resolveProjectName(config),
650
+ description: resolveProjectDescription(config),
651
+ version: resolveCliVersion(),
652
+ };
653
+
654
+ const constPath = join(outDir, "public", "const.json");
655
+ writeFileSync(constPath, `${JSON.stringify(constPayload, null, 2)}\n`, "utf-8");
656
+ }
657
+
658
+ function toPosixPath(value: string): string {
659
+ return value.replace(/\\/g, "/");
660
+ }
620
661
 
621
662
  function isInsideDocsRoot(docsDir: string, targetPath: string): boolean {
622
663
  const relPath = relative(docsDir, targetPath);
@@ -1167,12 +1208,14 @@ function build(docsDir: string, outDir: string) {
1167
1208
  console.log(`๐Ÿ“‹ Copied ${configName} as ${PRIMARY_CONFIG_NAME} (and legacy ${LEGACY_CONFIG_NAME})`);
1168
1209
 
1169
1210
  // โ”€โ”€ 3b. Copy static assets from docs project into public/ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1170
- copyStaticAssets(docsDir, join(outDir, "public"));
1171
- writeRedirectArtifacts(config, outDir);
1172
- if ((config.redirects ?? []).length > 0) {
1173
- console.log("โ†ช๏ธ Generated redirect artifacts");
1174
- }
1175
- console.log("๐Ÿ–ผ๏ธ Copied static assets");
1211
+ copyStaticAssets(docsDir, join(outDir, "public"));
1212
+ writeRedirectArtifacts(config, outDir);
1213
+ writeProjectConstFile(rawConfig, outDir);
1214
+ if ((config.redirects ?? []).length > 0) {
1215
+ console.log("โ†ช๏ธ Generated redirect artifacts");
1216
+ }
1217
+ console.log("๐Ÿงพ Generated const.json");
1218
+ console.log("๐Ÿ–ผ๏ธ Copied static assets");
1176
1219
 
1177
1220
  // โ”€โ”€ 4. Build content + metadata artifacts โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
1178
1221
  const contentDir = join(outDir, "content", "docs");
package/src/cli.ts CHANGED
@@ -35,6 +35,7 @@ function printHelp() {
35
35
  velu โ€” documentation site generator
36
36
 
37
37
  Usage:
38
+ velu version Print Velu CLI version
38
39
  velu init Scaffold a new docs project with example files
39
40
  velu lint Validate docs.json (or velu.json) and check referenced pages
40
41
  velu run [--port N] Build site and start dev server (default: 4321)
@@ -42,6 +43,7 @@ function printHelp() {
42
43
  velu paths Output navigation paths and source files as JSON (grouped by language)
43
44
 
44
45
  Options:
46
+ --version Show Velu CLI version
45
47
  --port <number> Port for the dev server (default: 4321)
46
48
  --help Show this help message
47
49
 
@@ -49,6 +51,24 @@ function printHelp() {
49
51
  `);
50
52
  }
51
53
 
54
+ function getCliVersion(): string {
55
+ try {
56
+ const pkgPath = join(PACKAGE_ROOT, "package.json");
57
+ const raw = readFileSync(pkgPath, "utf-8");
58
+ const parsed = JSON.parse(raw) as { version?: unknown };
59
+ if (typeof parsed.version === "string" && parsed.version.trim().length > 0) {
60
+ return parsed.version.trim();
61
+ }
62
+ } catch {
63
+ // ignore and fallback
64
+ }
65
+ return "unknown";
66
+ }
67
+
68
+ function printVersion() {
69
+ console.log(getCliVersion());
70
+ }
71
+
52
72
  // โ”€โ”€ init โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
53
73
 
54
74
  function init(targetDir: string) {
@@ -495,6 +515,11 @@ if (!command || command === "--help" || command === "-h") {
495
515
  process.exit(0);
496
516
  }
497
517
 
518
+ if (command === "version" || command === "--version" || command === "-v") {
519
+ printVersion();
520
+ process.exit(0);
521
+ }
522
+
498
523
  const docsDir = process.cwd();
499
524
 
500
525
  // init doesn't require docs.json