-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
38 lines (32 loc) · 1.34 KB
/
Copy pathindex.ts
File metadata and controls
38 lines (32 loc) · 1.34 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
34
35
36
37
38
#!/usr/bin/env node
/**
* HonestJS CLI entry point.
* Registers commands (new, list, info, doctor, generate) and parses CLI arguments.
* Version is read from package.json at runtime.
*/
import { Command } from 'commander'
import { existsSync, readFileSync } from 'fs'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'
import { doctorCommand } from './commands/doctor.js'
import { generateCommand } from './commands/generate.js'
import { infoCommand } from './commands/info.js'
import { listCommand } from './commands/list.js'
import { newCommand } from './commands/new.js'
import { handleCommandError } from './utils/errors.js'
const __dirname = dirname(fileURLToPath(import.meta.url))
const pkgPath = [join(__dirname, 'package.json'), join(__dirname, '..', 'package.json')].find((p) => existsSync(p))
if (!pkgPath) throw new Error('Could not find CLI package.json')
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
const program = new Command()
program.name('honestjs').description('CLI tool for scaffolding honestjs projects').version(pkg.version)
program.addCommand(newCommand)
program.addCommand(listCommand)
program.addCommand(infoCommand)
program.addCommand(doctorCommand)
program.addCommand(generateCommand)
try {
await program.parseAsync()
} catch (err) {
handleCommandError(err, { json: process.argv.includes('--json') })
}