@@ -16,6 +16,7 @@ import {
16
16
parseExampleOption ,
17
17
downloadAndExtract ,
18
18
} from './helpers/example-option.js' ;
19
+ import { spawn } from 'node:child_process' ;
19
20
20
21
const userAgent = process . env . npm_config_user_agent || '' ;
21
22
const packageManager = / p n p m / . test ( userAgent )
@@ -202,15 +203,32 @@ async function init() {
202
203
await installTemplate ( root , packageName , templateRoot , templateName ) ;
203
204
}
204
205
205
- // TODO automatically installing dependencies
206
206
// 1. check packageManager
207
207
// 2. and then install dependencies
208
-
209
- console . log ( `\nDone. Now run:\n` ) ;
210
- console . log ( `${ bold ( green ( `cd ${ targetDir } ` ) ) } ` ) ;
211
- console . log ( `${ bold ( green ( commands . install ) ) } ` ) ;
212
- console . log ( `${ bold ( green ( commands . dev ) ) } ` ) ;
213
208
console . log ( ) ;
209
+ console . log ( `Installing dependencies by running ${ commands . install } ...` ) ;
210
+
211
+ const installProcess = spawn ( packageManager , [ 'install' ] , {
212
+ stdio : 'inherit' ,
213
+ shell : process . platform === 'win32' ,
214
+ cwd : targetDir ,
215
+ } ) ;
216
+
217
+ installProcess . on ( 'close' , ( code ) => {
218
+ // process exit code
219
+ if ( code !== 0 ) {
220
+ console . error ( `Could not execute ${ commands . install } . Please run` ) ;
221
+ console . log ( `${ bold ( green ( `cd ${ targetDir } ` ) ) } ` ) ;
222
+ console . log ( `${ bold ( green ( commands . install ) ) } ` ) ;
223
+ console . log ( `${ bold ( green ( commands . dev ) ) } ` ) ;
224
+ console . log ( ) ;
225
+ } else {
226
+ console . log ( `\nDone. Now run:\n` ) ;
227
+ console . log ( `${ bold ( green ( `cd ${ targetDir } ` ) ) } ` ) ;
228
+ console . log ( `${ bold ( green ( commands . dev ) ) } ` ) ;
229
+ console . log ( ) ;
230
+ }
231
+ } ) ;
214
232
}
215
233
216
234
init ( )
0 commit comments