Skip to content

Commit 98e6b44

Browse files
committed
更新中英文 README 文件,优化 Node.js 版本描述和特性说明
1 parent 1cbe60d commit 98e6b44

File tree

2 files changed

+84
-158
lines changed

2 files changed

+84
-158
lines changed

README.md

Lines changed: 43 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
English | [中文简体](README_zh-CN.md)
1+
[English](README.md) | 中文简体
22

33
[![Build Status](https://github.com/axetroy/nodapt/workflows/ci/badge.svg)](https://github.com/axetroy/nodapt/actions)
44
[![Go Report Card](https://goreportcard.com/badge/github.com/axetroy/nodapt)](https://goreportcard.com/report/github.com/axetroy/nodapt)
@@ -8,41 +8,47 @@ English | [中文简体](README_zh-CN.md)
88

99
### Introduction
1010

11-
Nodapt (/noʊˈdæpt/) is a command-line tool that adapts to multiple NodeJS versions. It will run commands with the appropriate NodeJS version based on the NodeJS version constraints in `packages.json`.
11+
Nodapt (/noʊˈdæpt/) is a command-line tool designed to work with multiple Node.js versions. It automatically selects and uses the appropriate Node.js version to run commands based on the version constraints specified in the `package.json` file.
1212

1313
### Background
1414

15-
When developing NodeJS projects, we often need to switch NodeJS versions. For example, project A requires `16.x.y`, while project B uses `20.x.y`.
15+
When developing Node.js projects, it is common to switch between different Node.js versions. For example, Project A might require `16.x.y`, while Project B uses `20.x.y`.
1616

17-
However, global version management tools like nvm cannot meet the requirements. It has the following problems:
17+
However, traditional global version management tools (e.g., nvm) often fall short in meeting these needs due to the following issues:
1818

19-
1. nvm is not cross-platform, and it is not very convenient to use on Windows.
20-
2. nvm needs to install the specified version in advance to switch, which is not very friendly to the CI/CD environment.
21-
3. In a Monorepo, there may be a situation where package A requires `16.x.y`, while package B requires `20.x.y`. In this case, nvm cannot solve this problem well.
19+
1. **Limited cross-platform support**: nvm is not very convenient to use on Windows.
20+
2. **Pre-installation requirements**: nvm requires pre-installing specific versions, which is not ideal for CI/CD environments.
21+
3. **Lack of Monorepo support**: In Monorepo setups, different subprojects may require different Node.js versions, which nvm cannot handle effectively.
2222

23-
So I developed this tool to solve this problem.
24-
25-
It will run the command with the appropriate NodeJS version according to the NodeJS version constraint in `packages.json`.
23+
To address these challenges, Nodapt was developed. It automatically selects and installs the appropriate Node.js version to run commands based on the version constraints in `package.json`.
2624

2725
### Features
2826

2927
- [x] Cross-platform support (Mac/Linux/Windows)
30-
- [x] Automatically select and install the NodeJS version to run the command
31-
- [x] Specify the NodeJS version to run the command
28+
- [x] Automatically select and install the appropriate Node.js version to run commands
29+
- [x] Support for running commands with a specified Node.js version
30+
- [x] Support for Node.js version constraints in `package.json`
31+
- [x] Monorepo project support
32+
- [x] CI/CD environment support
33+
- [x] Compatibility with other Node.js version managers (e.g., nvm, n, fnm)
34+
- [x] Support for opening a new shell session with the `nodapt use <version>` command
3235

3336
### Usage
3437

3538
```bash
36-
# Automatically select the NodeJS version to run the command
39+
# Automatically select the appropriate Node.js version to run a command
3740
$ nodapt node -v
3841

39-
# Specify the NodeJS version and run the specified command
42+
# Run a command with a specified Node.js version
4043
$ nodapt use ^18 node -v
44+
45+
# Specify a version range and open a new shell session
46+
$ nodapt use 20
4147
```
4248

43-
### Integrate into your NodeJS project
49+
### Integrating with Your Node.js Project
4450

45-
1. Add NodeJS version constraint in `package.json`.
51+
1. Add Node.js version constraints to your `package.json` file:
4652

4753
```diff
4854
+ "engines": {
@@ -53,99 +59,56 @@ $ nodapt use ^18 node -v
5359
}
5460
```
5561

56-
2. Run the script with `nodapt` command.
62+
2. Use the `nodapt` command to run scripts:
5763

5864
```diff
5965
- yarn dev
6066
+ nodapt yarn dev
6167
```
6268

63-
Run with `--help` to see more options.
64-
65-
```
66-
$ nodapt --help
67-
nodapt - A virtual node environment for node.js, node version manager for projects.
68-
69-
USAGE:
70-
nodapt [OPTIONS] <ARGS...>
71-
nodapt [OPTIONS] run <ARGS...>
72-
nodapt [OPTIONS] use <CONSTRAINT> [ARGS...]
73-
nodapt [OPTIONS] rm <CONSTRAINT>
74-
nodapt [OPTIONS] clean
75-
nodapt [OPTIONS] ls
76-
nodapt [OPTIONS] ls-remote
77-
78-
COMMANDS:
79-
<ARGS...> Alias for 'run <ARGS...>' but shorter
80-
run <ARGS...> Automatically select node version to run commands
81-
use <CONSTRAINT> <ARGS...> Use the specified version of node to run the command
82-
rm|remove <CONSTRAINT> Remove the specified version of node that installed by nodapt
83-
clean Remove all the node version that installed by nodapt
84-
ls|list List all the installed node version
85-
ls-remote|list-remote List all the available node version
86-
87-
OPTIONS:
88-
--help|-h Print help information
89-
--version|-v Print version information
90-
91-
ENVIRONMENT VARIABLES:
92-
NODE_MIRROR The mirror of the nodejs download, defaults to: https://nodejs.org/dist/
93-
Chinese users defaults to: https://registry.npmmirror.com/-/binary/node/
94-
NODE_ENV_DIR The directory where the nodejs is stored, defaults to: $HOME/.nodapt
95-
DEBUG Print debug information when set DEBUG=1
96-
97-
EXAMPLES:
98-
nodapt node -v
99-
nodapt run node -v
100-
nodapt use v14.17.0 node -v
101-
102-
SOURCE CODE:
103-
https://github.com/axetroy/nodapt
104-
```
69+
Run `nodapt --help` to see more options.
10570

10671
### Installation
10772

108-
1. Install via [Cask](https://github.com/cask-pkg/cask.rs) (Mac/Linux/Windows)
73+
#### Install via [Cask](https://github.com/cask-pkg/cask.rs) (Mac/Linux/Windows)
10974

11075
```bash
11176
$ cask install github.com/axetroy/nodapt
11277
$ nodapt --help
11378
```
11479

115-
2. Install via npm
80+
#### Install via npm
11681

117-
```sh
118-
$ npm install nodapt -g
82+
```bash
83+
$ npm install @axetroy/nodapt -g
11984
$ nodapt --help
12085
```
12186

122-
### Uninstall
87+
### Uninstallation
12388

12489
```bash
12590
$ nodapt clean
126-
# then remove the binary file or uninstall via package manager
91+
# Then remove the executable file or uninstall it via your package manager
12792
```
12893

129-
### NodeJS version selection algorithm
94+
### Node.js Version Selection Algorithm
13095

131-
This section explains what happens when you run `nodapt` and how it selects the node version.
96+
This section explains how `nodapt` behaves and selects the appropriate Node.js version when executed:
13297

133-
1. Check for the presence of `package.json`.
134-
2. If `package.json` exists:
135-
1. If the `engines.node` field is specified, use the indicated version.
136-
1. If the currently installed version matches `engines.node`, the command is run using the currently installed version.
137-
2. Otherwise, select the latest matching version from the remote list, install it, and run the command.
138-
2. Otherwise, run the command directly.
139-
3. Otherwise, run the command directly.
98+
1. Check if a `package.json` file exists in the current directory.
99+
2. If it exists:
100+
1. Check if the `engines.node` field specifies a version constraint:
101+
- If the currently installed version satisfies the constraint, use it directly.
102+
- If not, select the latest matching version from the remote list, install it, and then run the command.
103+
2. If `engines.node` is not specified, run the command directly.
104+
3. If `package.json` does not exist, run the command directly.
140105

141106
### Similar Projects
142107

143-
[https://github.com/jdx/mise](https://github.com/jdx/mise)
144-
145-
[https://github.com/gvcgo/version-manager](https://github.com/gvcgo/version-manager)
146-
147-
[https://github.com/version-fox/vfox](https://github.com/version-fox/vfox)
108+
- [https://github.com/jdx/mise](https://github.com/jdx/mise)
109+
- [https://github.com/gvcgo/version-manager](https://github.com/gvcgo/version-manager)
110+
- [https://github.com/version-fox/vfox](https://github.com/version-fox/vfox)
148111

149112
### License
150113

151-
The [Anti-996 License](LICENSE)
114+
This project is licensed under the [Anti-996 License](LICENSE).

README_zh-CN.md

Lines changed: 41 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,47 @@
88

99
### 介绍
1010

11-
Nodapt (/noʊˈdæpt/) 是一个适配多个 NodeJS 版本的命令行工具它会根据 `packages.json` 中的 NodeJS 版本约束,使用合适的 NodeJS 版本运行命令。
11+
Nodapt (/noʊˈdæpt/) 是一个适配多个 Node.js 版本的命令行工具它会根据 `package.json` 中的 Node.js 版本约束,自动选择并使用合适的 Node.js 版本运行命令。
1212

1313
### 背景
1414

15-
在开发 NodeJS 项目时,我们经常需要切换 NodeJS 版本例如,项目 A 需要`16.x.y`,而项目 B 使用`20.x.y`
15+
在开发 Node.js 项目时,我们经常需要切换 Node.js 版本例如,项目 A 需要 `16.x.y`,而项目 B 使用 `20.x.y`
1616

17-
但是全局的版本管理工具类似 nvm 并不能满足,它有一下几个问题
17+
然而,传统的全局版本管理工具(如 nvm)并不能很好地满足这些需求,主要存在以下问题
1818

19-
1. nvm 并不是跨平台的,windows 上使用起来并不是很方便
20-
2. nvm 需要提前安装好指定的版本才能切换,这对于 CI/CD 环境并不是很友好
21-
3. 在 Monorepo 中可能会存在 package A 需要`16.x.y`,而 package B 需要`20.x.y`,这时候 nvm 并不能很好的解决这个问题
19+
1. **跨平台支持不足**nvm 在 Windows 上使用不够方便
20+
2. **版本预安装要求**nvm 需要提前安装指定版本,CI/CD 环境中使用不够友好
21+
3. **Monorepo 支持不足**在 Monorepo 中,不同子项目可能需要不同的 Node.js 版本,nvm 无法很好地解决这一问题
2222

23-
所以我开发了这个工具,用于解决这个问题。
24-
25-
它会根据 `packages.json` 中的 NodeJS 版本约束,使用合适的 NodeJS 版本运行命令。
23+
为了解决这些问题,开发了 Nodapt。它能够根据 `package.json` 中的 Node.js 版本约束,自动选择并安装合适的版本运行命令。
2624

2725
### 特性
2826

29-
- [x] 跨平台支持 (Mac/Linux/Windows)
30-
- [x] 自动选择并安装 NodeJS 版本运行命令
31-
- [x] 指定 NodeJS 版本运行命令
27+
- [x] 跨平台支持(Mac/Linux/Windows)
28+
- [x] 自动选择并安装 Node.js 版本运行命令
29+
- [x] 支持指定 Node.js 版本运行命令
30+
- [x] 支持 `package.json` 中的 Node.js 版本约束
31+
- [x] 支持 Monorepo 项目
32+
- [x] 支持 CI/CD 环境
33+
- [x] 兼容其他 Node.js 版本管理工具(如 nvm、n、fnm 等)
34+
- [x] 支持 `nodapt use <version>` 命令开启新的 shell 会话
3235

3336
### 用法
3437

3538
```bash
36-
# 自动选择 NodeJS 版本运行命令
39+
# 自动选择 Node.js 版本运行命令
3740
$ nodapt node -v
3841

39-
# 指定 NodeJS 版本并运行指定命令
42+
# 指定 Node.js 版本并运行命令
4043
$ nodapt use ^18 node -v
44+
45+
# 指定版本范围并开启新的 shell 会话
46+
$ nodapt use 20
4147
```
4248

43-
### 集成到你的 NodeJS 项目中
49+
### 集成到你的 Node.js 项目中
4450

45-
1.`package.json` 中添加 NodeJS 版本约束
51+
1.`package.json` 中添加 Node.js 版本约束
4652

4753
```diff
4854
+ "engines": {
@@ -53,68 +59,27 @@ $ nodapt use ^18 node -v
5359
}
5460
```
5561

56-
2. 使用 `nodapt` 命令运行脚本
62+
2. 使用 `nodapt` 命令运行脚本
5763

5864
```diff
5965
- yarn dev
6066
+ nodapt yarn dev
6167
```
6268

63-
运行 `--help` 查看更多选项。
64-
65-
```
66-
$ nodapt --help
67-
nodapt - A virtual node environment for node.js, node version manager for projects.
68-
69-
USAGE:
70-
nodapt [OPTIONS] <ARGS...>
71-
nodapt [OPTIONS] run <ARGS...>
72-
nodapt [OPTIONS] use <CONSTRAINT> [ARGS...]
73-
nodapt [OPTIONS] rm <CONSTRAINT>
74-
nodapt [OPTIONS] clean
75-
nodapt [OPTIONS] ls
76-
nodapt [OPTIONS] ls-remote
77-
78-
COMMANDS:
79-
<ARGS...> Alias for 'run <ARGS...>' but shorter
80-
run <ARGS...> Automatically select node version to run commands
81-
use <CONSTRAINT> <ARGS...> Use the specified version of node to run the command
82-
rm|remove <CONSTRAINT> Remove the specified version of node that installed by nodapt
83-
clean Remove all the node version that installed by nodapt
84-
ls|list List all the installed node version
85-
ls-remote|list-remote List all the available node version
86-
87-
OPTIONS:
88-
--help|-h Print help information
89-
--version|-v Print version information
90-
91-
ENVIRONMENT VARIABLES:
92-
NODE_MIRROR The mirror of the nodejs download, defaults to: https://nodejs.org/dist/
93-
Chinese users defaults to: https://registry.npmmirror.com/-/binary/node/
94-
NODE_ENV_DIR The directory where the nodejs is stored, defaults to: $HOME/.nodapt
95-
DEBUG Print debug information when set DEBUG=1
96-
97-
EXAMPLES:
98-
nodapt node -v
99-
nodapt run node -v
100-
nodapt use v14.17.0 node -v
101-
102-
SOURCE CODE:
103-
https://github.com/axetroy/nodapt
104-
```
69+
运行 `nodapt --help` 查看更多选项。
10570

10671
### 安装
10772

108-
1. 通过 [Cask](https://github.com/cask-pkg/cask.rs) 安装 (Mac/Linux/Windows)
73+
#### 通过 [Cask](https://github.com/cask-pkg/cask.rs) 安装Mac/Linux/Windows
10974

11075
```bash
11176
$ cask install github.com/axetroy/nodapt
11277
$ nodapt --help
11378
```
11479

115-
2. 通过 npm 安装
80+
#### 通过 npm 安装
11681

117-
```sh
82+
```bash
11883
$ npm install @axetroy/nodapt -g
11984
$ nodapt --help
12085
```
@@ -123,29 +88,27 @@ $ nodapt --help
12388

12489
```bash
12590
$ nodapt clean
126-
# 然后移除可执行文件或者通过包管理器卸载
91+
# 然后移除可执行文件,或者通过包管理器卸载
12792
```
12893

129-
### NodeJS 版本选择算法
94+
### Node.js 版本选择算法
13095

131-
本节解释运行 `nodapt` 时发生的情况以及它如何选择节点版本。
96+
本节解释运行 `nodapt` 时的行为以及它如何选择 Node.js 版本:
13297

133-
1. 检查 `package.json` 是否存在
134-
2. 如果 `package.json` 存在
135-
1. 如果指定了 `engines.node` 字段
136-
1. 如果当前安装的版本与 `engines.node` 匹配,则使用当前安装版本运行命令
137-
2. 否则,从远程列表中选择匹配的最新版本,然后安装并运行命令
138-
2. 否则, 直接运行命令。
139-
3. 否则, 直接运行命令。
98+
1. 检查当前目录下是否存在 `package.json` 文件
99+
2. 如果存在
100+
1. 检查 `engines.node` 字段是否指定了版本约束
101+
- 如果当前安装的版本符合约束,则直接使用
102+
- 如果不符合,从远程列表中选择匹配的最新版本,安装后运行命令
103+
2. 如果未指定 `engines.node`直接运行命令。
104+
3. 如果 `package.json` 不存在,直接运行命令。
140105

141106
### 类似项目
142107

143-
[https://github.com/jdx/mise](https://github.com/jdx/mise)
144-
145-
[https://github.com/gvcgo/version-manager](https://github.com/gvcgo/version-manager)
146-
147-
[https://github.com/version-fox/vfox](https://github.com/version-fox/vfox)
108+
- [https://github.com/jdx/mise](https://github.com/jdx/mise)
109+
- [https://github.com/gvcgo/version-manager](https://github.com/gvcgo/version-manager)
110+
- [https://github.com/version-fox/vfox](https://github.com/version-fox/vfox)
148111

149112
### 开源许可
150113

151-
The [Anti-996 License](LICENSE)
114+
本项目采用 [Anti-996 License](LICENSE) 开源许可。

0 commit comments

Comments
 (0)