@@ -18,7 +18,15 @@ import type { PackageManager } from './package-manager.js'
1818import type { ToolChain } from './toolchain.js'
1919import type { CliOptions , Framework } from './types.js'
2020
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+ } ) {
2230 const program = new Command ( )
2331
2432 program
@@ -46,7 +54,7 @@ export function cli() {
4654 // await initAddOn('overlay')
4755 // })
4856
49- program // 104 22
57+ program
5058 . argument ( '[project-name]' , 'name of the project' )
5159 . option ( '--no-git' , 'do not create a git repository' )
5260 . option ( '--target-dir <path>' , 'the directory to create the project in' )
@@ -65,22 +73,6 @@ export function cli() {
6573 } ,
6674 DEFAULT_FRAMEWORK ,
6775 )
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- )
8476 . option < PackageManager > (
8577 `--package-manager <${ SUPPORTED_PACKAGE_MANAGERS . join ( '|' ) } >` ,
8678 `Explicitly tell the CLI to use this package manager` ,
@@ -122,42 +114,68 @@ export function cli() {
122114 } ,
123115 )
124116 . 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)
126118 . option ( '--mcp' , 'run the MCP server' , false )
127119 . 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
139120
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` ,
156133 )
157- process . exit ( 1 )
158134 }
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 )
159176 }
160- } )
177+ }
178+ } )
161179
162180 program . parse ( )
163181}
0 commit comments