File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -254,14 +254,23 @@ async function init() {
254254
255255 write ( 'package.json' , JSON . stringify ( pkg , null , 2 ) )
256256
257- const pkgManager = / y a r n / . test ( process . env . npm_execpath ) ? 'yarn' : 'npm'
257+ const pkgInfo = pkgFromUserAgent ( process . env . npm_config_user_agent )
258+ const pkgManager = pkgInfo ? pkgInfo . name : 'npm'
258259
259260 console . log ( `\nDone. Now run:\n` )
260261 if ( root !== cwd ) {
261262 console . log ( ` cd ${ path . relative ( cwd , root ) } ` )
262263 }
263- console . log ( ` ${ pkgManager === 'yarn' ? `yarn` : `npm install` } ` )
264- console . log ( ` ${ pkgManager === 'yarn' ? `yarn dev` : `npm run dev` } ` )
264+ switch ( pkgManager ) {
265+ case 'yarn' :
266+ console . log ( ' yarn' )
267+ console . log ( ' yarn dev' )
268+ break
269+ default :
270+ console . log ( ` ${ pkgManager } install` )
271+ console . log ( ` ${ pkgManager } run dev` )
272+ break
273+ }
265274 console . log ( )
266275}
267276
@@ -318,6 +327,20 @@ function emptyDir(dir) {
318327 }
319328}
320329
330+ /**
331+ * @param {string | undefined } userAgent process.env.npm_config_user_agent
332+ * @returns object | undefined
333+ */
334+ function pkgFromUserAgent ( userAgent ) {
335+ if ( ! userAgent ) return undefined
336+ const pkgSpec = userAgent . split ( ' ' ) [ 0 ]
337+ const pkgSpecArr = pkgSpec . split ( '/' )
338+ return {
339+ name : pkgSpecArr [ 0 ] ,
340+ version : pkgSpecArr [ 1 ]
341+ }
342+ }
343+
321344init ( ) . catch ( ( e ) => {
322345 console . error ( e )
323346} )
You can’t perform that action at this time.
0 commit comments