@@ -27,13 +27,15 @@ import {
2727 writeAgentInstructions ,
2828} from '../utils/agent.ts' ;
2929import { detectExistingEditors , selectEditors , writeEditorConfigs } from '../utils/editor.ts' ;
30+ import { initGitRepository } from '../utils/git.ts' ;
3031import { renderCliDoc } from '../utils/help.ts' ;
3132import { displayRelative } from '../utils/path.ts' ;
3233import {
3334 type CommandRunSummary ,
3435 defaultInteractive ,
3536 downloadPackageManager ,
3637 promptGitHooks ,
38+ promptGitInit ,
3739 runViteFmt ,
3840 runViteInstall ,
3941 selectPackageManager ,
@@ -95,6 +97,8 @@ const helpMessage = renderCliDoc({
9597 label : '--editor NAME' ,
9698 description : 'Write editor config files for the specified editor.' ,
9799 } ,
100+ { label : '--git' , description : 'Initialize a git repository with an initial commit' } ,
101+ { label : '--no-git' , description : 'Skip git repository initialization' } ,
98102 {
99103 label : '--hooks' ,
100104 description : 'Set up pre-commit hooks (default in non-interactive mode)' ,
@@ -220,11 +224,12 @@ function parseArgs() {
220224 verbose ?: boolean ;
221225 agent ?: string | string [ ] | false ;
222226 editor ?: string ;
227+ git ?: boolean ;
223228 hooks ?: boolean ;
224229 'package-manager' ?: string ;
225230 } > ( viteArgs , {
226231 alias : { h : 'help' } ,
227- boolean : [ 'help' , 'list' , 'all' , 'interactive' , 'hooks' , 'verbose' ] ,
232+ boolean : [ 'help' , 'list' , 'all' , 'interactive' , 'hooks' , 'verbose' , 'git' ] ,
228233 string : [ 'directory' , 'agent' , 'editor' , 'package-manager' ] ,
229234 default : { interactive : defaultInteractive ( ) } ,
230235 } ) ;
@@ -241,6 +246,7 @@ function parseArgs() {
241246 verbose : parsed . verbose || false ,
242247 agent : parsed . agent ,
243248 editor : parsed . editor ,
249+ git : parsed . git ,
244250 hooks : parsed . hooks ,
245251 packageManager : parsed [ 'package-manager' ] ,
246252 } as Options ,
@@ -696,6 +702,7 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
696702 onCancel : ( ) => cancelAndExit ( ) ,
697703 } ) ) ;
698704
705+ const shouldSetupGit = await promptGitInit ( options ) ;
699706 if ( ! isMonorepo ) {
700707 shouldSetupHooks = await promptGitHooks ( options ) ;
701708 }
@@ -811,6 +818,10 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
811818 workspaceInfo . rootDir = fullPath ;
812819 updateCreateProgress ( 'Integrating monorepo' ) ;
813820 rewriteMonorepo ( workspaceInfo , undefined , compactOutput ) ;
821+ if ( shouldSetupGit ) {
822+ updateCreateProgress ( 'Initializing git repository' ) ;
823+ await initGitRepository ( fullPath ) ;
824+ }
814825 if ( shouldSetupHooks ) {
815826 installGitHooks ( fullPath , compactOutput ) ;
816827 }
@@ -1021,6 +1032,9 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
10211032 await runViteFmt ( workspaceInfo . rootDir , options . interactive , [ projectDir ] , {
10221033 silent : compactOutput ,
10231034 } ) ;
1035+ if ( shouldSetupGit ) {
1036+ await initGitRepository ( workspaceInfo . rootDir ) ;
1037+ }
10241038 } else {
10251039 if ( shouldMigrateLintFmtTools ) {
10261040 await installAndMigrate ( fullPath ) ;
@@ -1032,6 +1046,10 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
10321046 addFrameworkShim ( fullPath , framework ) ;
10331047 }
10341048 }
1049+ if ( shouldSetupGit ) {
1050+ updateCreateProgress ( 'Initializing git repository' ) ;
1051+ await initGitRepository ( fullPath ) ;
1052+ }
10351053 if ( shouldSetupHooks ) {
10361054 installGitHooks ( fullPath , compactOutput ) ;
10371055 }
0 commit comments