-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如何使用 Node.js 构建一个命令行界面(CLI) #5868
如何使用 Node.js 构建一个命令行界面(CLI) #5868
Conversation
校对认领 @leviding |
@suhanyujie 好的呢 🍺 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
校对完成 @EmilyQiRabbit @leviding
翻译的很棒!
|
||
Now that we covered why you might want to create a CLI using Node.js, let's start building one. We'll use `npm` in this tutorial but there are equivalent commands for most things in `yarn`. Make sure you have [Node.js](https://nodejs.org/en/download/) and [`npm`](https://www.npmjs.com/) installed on your system. | ||
目前我们已经解释过用 Node.js 创建 CLI 的优势,现在就让我们开始构建一个 CLI 吧。在本篇教程里,我们会使用 `npm`,但如果你想用 `yarn`,绝大多数的命令也都是相同的。确保你的系统中已经安装了 [Node.js](https://nodejs.org/en/download/) 和 [`npm`](https://www.npmjs.com/)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前我们已经解释过用 Node.js 创建 CLI 的优势,现在就让我们开始构建一个 CLI 吧。在本篇教程里,我们会使用 `npm`,但如果你想用 `yarn`,绝大多数的命令也都是相同的。确保你的系统中已经安装了 [Node.js](https://nodejs.org/en/download/) 和 [`npm`](https://www.npmjs.com/)。 | |
目前我们已经解释过用 Node.js 创建 CLI 的原因,现在就让我们开始构建一个 CLI 吧。在本篇教程里,我们会使用 `npm`,但如果你想用 `yarn`,绝大多数的命令也都是相同的。确保你的系统中已经安装了 [Node.js](https://nodejs.org/en/download/) 和 [`npm`](https://www.npmjs.com/)。 |
@@ -134,57 +134,57 @@ We'll also have to inform the package manager that we are exposing a CLI script. | |||
} | |||
``` | |||
|
|||
If you look at the `bin` key, we are passing in an object with two key/value pairs. Those define the CLI commands that your package manager will install. In our case we'll register the same script for two commands. Once using our own `npm` scope by using our username and once as the generic `create-project` command for convenience. | |||
如果你注意到 `bin` 属性,你会发现我们将其定义为一个具有两个键值对的对象。这个对象内定义的是包管理器将会安装的 CLI 命令。在上述的例子中,我们为同一段脚本注册了两个命令。一个通过加上了我们的用户名来使用自己的 `npm` 作用域,另一个通用的 `create-project` 命令则更便于使用。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果你注意到 `bin` 属性,你会发现我们将其定义为一个具有两个键值对的对象。这个对象内定义的是包管理器将会安装的 CLI 命令。在上述的例子中,我们为同一段脚本注册了两个命令。一个通过加上了我们的用户名来使用自己的 `npm` 作用域,另一个通用的 `create-project` 命令则更便于使用。 | |
如果你注意到 `bin` 属性,你会发现我们将其定义为一个具有两个键值对的对象。这个对象内定义的是包管理器将会安装的 CLI 命令。在上述的例子中,我们为同一段脚本注册了两个命令。一个通过加上了我们的用户名来使用自己的 `npm` 作用域,另一个则为了便于使用通用的 `create-project` 命令。 |
- 这里的意思,突出前面提到的“两个命令”的作用,会更好一点。
@@ -373,27 +373,29 @@ export async function cli(args) { | |||
} | |||
``` | |||
|
|||
To test our progress, create a new directory somewhere like `~/test-dir` on your system and run inside it the command using one of your templates. For example: | |||
如果想要检测程序,在你的系统中某个位置例如 `~/test-dir` 中创建一个新目录,然后在这个文件夹内使用某个模版运行命令。比如: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果想要检测程序,在你的系统中某个位置例如 `~/test-dir` 中创建一个新目录,然后在这个文件夹内使用某个模版运行命令。比如: | |
为了测试我们的进度,在你的系统中某个位置例如 `~/test-dir` 中创建一个新目录,然后在这个文件夹内使用某个模版运行命令。比如: |
> * 校对者: | ||
|
||
# How to build a CLI with Node.js | ||
# 如何使用 Node.js 构建一个命令行界面(CLI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 如何使用 Node.js 构建一个命令行界面(CLI) | |
# 如何使用 Node.js 构建一个命令行应用 |
- 这里的 CLI 应该特指 命令行应用
|
||
## Why create CLIs with Node.js | ||
## 为什么要用 Node.js 创建命令行界面 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## 为什么要用 Node.js 创建命令行界面 | |
## 为什么要用 Node.js 创建命令行应用 |
@suhanyujie 感谢校对~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
很棒啊!
@EmilyQiRabbit 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。 文章发布时,标题前面那个大图,你可以在上传掘金的时候作为题图使用,然后在文中删除那个图就行啦。 掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件。 |
译文翻译完成,resolve #5817