Skip to content

Commit 5c07345

Browse files
authored
feat: add getUsePackageManager (#89)
feat: add getUsePackageManager
2 parents c95a03d + bd56e29 commit 5c07345

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/core/CoreGitDownloader.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spawnSync } from 'child_process';
12
import fs from 'fs';
23
import download from 'download-git-repo';
34
import 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
}

0 commit comments

Comments
 (0)