@@ -22,21 +22,17 @@ import {
2222 detectExistingAgentTargetPath ,
2323 writeAgentInstructions ,
2424} from '../utils/index.js' ;
25+ import { getVitePlusHeader } from '../utils/terminal.js' ;
2526import type { ExecutionResult } from './command.js' ;
2627import { discoverTemplate , inferParentDir } from './discovery.js' ;
27- import {
28- cancelAndExit ,
29- checkProjectDirExists ,
30- promptPackageNameAndTargetDir ,
31- } from './prompts.js' ;
28+ import { cancelAndExit , checkProjectDirExists , promptPackageNameAndTargetDir } from './prompts.js' ;
3229import {
3330 executeBuiltinTemplate ,
3431 executeMonorepoTemplate ,
3532 executeRemoteTemplate ,
3633} from './templates/index.js' ;
3734import { BuiltinTemplate , TemplateType } from './templates/types.js' ;
3835import { formatTargetDir } from './utils.js' ;
39- import { getVitePlusHeader } from '../utils/terminal.js' ;
4036
4137const { blue, cyan, green, gray } = colors ;
4238
@@ -115,8 +111,7 @@ function parseArgs() {
115111 const viteArgs = separatorIndex >= 0 ? args . slice ( 0 , separatorIndex ) : args ;
116112
117113 // Arguments after -- are template options
118- const templateArgs =
119- separatorIndex >= 0 ? args . slice ( separatorIndex + 1 ) : [ ] ;
114+ const templateArgs = separatorIndex >= 0 ? args . slice ( separatorIndex + 1 ) : [ ] ;
120115
121116 const parsed = mri < {
122117 directory ?: string ;
@@ -171,9 +166,7 @@ Template name is required when running in non-interactive mode
171166Usage: vite new [TEMPLATE] [OPTIONS] [-- TEMPLATE_OPTIONS]
172167
173168Example:
174- ${ gray (
175- '# Create a new application in non-interactive mode with a custom target directory' ,
176- ) }
169+ ${ gray ( '# Create a new application in non-interactive mode with a custom target directory' ) }
177170 vite new vite:application --no-interactive --directory=apps/my-app
178171
179172Use \`vite new --list\` to list all available templates, or run \`vite new --help\` for more information.
@@ -292,10 +285,7 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
292285
293286 const isBuiltinTemplate = selectedTemplateName . startsWith ( 'vite:' ) ;
294287 if ( targetDir && ! isBuiltinTemplate ) {
295- cancelAndExit (
296- 'The --directory option is only available for builtin templates' ,
297- 1 ,
298- ) ;
288+ cancelAndExit ( 'The --directory option is only available for builtin templates' , 1 ) ;
299289 }
300290 if ( selectedTemplateName === BuiltinTemplate . monorepo && isMonorepo ) {
301291 prompts . log . info (
@@ -371,16 +361,11 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
371361 packageName = selected . packageName ;
372362 targetDir = selected . targetDir ;
373363 } else {
374- let defaultPackageName = `vite-plus-${
375- selectedTemplateName . split ( ':' ) [ 1 ]
376- } `;
364+ let defaultPackageName = `vite-plus-${ selectedTemplateName . split ( ':' ) [ 1 ] } ` ;
377365 if ( workspaceInfoOptional . monorepoScope ) {
378366 defaultPackageName = `${ workspaceInfoOptional . monorepoScope } /${ defaultPackageName } ` ;
379367 }
380- const selected = await promptPackageNameAndTargetDir (
381- defaultPackageName ,
382- options . interactive ,
383- ) ;
368+ const selected = await promptPackageNameAndTargetDir ( defaultPackageName , options . interactive ) ;
384369 packageName = selected . packageName ;
385370 targetDir = selectedParentDir
386371 ? path . join ( selectedParentDir , selected . targetDir )
@@ -390,8 +375,7 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
390375
391376 // Prompt for package manager or use default
392377 const packageManager =
393- workspaceInfoOptional . packageManager ??
394- ( await selectPackageManager ( options . interactive ) ) ;
378+ workspaceInfoOptional . packageManager ?? ( await selectPackageManager ( options . interactive ) ) ;
395379 // ensure the package manager is installed by vite-plus
396380 const downloadResult = await downloadPackageManager (
397381 packageManager ,
@@ -439,20 +423,14 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
439423 // #region Handle monorepo template
440424 if ( templateInfo . command === BuiltinTemplate . monorepo ) {
441425 prompts . log . info ( `Target directory: ${ cyan ( targetDir ) } ` ) ;
442- await checkProjectDirExists (
443- path . join ( workspaceInfo . rootDir , targetDir ) ,
444- options . interactive ,
445- ) ;
426+ await checkProjectDirExists ( path . join ( workspaceInfo . rootDir , targetDir ) , options . interactive ) ;
446427 const result = await executeMonorepoTemplate (
447428 workspaceInfo ,
448429 { ...templateInfo , packageName, targetDir } ,
449430 options . interactive ,
450431 ) ;
451432 if ( result . exitCode !== 0 ) {
452- cancelAndExit (
453- `Failed to create monorepo, exit code: ${ result . exitCode } ` ,
454- result . exitCode ,
455- ) ;
433+ cancelAndExit ( `Failed to create monorepo, exit code: ${ result . exitCode } ` , result . exitCode ) ;
456434 }
457435
458436 // rewrite monorepo to add vite-plus dependencies
@@ -477,16 +455,11 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
477455 if ( templateInfo . type === TemplateType . builtin ) {
478456 // prompt for package name if not provided
479457 if ( ! targetDir ) {
480- let defaultPackageName = `vite-plus-${
481- templateInfo . command . split ( ':' ) [ 1 ]
482- } `;
458+ let defaultPackageName = `vite-plus-${ templateInfo . command . split ( ':' ) [ 1 ] } ` ;
483459 if ( workspaceInfo . monorepoScope ) {
484460 defaultPackageName = `${ workspaceInfo . monorepoScope } /${ defaultPackageName } ` ;
485461 }
486- const selected = await promptPackageNameAndTargetDir (
487- defaultPackageName ,
488- options . interactive ,
489- ) ;
462+ const selected = await promptPackageNameAndTargetDir ( defaultPackageName , options . interactive ) ;
490463 packageName = selected . packageName ;
491464 targetDir = templateInfo . parentDir
492465 ? path . join ( templateInfo . parentDir , selected . targetDir )
@@ -617,48 +590,23 @@ function showAvailableTemplates() {
617590 console . log ( '' ) ;
618591
619592 console . log ( blue ( 'Vite+ Built-in Templates:' ) ) ;
620- console . log (
621- ' • vite:monorepo ' + gray ( '- Create a new monorepo' ) ,
622- ) ;
623- console . log (
624- ' • vite:application ' + gray ( '- Create a new application' ) ,
625- ) ;
626- console . log (
627- ' • vite:library ' + gray ( '- Create a new library' ) ,
628- ) ;
629- console . log (
630- ' • vite:generator ' +
631- gray ( '- Scaffold a new code generator' ) ,
632- ) ;
593+ console . log ( ' • vite:monorepo ' + gray ( '- Create a new monorepo' ) ) ;
594+ console . log ( ' • vite:application ' + gray ( '- Create a new application' ) ) ;
595+ console . log ( ' • vite:library ' + gray ( '- Create a new library' ) ) ;
596+ console . log ( ' • vite:generator ' + gray ( '- Scaffold a new code generator' ) ) ;
633597 console . log ( '' ) ;
634598
635599 console . log ( green ( 'Popular Remote Templates:' ) ) ;
636- console . log (
637- ' • create-vite ' + gray ( '- Official Vite templates' ) ,
638- ) ;
639- console . log (
640- ' • @tanstack/create-start ' + gray ( '- TanStack applications' ) ,
641- ) ;
642- console . log (
643- ' • create-next-app ' + gray ( '- Next.js application' ) ,
644- ) ;
645- console . log (
646- ' • create-nuxt ' + gray ( '- Nuxt application' ) ,
647- ) ;
648- console . log (
649- ' • create-typescript-app ' + gray ( '- TypeScript application' ) ,
650- ) ;
651- console . log (
652- ' • create-react-router ' + gray ( '- React Router application' ) ,
653- ) ;
600+ console . log ( ' • create-vite ' + gray ( '- Official Vite templates' ) ) ;
601+ console . log ( ' • @tanstack/create-start ' + gray ( '- TanStack applications' ) ) ;
602+ console . log ( ' • create-next-app ' + gray ( '- Next.js application' ) ) ;
603+ console . log ( ' • create-nuxt ' + gray ( '- Nuxt application' ) ) ;
604+ console . log ( ' • create-typescript-app ' + gray ( '- TypeScript application' ) ) ;
605+ console . log ( ' • create-react-router ' + gray ( '- React Router application' ) ) ;
654606 console . log ( ' • create-vue ' + gray ( '- Vue application' ) ) ;
655607
656- console . log (
657- '\n' + gray ( 'Run ' ) + cyan ( 'vite new' ) + gray ( ' for interactive mode' ) ,
658- ) ;
659- console . log (
660- gray ( 'Run ' ) + cyan ( 'vite new <template>' ) + gray ( ' to use any template' ) ,
661- ) ;
608+ console . log ( '\n' + gray ( 'Run ' ) + cyan ( 'vite new' ) + gray ( ' for interactive mode' ) ) ;
609+ console . log ( gray ( 'Run ' ) + cyan ( 'vite new <template>' ) + gray ( ' to use any template' ) ) ;
662610 console . log (
663611 gray ( 'Run ' ) +
664612 cyan ( 'vite new <template> -- <options>' ) +
0 commit comments