-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.ts
More file actions
33 lines (28 loc) · 1.02 KB
/
dev.ts
File metadata and controls
33 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Command } from 'commander'
import { spawn } from 'child_process'
import path from 'path'
import fs from 'fs'
import chalk from 'chalk'
import { attachLifecycleHandlers, resolveNextCli } from '@/cli/utils'
export const devCommand = new Command('dev')
.description('Start development server')
.option('-p, --port <port>', 'Port number', '3000')
.action((options) => {
const scaffoldPath = path.join(process.cwd(), '.chronicle')
if (!fs.existsSync(scaffoldPath)) {
console.log(chalk.red('Error: .chronicle/ not found. Run'), chalk.cyan('chronicle init'), chalk.red('first.'))
process.exit(1)
}
const nextCli = resolveNextCli()
console.log(chalk.cyan('Starting dev server...'))
const child = spawn(process.execPath, [nextCli, 'dev', '-p', options.port], {
stdio: 'inherit',
cwd: scaffoldPath,
env: {
...process.env,
CHRONICLE_PROJECT_ROOT: process.cwd(),
CHRONICLE_CONTENT_DIR: './content',
},
})
attachLifecycleHandlers(child)
})