File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { spawnSync } from 'child_process' ;
12import fs from 'fs' ;
23import download from 'download-git-repo' ;
34import ora from 'ora' ;
@@ -146,17 +147,17 @@ export class CoreGitDownloader {
146147 } catch ( error ) {
147148 console . log ( 'write file error==' , error ) ;
148149 }
149-
150+ const usePackageManager = this . getUsePackageManager ( ) ;
150151 console . log ( ) ;
151152 console . log ( chalk . green ( '👏 初始化项目完成!👏' ) ) ;
152153 console . log ( ) ;
153154 console . log ( chalk . blue ( '命令提示:' ) ) ;
154155 console . log ( chalk . blue ( ` # 进入项目` ) ) ;
155156 console . log ( chalk . blue ( ` $ cd ./${ options . name } ` ) ) ;
156157 console . log ( chalk . blue ( ` # 安装依赖` ) ) ;
157- console . log ( chalk . blue ( ` $ npm install` ) ) ;
158+ console . log ( chalk . blue ( ` $ ${ usePackageManager } install` ) ) ;
158159 console . log ( chalk . blue ( ` # 运行` ) ) ;
159- console . log ( chalk . blue ( ` $ npm run dev` ) ) ;
160+ console . log ( chalk . blue ( ` $ ${ usePackageManager } run dev` ) ) ;
160161 console . log ( ) ;
161162 }
162163
@@ -186,4 +187,19 @@ export class CoreGitDownloader {
186187 } ) ;
187188 } ) ;
188189 }
190+
191+ /**
192+ * 获取常用包管理器, 优先顺序 pnpm > yarn > npm
193+ */
194+ private getUsePackageManager ( ) {
195+ if ( spawnSync ( 'pnpm' , [ '--version' ] ) . status === 0 ) {
196+ return 'pnpm' ;
197+ }
198+
199+ if ( spawnSync ( 'yarn' , [ '--version' ] ) . status === 0 ) {
200+ return 'yarn' ;
201+ }
202+
203+ return 'npm' ;
204+ }
189205}
You can’t perform that action at this time.
0 commit comments