Open History to see the last commit
1import { cac } from 'cac'
2import { getConfig } from '@tanstack/router-generator'
3import { generate } from './generate'
4import { watch } from './watch'
5β
6declare const __TSR_VERSION__: string
7β
8main()
9β
10export function main() {
11 const cli = cac('tsr')
12β
13 cli
14 .command('generate', 'Generate the routes for a project')
15 .action(async () => {
16 const config = getConfig()
17 await generate(config, process.cwd())
18 })
19β
20 cli
21 .command(
22 'watch',
23 'Continuously watch and generate the routes for a project',
24 )
25 .action(() => {
26 watch(process.cwd())
27 })
28β
29 cli.help()
30 cli.version(__TSR_VERSION__)
31β
32 try {
33 cli.parse()
34 } catch (err) {
35 // cac throws `CACError` for invalid usage (unknown option, extra args)
36 if (err instanceof Error && err.name === 'CACError') {
37 console.error(err.message)
38 process.exit(1)
39 }
40 throw err
41 }
42β
43 if (!cli.matchedCommand && !cli.options.help && !cli.options.version) {
44 // `tsr` and `tsr help` print help; unknown commands also exit with 1
45 if (cli.args.length && cli.args[0] !== 'help') {
46 console.error(`Unknown command: ${cli.args.join(' ')}\n`)
47 process.exitCode = 1
48 }
49 cli.outputHelp()
50 }
51}