@@ -41,6 +41,18 @@ function runInstall(cwd: string): Promise<boolean> {
4141 } ) ;
4242}
4343
44+ function installGitHooks ( cwd : string ) : Promise < boolean > {
45+ return new Promise ( ( resolve ) => {
46+ const isWindows = process . platform === 'win32' ;
47+ const child = spawn ( isWindows ? 'pnpm.cmd' : 'pnpm' , [ 'exec' , 'husky' ] , {
48+ cwd,
49+ stdio : 'ignore' ,
50+ } ) ;
51+ child . on ( 'close' , ( code ) => resolve ( code === 0 ) ) ;
52+ child . on ( 'error' , ( ) => resolve ( false ) ) ;
53+ } ) ;
54+ }
55+
4456interface CreateFlags {
4557 skipGit ?: boolean ;
4658 skipInstall ?: boolean ;
@@ -128,12 +140,12 @@ function printDryRun(options: {
128140 console . log ( ` ${ chalk . dim ( '•' ) } Download template from GitHub` ) ;
129141 console . log ( ` ${ chalk . dim ( '•' ) } Transform package.json files` ) ;
130142 console . log ( ` ${ chalk . dim ( '•' ) } Create .env.local files` ) ;
131- if ( ! options . skipGit ) {
132- console . log ( ` ${ chalk . dim ( '•' ) } Initialize git repository` ) ;
133- }
134143 if ( ! options . skipInstall ) {
135144 console . log ( ` ${ chalk . dim ( '•' ) } Install dependencies (pnpm install)` ) ;
136145 }
146+ if ( ! options . skipGit ) {
147+ console . log ( ` ${ chalk . dim ( '•' ) } Initialize git repository` ) ;
148+ }
137149 console . log ( ) ;
138150}
139151
@@ -198,6 +210,7 @@ export async function create(
198210 ( shouldRunSetup ? 1 : 0 ) ;
199211 let currentStep = 0 ;
200212 let spinner : Ora | undefined ;
213+ let installSucceeded = false ;
201214
202215 try {
203216 currentStep += 1 ;
@@ -220,13 +233,39 @@ export async function create(
220233 await copyEnvFiles ( targetDir ) ;
221234 spinner . succeed ( 'Configured project' ) ;
222235
236+ if ( ! options . skipInstall ) {
237+ currentStep += 1 ;
238+ printStepHeader ( currentStep , totalSteps , 'Install dependencies' ) ;
239+ spinner . start ( 'Installing dependencies...' ) ;
240+ installSucceeded = await runInstall ( targetDir ) ;
241+ if ( installSucceeded ) {
242+ spinner . succeed ( 'Installed dependencies' ) ;
243+ } else {
244+ spinner . warn (
245+ 'Failed to install dependencies. Run "pnpm install" manually.'
246+ ) ;
247+ }
248+ }
249+
223250 if ( ! options . skipGit && isGitInstalled ( ) ) {
224251 currentStep += 1 ;
225252 printStepHeader ( currentStep , totalSteps , 'Initialize git repository' ) ;
226253 spinner . start ( 'Initializing git repository...' ) ;
227254 const gitSuccess = initGit ( targetDir ) ;
228255 if ( gitSuccess ) {
229- spinner . succeed ( 'Initialized git repository' ) ;
256+ if ( installSucceeded ) {
257+ spinner . start ( 'Installing git hooks...' ) ;
258+ const hooksSuccess = await installGitHooks ( targetDir ) ;
259+ if ( hooksSuccess ) {
260+ spinner . succeed ( 'Initialized git repository' ) ;
261+ } else {
262+ spinner . warn (
263+ 'Initialized git repository, but failed to install git hooks'
264+ ) ;
265+ }
266+ } else {
267+ spinner . succeed ( 'Initialized git repository' ) ;
268+ }
230269 } else {
231270 spinner . warn ( 'Failed to initialize git repository' ) ;
232271 }
@@ -236,20 +275,6 @@ export async function create(
236275 spinner . warn ( 'Skipped git initialization (git not installed)' ) ;
237276 }
238277
239- if ( ! options . skipInstall ) {
240- currentStep += 1 ;
241- printStepHeader ( currentStep , totalSteps , 'Install dependencies' ) ;
242- spinner . start ( 'Installing dependencies...' ) ;
243- const success = await runInstall ( targetDir ) ;
244- if ( success ) {
245- spinner . succeed ( 'Installed dependencies' ) ;
246- } else {
247- spinner . warn (
248- 'Failed to install dependencies. Run "pnpm install" manually.'
249- ) ;
250- }
251- }
252-
253278 let ranAutomaticSetup = false ;
254279
255280 if ( shouldRunSetup ) {
0 commit comments