Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
打开git bash、zsh等命令行工具,输入如下命令后回车:

```bash
npm i @opentiny/cli npminstall@3 -g
$ npm i @opentiny/cli -g
```

等待片刻,待安装完成之后在终端执行 `$ tiny -v`,正常返回版本信息,表示安装成功。
Expand Down
2 changes: 1 addition & 1 deletion docs/use-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $ npm -v


```bash
$ npm install @opentiny/cli npminstall -g
$ npm install @opentiny/cli -g
```


Expand Down
1 change: 1 addition & 0 deletions packages/cli/devkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 20 additions & 5 deletions packages/cli/devkit/src/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
};

/**
Expand Down Expand Up @@ -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} 需要安装的包或包列表, 需要带版本号直接在包名后面 @ 版本号即可
Expand All @@ -158,23 +173,23 @@ 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);
}

/**
* 移除npm包
*/
export async function unInstall(pkg: string | string[], options?: NpmOption) {
const installer = 'npmuninstall ';
const installer = getUnInstaller();
await runInstall(installer, pkg, options);
}

/**
* 安装package.json 中的依赖
*/
export async function installDependencies(options?: NpmOption) {
const installer = 'npminstall';
const installer = getInstaller();
await runInstall(installer, [], options);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/cli/devkit/src/upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,30 @@ async function updateTip(data: any): Promise<boolean> {
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')} ******************************`
);
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
Expand Down