diff --git a/README.md b/README.md index 8996cc31..8f4ee5a4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ English | [简体中文](README.zh-CN.md) Open git bash, zsh, and other command-line tools, type the following command, and press Enter: ```bash -npm i @opentiny/cli npminstall@3 -g +$ npm i @opentiny/cli -g ``` Wait for a while. After the installation is complete, run `$tiny -v` on the terminal. If the version information is displayed, the installation is successful. diff --git a/README.zh-CN.md b/README.zh-CN.md index 3c2a980e..8af9e78c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -12,7 +12,7 @@ 打开git bash、zsh等命令行工具,输入如下命令后回车: ```bash -npm i @opentiny/cli npminstall@3 -g +$ npm i @opentiny/cli -g ``` 等待片刻,待安装完成之后在终端执行 `$ tiny -v`,正常返回版本信息,表示安装成功。 diff --git a/docs/use-install.md b/docs/use-install.md index 7bf37b6f..619df873 100644 --- a/docs/use-install.md +++ b/docs/use-install.md @@ -22,7 +22,7 @@ $ npm -v ```bash -$ npm install @opentiny/cli npminstall -g +$ npm install @opentiny/cli -g ``` diff --git a/packages/cli/devkit/package.json b/packages/cli/devkit/package.json index 18856f16..5ac7ac5b 100644 --- a/packages/cli/devkit/package.json +++ b/packages/cli/devkit/package.json @@ -31,6 +31,7 @@ "mem-fs-editor": "^6.0.0", "node-emoji": "^1.10.0", "npm-run": "^5.0.1", + "npminstall": "^7.9.0", "npmlog": "^4.1.2", "os": "^0.1.1", "os-locale": "^4.0.0", diff --git a/packages/cli/devkit/src/npm/index.ts b/packages/cli/devkit/src/npm/index.ts index 8eec806c..7d62132e 100644 --- a/packages/cli/devkit/src/npm/index.ts +++ b/packages/cli/devkit/src/npm/index.ts @@ -24,9 +24,10 @@ const log = logs('core-npm'); // TIMEOUT 超时时间 const TIMEOUT = 5000; +// 未配置cnpmrc时默认使用淘宝镜像源 const defaultRegistries = { - registry: 'https://registry.npmjs.org/', - '@opentiny:registry': 'https://registry.npmjs.org' + registry: 'https://registry.npmmirror.com/', + '@opentiny:registry': 'https://registry.npmmirror.com/' }; /** @@ -149,6 +150,20 @@ export function setCnpmrc(config: any) { fs.writeFileSync(userConfig, data.join(os.EOL)); } +/** + * 获取安装器 + */ +export function getInstaller() { + return require.resolve('npminstall/bin/install.js') +} + +/** + * 获取卸载器 + */ +export function getUnInstaller() { + return require.resolve('npminstall/bin/uninstall.js') +} + /** * 安装 npm 包 * @param pkg {string|array} 需要安装的包或包列表, 需要带版本号直接在包名后面 @ 版本号即可 @@ -158,7 +173,7 @@ export function setCnpmrc(config: any) { * @param options */ export async function install(pkg: string | string[], options?: NpmOption) { - const installer = 'npminstall'; + const installer = getInstaller(); await runInstall(installer, pkg, options); } @@ -166,7 +181,7 @@ export async function install(pkg: string | string[], options?: NpmOption) { * 移除npm包 */ export async function unInstall(pkg: string | string[], options?: NpmOption) { - const installer = 'npmuninstall '; + const installer = getUnInstaller(); await runInstall(installer, pkg, options); } @@ -174,7 +189,7 @@ export async function unInstall(pkg: string | string[], options?: NpmOption) { * 安装package.json 中的依赖 */ export async function installDependencies(options?: NpmOption) { - const installer = 'npminstall'; + const installer = getInstaller(); await runInstall(installer, [], options); } diff --git a/packages/cli/devkit/src/upgrade/index.ts b/packages/cli/devkit/src/upgrade/index.ts index e57af679..7dff2b14 100644 --- a/packages/cli/devkit/src/upgrade/index.ts +++ b/packages/cli/devkit/src/upgrade/index.ts @@ -77,21 +77,21 @@ async function updateTip(data: any): Promise { log.warn( intl.get('updatingCommand', { icon: emoji.get('point_right'), - command: chalk.bgRed.bold(` ${installer} i ${data.name} npminstall -g `) + command: chalk.bgRed.bold(` ${installer} i ${data.name} -g `) }) ); } else { log.warn( intl.get('updateCommand', { icon: emoji.get('point_right'), - command: chalk.bgRed.bold(` ${installer} i ${data.name} npminstall -g`) + command: chalk.bgRed.bold(` ${installer} i ${data.name} -g`) }) ); } // linux & mac 下才提示 if (process!.platform.indexOf('win') !== 0) { - log.warn(`${intl.get('ifUpdateError')} ${chalk.red.bold(`sudo ${installer} install -g ${data.name} npminstall`)}`); + log.warn(`${intl.get('ifUpdateError')} ${chalk.red.bold(`sudo ${installer} install -g ${data.name}`)}`); } log.warn( `******************************${emoji.get('point_up_2')} ${emoji.get('point_up_2')} ******************************` @@ -99,8 +99,8 @@ async function updateTip(data: any): Promise { console.log('\n'); if (needFocusUpdate) { - // 执行 npm install -g @opentiny/cli 和 npminstall 更新本地系统 - const depen = [`${data.name}`, 'npminstall']; + // 执行 npm install -g @opentiny/cli 更新本地版本 + const depen = [`${data.name}`]; await npm.install(depen, { // global安装 g: true