@aravindc26/velu 0.1.2 → 0.2.0

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/README.md CHANGED
@@ -10,52 +10,21 @@ npm install -g @aravindc26/velu
10
10
 
11
11
  ## Quick Start
12
12
 
13
- 1. Create a directory with your docs:
14
-
15
- ```
16
- my-docs/
17
- velu.json
18
- quickstart.md
19
- guides/
20
- installation.md
21
- editor.md
22
- ```
23
-
24
- 2. Define your navigation in `velu.json`:
25
-
26
- ```json
27
- {
28
- "$schema": "https://raw.githubusercontent.com/aravindc26/velu/main/schema/velu.schema.json",
29
- "navigation": {
30
- "tabs": [
31
- {
32
- "tab": "API Reference",
33
- "pages": ["api-reference/get", "api-reference/post"]
34
- }
35
- ],
36
- "groups": [
37
- {
38
- "group": "Getting Started",
39
- "pages": ["quickstart", "guides/installation"]
40
- }
41
- ]
42
- }
43
- }
44
- ```
45
-
46
- 3. Run the dev server:
47
-
48
13
  ```bash
49
- cd my-docs
14
+ mkdir my-docs && cd my-docs
15
+ velu init
50
16
  velu run
51
17
  ```
52
18
 
53
19
  Your site is live at `http://localhost:4321`.
54
20
 
21
+ `velu init` scaffolds a complete example project with `velu.json`, sample pages, tabs, and groups — ready to customize.
22
+
55
23
  ## CLI Commands
56
24
 
57
25
  | Command | Description |
58
26
  | -------------------- | ------------------------------------------------ |
27
+ | `velu init` | Scaffold a new docs project with example files |
59
28
  | `velu lint` | Validate `velu.json` and check referenced pages |
60
29
  | `velu run` | Build and start the dev server (default port 4321)|
61
30
  | `velu run --port N` | Start on a custom port |
package/bin/velu.mjs CHANGED
@@ -1,15 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from "node:child_process";
4
+ import { createRequire } from "node:module";
4
5
  import { dirname, join } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
7
 
7
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
8
- const cliPath = join(__dirname, "..", "src", "cli.ts");
9
+ const pkgRoot = join(__dirname, "..");
10
+ const cliPath = join(pkgRoot, "src", "cli.ts");
11
+
12
+ // Resolve tsx from the package's own node_modules, not the user's CWD
13
+ const require = createRequire(join(pkgRoot, "package.json"));
14
+ const tsxPath = pathToFileURL(require.resolve("tsx")).href;
9
15
 
10
16
  const child = spawn(
11
17
  process.execPath,
12
- ["--import", "tsx", cliPath, ...process.argv.slice(2)],
18
+ ["--import", tsxPath, cliPath, ...process.argv.slice(2)],
13
19
  { stdio: "inherit", cwd: process.cwd() }
14
20
  );
15
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aravindc26/velu",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
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 } from "node:path";
2
- import { existsSync } from "node:fs";
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
3
  import { spawn } from "node:child_process";
4
4
  import { fileURLToPath } from "node:url";
5
5
 
@@ -14,6 +14,7 @@ function printHelp() {
14
14
  velu — documentation site generator
15
15
 
16
16
  Usage:
17
+ velu init Scaffold a new docs project with example files
17
18
  velu lint Validate velu.json and check referenced pages
18
19
  velu run [--port N] Build site and start dev server (default: 4321)
19
20
  velu build Build site without starting the dev server
@@ -22,10 +23,73 @@ function printHelp() {
22
23
  --port <number> Port for the dev server (default: 4321)
23
24
  --help Show this help message
24
25
 
25
- Run these commands from a directory containing velu.json.
26
+ Run lint/run/build from a directory containing velu.json.
26
27
  `);
27
28
  }
28
29
 
30
+ // ── init ────────────────────────────────────────────────────────────────────────
31
+
32
+ function init(targetDir: string) {
33
+ if (existsSync(join(targetDir, "velu.json"))) {
34
+ console.error("❌ velu.json already exists in this directory.");
35
+ process.exit(1);
36
+ }
37
+
38
+ // velu.json
39
+ const config = {
40
+ $schema: "https://raw.githubusercontent.com/aravindc26/velu/main/schema/velu.schema.json",
41
+ navigation: {
42
+ tabs: [
43
+ {
44
+ tab: "API Reference",
45
+ pages: ["api-reference/overview", "api-reference/authentication"],
46
+ },
47
+ ],
48
+ groups: [
49
+ {
50
+ group: "Getting Started",
51
+ pages: ["quickstart", "installation"],
52
+ },
53
+ {
54
+ group: "Guides",
55
+ pages: ["guides/configuration", "guides/deployment"],
56
+ },
57
+ ],
58
+ },
59
+ };
60
+ writeFileSync(join(targetDir, "velu.json"), JSON.stringify(config, null, 2) + "\n", "utf-8");
61
+
62
+ // Example pages
63
+ const pages: Record<string, string> = {
64
+ "quickstart.md": `# Quickstart\n\nWelcome to your new documentation site!\n\n## Prerequisites\n\n- Node.js 18+\n- npm\n\n## Getting Started\n\n1. Edit the markdown files in this directory\n2. Update \`velu.json\` to configure navigation\n3. Run \`velu run\` to start the dev server\n\n\`\`\`bash\nvelu run\n\`\`\`\n\nYour site is live at \`http://localhost:4321\`.\n`,
65
+ "installation.md": `# Installation\n\nInstall Velu globally:\n\n\`\`\`bash\nnpm install -g @aravindc26/velu\n\`\`\`\n\nOr run directly with npx:\n\n\`\`\`bash\nnpx @aravindc26/velu run\n\`\`\`\n`,
66
+ "guides/configuration.md": `# Configuration\n\nVelu uses a \`velu.json\` file to define your site's navigation.\n\n## Navigation Structure\n\n- **Tabs** — Top-level horizontal navigation\n- **Groups** — Collapsible sidebar sections\n- **Pages** — Individual markdown documents\n\n## Example\n\n\`\`\`json\n{\n "navigation": {\n "groups": [\n {\n "group": "Getting Started",\n "pages": ["quickstart"]\n }\n ]\n }\n}\n\`\`\`\n`,
67
+ "guides/deployment.md": `# Deployment\n\nBuild your site for production:\n\n\`\`\`bash\nvelu build\n\`\`\`\n\nThe output is a static site you can deploy anywhere — Netlify, Vercel, GitHub Pages, etc.\n`,
68
+ "api-reference/overview.md": `# API Overview\n\nThis section covers the API reference for your project.\n\n## Endpoints\n\n| Method | Path | Description |\n|--------|------|-------------|\n| GET | /api/health | Health check |\n| POST | /api/data | Create data |\n`,
69
+ "api-reference/authentication.md": `# Authentication\n\nAll API requests require an API key.\n\n## Headers\n\n\`\`\`\nAuthorization: Bearer YOUR_API_KEY\n\`\`\`\n\n## Getting an API Key\n\nVisit the dashboard to generate your API key.\n`,
70
+ };
71
+
72
+ for (const [filePath, content] of Object.entries(pages)) {
73
+ const fullPath = join(targetDir, filePath);
74
+ mkdirSync(dirname(fullPath), { recursive: true });
75
+ writeFileSync(fullPath, content, "utf-8");
76
+ }
77
+
78
+ console.log("");
79
+ console.log(" \x1b[36mvelu\x1b[0m project initialized");
80
+ console.log("");
81
+ console.log(" Created:");
82
+ console.log(" velu.json");
83
+ for (const filePath of Object.keys(pages)) {
84
+ console.log(` ${filePath}`);
85
+ }
86
+ console.log("");
87
+ console.log(" Next steps:");
88
+ console.log(" velu run Start the dev server");
89
+ console.log(" velu lint Validate your config");
90
+ console.log("");
91
+ }
92
+
29
93
  // ── lint ─────────────────────────────────────────────────────────────────────────
30
94
 
31
95
  async function lint(docsDir: string) {
@@ -99,9 +163,15 @@ if (!command || command === "--help" || command === "-h") {
99
163
 
100
164
  const docsDir = process.cwd();
101
165
 
166
+ // init doesn't require velu.json
167
+ if (command === "init") {
168
+ init(docsDir);
169
+ process.exit(0);
170
+ }
171
+
102
172
  if (!existsSync(join(docsDir, "velu.json"))) {
103
173
  console.error("❌ No velu.json found in the current directory.");
104
- console.error(" Run this command from a directory containing velu.json.");
174
+ console.error(" Run `velu init` to scaffold a new project, or run from a directory containing velu.json.");
105
175
  process.exit(1);
106
176
  }
107
177