@@ -15,7 +15,10 @@ import {
1515 getAllAddOns ,
1616} from '@tanstack/create'
1717
18- import { validateProjectName } from './utils.js'
18+ import {
19+ isCurrentDirectoryProjectNameInput ,
20+ validateProjectName ,
21+ } from './utils.js'
1922import type { AddOn , PackageManager } from '@tanstack/create'
2023
2124import type { Framework } from '@tanstack/create/dist/types/types.js'
@@ -29,7 +32,7 @@ export async function selectFramework(
2932 frameworks . find (
3033 ( f ) => f . id . toLowerCase ( ) === defaultFrameworkId . toLowerCase ( ) ,
3134 ) ?. id ) ||
32- frameworks [ 0 ] ! . id
35+ frameworks [ 0 ] . id
3336
3437 const selected = await select ( {
3538 message : 'Select framework:' ,
@@ -64,10 +67,10 @@ export async function selectInstall(): Promise<boolean> {
6467export async function getProjectName ( ) : Promise < string > {
6568 const value = await text ( {
6669 message : 'What would you like to name your project?' ,
67- defaultValue : 'my-app ' ,
70+ placeholder : 'Leave empty to initialize in the current directory ' ,
6871 validate ( value ) {
69- if ( ! value ) {
70- return 'Please enter a name'
72+ if ( isCurrentDirectoryProjectNameInput ( value ) ) {
73+ return
7174 }
7275
7376 const { valid, error } = validateProjectName ( value )
@@ -82,7 +85,7 @@ export async function getProjectName(): Promise<string> {
8285 process . exit ( 0 )
8386 }
8487
85- return value
88+ return value . trim ( )
8689}
8790
8891export async function selectPackageManager ( ) : Promise < PackageManager > {
@@ -284,34 +287,21 @@ export async function promptForAddOnOptions(
284287 addOnOptions [ addOnId ] = { }
285288
286289 for ( const [ optionName , option ] of Object . entries ( addOn . options ) ) {
287- if ( option && typeof option === 'object' && 'type' in option ) {
288- if ( option . type === 'select' ) {
289- const selectOption = option as {
290- type : 'select'
291- label : string
292- description ?: string
293- default : string
294- options : Array < { value : string ; label : string } >
295- }
296-
297- const value = await select ( {
298- message : `${ addOn . name } : ${ selectOption . label } ` ,
299- options : selectOption . options . map ( ( opt ) => ( {
300- value : opt . value ,
301- label : opt . label ,
302- } ) ) ,
303- initialValue : selectOption . default ,
304- } )
305-
306- if ( isCancel ( value ) ) {
307- cancel ( 'Operation cancelled.' )
308- process . exit ( 0 )
309- }
310-
311- addOnOptions [ addOnId ] [ optionName ] = value
312- }
313- // Future option types can be added here
290+ const value = await select ( {
291+ message : `${ addOn . name } : ${ option . label } ` ,
292+ options : option . options . map ( ( opt ) => ( {
293+ value : opt . value ,
294+ label : opt . label ,
295+ } ) ) ,
296+ initialValue : option . default ,
297+ } )
298+
299+ if ( isCancel ( value ) ) {
300+ cancel ( 'Operation cancelled.' )
301+ process . exit ( 0 )
314302 }
303+
304+ addOnOptions [ addOnId ] [ optionName ] = value
315305 }
316306 }
317307
0 commit comments