Skip to content

Commit 813a36d

Browse files
committed
feat(cli): add start command to serve static site
1 parent b82bd84 commit 813a36d

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"dev": "objectdocs dev",
77
"build": "objectdocs build",
8+
"start": "objectdocs start",
89
"translate": "objectdocs translate",
910
"translate:all": "objectdocs translate --all"
1011
},

‎packages/cli/bin/cli.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import 'dotenv/config';
44
import { registerTranslateCommand } from '../src/commands/translate.mjs';
55
import { registerDevCommand } from '../src/commands/dev.mjs';
66
import { registerBuildCommand } from '../src/commands/build.mjs';
7+
import { registerStartCommand } from '../src/commands/start.mjs';
78

89
const cli = cac('objectdocs');
910

1011
registerTranslateCommand(cli);
1112
registerDevCommand(cli);
1213
registerBuildCommand(cli);
14+
registerStartCommand(cli);
1315

1416
cli.help();
1517
cli.version('0.0.1');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { spawn } from 'node:child_process';
2+
import path from 'node:path';
3+
4+
export function registerStartCommand(cli) {
5+
cli.command('start [dir]', 'Serve the static site')
6+
.action((dir = 'out') => {
7+
const targetDir = path.resolve(process.cwd(), dir);
8+
console.log(`Serving static site from: ${targetDir}`);
9+
10+
// Use npx serve to serve the directory
11+
const child = spawn('npx', ['serve', targetDir], {
12+
stdio: 'inherit',
13+
shell: true
14+
});
15+
16+
child.on('error', (err) => {
17+
console.error('Failed to start server:', err);
18+
console.log('You may need to install serve: npm install -g serve');
19+
});
20+
});
21+
}

0 commit comments

Comments
 (0)