Skip to content

Commit 8fa7f6f

Browse files
authored
Merge pull request #15 from clidey/claude/issue-14-20250623_044710
feat: add dory CLI tool with build and preview commands
2 parents a994063 + 7727bbf commit 8fa7f6f

File tree

4 files changed

+229
-4
lines changed

4 files changed

+229
-4
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,49 @@ Dory is:
3838

3939
---
4040

41-
## 🧑‍💻 Quick Start
41+
## 📦 CLI Installation
42+
43+
Install Dory globally to use the CLI tool:
44+
45+
```bash
46+
npm install -g dory
47+
```
48+
49+
### CLI Usage
50+
51+
Once installed, you can use the `dory` command:
52+
53+
#### `dory build`
54+
Builds your documentation site:
55+
- Checks for `dory.json` in current directory
56+
- Clears and prepares the `docs` folder
57+
- Copies configuration to `docs` folder
58+
- Runs the build process
59+
- Creates `dist` folder with build output
60+
61+
```bash
62+
dory build
63+
```
64+
65+
#### `dory preview`
66+
Previews the built documentation site:
67+
- Requires `dist` folder (run `dory build` first)
68+
- Starts a local preview server
69+
70+
```bash
71+
dory preview
72+
```
73+
74+
#### `dory help`
75+
Shows CLI usage information:
76+
77+
```bash
78+
dory help
79+
```
80+
81+
---
82+
83+
## 🧑‍💻 Development Setup
4284

4385
Follow these steps to set up and preview the documentation locally, as well as build a static site for deployment.
4486

bin/dory.js

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env node
2+
3+
import { execSync } from 'child_process';
4+
import { existsSync, rmSync, mkdirSync, cpSync, readFileSync } from 'fs';
5+
import { resolve, dirname } from 'path';
6+
import { fileURLToPath } from 'url'
7+
import http from 'http';
8+
import sirv from 'sirv';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = dirname(__filename);
12+
13+
const commands = {
14+
build: () => {
15+
console.log('🏗️ Starting Dory build...');
16+
17+
// Check if dory.json exists in current directory
18+
const currentDir = process.cwd();
19+
const doryConfigPath = resolve(currentDir, 'dory.json');
20+
21+
if (!existsSync(doryConfigPath)) {
22+
console.error('❌ dory.json not found in current directory');
23+
process.exit(1);
24+
}
25+
26+
// Read and validate dory.json
27+
try {
28+
const config = JSON.parse(readFileSync(doryConfigPath, 'utf8'));
29+
console.log(`📋 Using config: ${config.name || 'Unnamed project'}`);
30+
} catch (error) {
31+
console.error('❌ Invalid dory.json file:', error.message);
32+
process.exit(1);
33+
}
34+
35+
// Clear and prepare docs folder
36+
const docsDir = resolve(currentDir, 'docs');
37+
if (existsSync(docsDir)) {
38+
console.log('🧹 Clearing docs folder...');
39+
rmSync(docsDir, { recursive: true, force: true });
40+
}
41+
mkdirSync(docsDir, { recursive: true });
42+
43+
// Copy dory.json to docs folder
44+
cpSync(doryConfigPath, resolve(docsDir, 'dory.json'));
45+
console.log('📄 Copied dory.json to docs folder');
46+
47+
// Run the build command
48+
console.log('⚡ Running build command...');
49+
try {
50+
execSync('npm run build', { stdio: 'inherit', cwd: __dirname });
51+
} catch (error) {
52+
console.error('❌ Build failed:', error.message);
53+
process.exit(1);
54+
}
55+
56+
// Check if dist folder was created
57+
const distDir = resolve(__dirname, '..', 'dist');
58+
if (existsSync(distDir)) {
59+
console.log('✅ Build completed successfully!');
60+
console.log(`📦 Build output available in: ${distDir}`);
61+
console.log('📋 Moving build output to current directory...');
62+
cpSync(distDir, resolve(currentDir, 'dist'), { recursive: true });
63+
console.log(`📦 Build output moved to: ${resolve(currentDir, 'dist')}`);
64+
} else {
65+
console.log('⚠️ Build completed but no dist folder found');
66+
}
67+
rmSync(distDir, { recursive: true, force: true });
68+
},
69+
70+
preview: () => {
71+
console.log('👀 Starting Dory preview...');
72+
const currentDir = process.cwd();
73+
const distDir = resolve(currentDir, 'dist');
74+
const port = process.env.PORT || 3000;
75+
76+
const serve = sirv(distDir, {
77+
dev: false,
78+
single: true,
79+
etag: true,
80+
gzip: true,
81+
brotli: true,
82+
});
83+
84+
const server = http.createServer((req, res) => {
85+
serve(req, res);
86+
});
87+
88+
server.listen(port, () => {
89+
console.log(`🚀 Serving Dory at http://localhost:${port}`);
90+
});
91+
},
92+
93+
help: () => {
94+
console.log(`
95+
🐟 Dory CLI - Documentation Build Tool
96+
97+
Usage:
98+
dory <command>
99+
100+
Commands:
101+
build Build the documentation site
102+
- Requires dory.json in current directory
103+
- Clears and copies to docs folder
104+
- Runs build command
105+
- Creates dist folder with build output
106+
107+
preview Preview the built documentation site
108+
- Requires dist folder (run build first)
109+
- Starts preview server
110+
111+
help Show this help message
112+
113+
Examples:
114+
dory build # Build the documentation
115+
dory preview # Preview the built site
116+
`);
117+
}
118+
};
119+
120+
// Parse command line arguments
121+
const command = process.argv[2];
122+
123+
if (!command || command === 'help' || command === '--help' || command === '-h') {
124+
commands.help();
125+
} else if (commands[command]) {
126+
commands[command]();
127+
} else {
128+
console.error(`❌ Unknown command: ${command}`);
129+
console.log('Run "dory help" for usage information');
130+
process.exit(1);
131+
}

package.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
{
2-
"name": "doc-engine-v2",
3-
"private": true,
4-
"version": "0.0.0",
2+
"name": "@clidey/dory",
3+
"private": false,
4+
"version": "1.0.0",
55
"type": "module",
6+
"description": "A CLI tool for building and previewing documentation sites",
7+
"keywords": [
8+
"cli",
9+
"documentation",
10+
"build",
11+
"preview",
12+
"static-site"
13+
],
14+
"bin": {
15+
"dory": "./bin/dory.js"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "https://github.com/clidey/dory.git"
20+
},
21+
"author": "Clidey",
22+
"license": "MIT",
23+
"homepage": "https://github.com/clidey/dory",
24+
"bugs": {
25+
"url": "https://github.com/clidey/dory/issues"
26+
},
627
"scripts": {
728
"dev": "vite",
829
"build": "tsc -b && vite build",
@@ -32,6 +53,7 @@
3253
"react-highlight-words": "^0.21.0",
3354
"remark-gfm": "^4.0.1",
3455
"saas": "^1.0.0",
56+
"sirv": "^3.0.1",
3557
"tailwindcss": "^4.1.8",
3658
"unist-util-visit": "^5.0.0",
3759
"vite-plugin-mdx": "^3.6.1",

pnpm-lock.yaml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)