@@ -18,7 +18,15 @@ import type { PackageManager } from './package-manager.js'
18
18
import type { ToolChain } from './toolchain.js'
19
19
import type { CliOptions , Framework } from './types.js'
20
20
21
- export function cli ( ) {
21
+ export function cli ( {
22
+ name,
23
+ forcedMode,
24
+ forcedAddOns,
25
+ } : {
26
+ name : string
27
+ forcedMode ?: 'typescript' | 'javascript' | 'file-router'
28
+ forcedAddOns ?: Array < string >
29
+ } ) {
22
30
const program = new Command ( )
23
31
24
32
program
@@ -46,7 +54,7 @@ export function cli() {
46
54
// await initAddOn('overlay')
47
55
// })
48
56
49
- program // 104 22
57
+ program
50
58
. argument ( '[project-name]' , 'name of the project' )
51
59
. option ( '--no-git' , 'do not create a git repository' )
52
60
. option ( '--target-dir <path>' , 'the directory to create the project in' )
@@ -65,22 +73,6 @@ export function cli() {
65
73
} ,
66
74
DEFAULT_FRAMEWORK ,
67
75
)
68
- . option < 'typescript' | 'javascript' | 'file-router' > (
69
- '--template <type>' ,
70
- 'project template (typescript, javascript, file-router)' ,
71
- ( value ) => {
72
- if (
73
- value !== 'typescript' &&
74
- value !== 'javascript' &&
75
- value !== 'file-router'
76
- ) {
77
- throw new InvalidArgumentError (
78
- `Invalid template: ${ value } . Only the following are allowed: typescript, javascript, file-router` ,
79
- )
80
- }
81
- return value
82
- } ,
83
- )
84
76
. option < PackageManager > (
85
77
`--package-manager <${ SUPPORTED_PACKAGE_MANAGERS . join ( '|' ) } >` ,
86
78
`Explicitly tell the CLI to use this package manager` ,
@@ -122,42 +114,68 @@ export function cli() {
122
114
} ,
123
115
)
124
116
. option ( '--list-add-ons' , 'list all available add-ons' , false )
125
- . option ( '--overlay [url]' , 'add an overlay from a URL' , false )
117
+ // .option('--overlay [url]', 'add an overlay from a URL', false)
126
118
. option ( '--mcp' , 'run the MCP server' , false )
127
119
. option ( '--mcp-sse' , 'run the MCP server in SSE mode' , false )
128
- . action ( async ( projectName : string , options : CliOptions ) => {
129
- if ( options . listAddOns ) {
130
- await listAddOns ( options )
131
- } else if ( options . mcp || options . mcpSse ) {
132
- await runServer ( ! ! options . mcpSse )
133
- } else {
134
- try {
135
- const cliOptions = {
136
- projectName,
137
- ...options ,
138
- } as CliOptions
139
120
140
- let finalOptions = await normalizeOptions ( cliOptions )
141
- if ( finalOptions ) {
142
- intro ( `Creating a new TanStack app in ${ projectName } ...` )
143
- } else {
144
- intro ( "Let's configure your TanStack application" )
145
- finalOptions = await promptForOptions ( cliOptions )
146
- }
147
- await createApp ( finalOptions , {
148
- environment : createDefaultEnvironment ( ) ,
149
- cwd : options . targetDir || undefined ,
150
- } )
151
- } catch ( error ) {
152
- log . error (
153
- error instanceof Error
154
- ? error . message
155
- : 'An unknown error occurred' ,
121
+ if ( ! forcedMode ) {
122
+ program . option < 'typescript' | 'javascript' | 'file-router' > (
123
+ '--template <type>' ,
124
+ 'project template (typescript, javascript, file-router)' ,
125
+ ( value ) => {
126
+ if (
127
+ value !== 'typescript' &&
128
+ value !== 'javascript' &&
129
+ value !== 'file-router'
130
+ ) {
131
+ throw new InvalidArgumentError (
132
+ `Invalid template: ${ value } . Only the following are allowed: typescript, javascript, file-router` ,
156
133
)
157
- process . exit ( 1 )
158
134
}
135
+ return value
136
+ } ,
137
+ )
138
+ }
139
+
140
+ program . action ( async ( projectName : string , options : CliOptions ) => {
141
+ if ( options . listAddOns ) {
142
+ await listAddOns ( options )
143
+ } else if ( options . mcp || options . mcpSse ) {
144
+ await runServer ( ! ! options . mcpSse )
145
+ } else {
146
+ try {
147
+ const cliOptions = {
148
+ projectName,
149
+ ...options ,
150
+ } as CliOptions
151
+
152
+ if ( forcedMode ) {
153
+ cliOptions . template = forcedMode
154
+ }
155
+
156
+ let finalOptions = await normalizeOptions ( cliOptions , forcedAddOns )
157
+ if ( finalOptions ) {
158
+ intro ( `Creating a new TanStack app in ${ projectName } ...` )
159
+ } else {
160
+ intro ( "Let's configure your TanStack application" )
161
+ finalOptions = await promptForOptions ( cliOptions , {
162
+ forcedMode,
163
+ forcedAddOns,
164
+ } )
165
+ }
166
+ await createApp ( finalOptions , {
167
+ environment : createDefaultEnvironment ( ) ,
168
+ cwd : options . targetDir || undefined ,
169
+ name,
170
+ } )
171
+ } catch ( error ) {
172
+ log . error (
173
+ error instanceof Error ? error . message : 'An unknown error occurred' ,
174
+ )
175
+ process . exit ( 1 )
159
176
}
160
- } )
177
+ }
178
+ } )
161
179
162
180
program . parse ( )
163
181
}
0 commit comments