0.0.1 • Published 4 years ago

okyri v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

1. package.json 中的 bin 字段

https://docs.npmjs.com/files/package.json#bin

一个 npm 模块,若在 package.json 中指定了 bin 字段,说明该模块提供了可在命令行中执行的命令,具体可以执行的命令在 bin 中指定。

{
  "bin": {
    "pluto": "bin/init.js"
  }
}

程序安装后会可在命令行执行 pluto 命令,实际执行的就是指定的这个 init.js 文件。如果是全局安装,会将这个目标 js 文件映射到 prefix/bin 目录下,而如果是在项目中安装,则映射到 ./node_modules/.bin/ 目录下。

2. commander

commander 是一个提供了用户命令行输入和参数解析功能的 nodejs 模块。

API

  • .option(): 用于自定义带选项,同时会将定义的选项服务于选项的文档部分,要设置“关键字”和“描述”,关键字包括“简写”和“全写”两部分,以,,|或者空格做分隔。
  • .command()/.addCommand(): 定义指令
  • .arguments(): 设置顶层指令以及.command调用的子指令的参数
  • .action(): 注册一个回调函数
  • .parse(): 解析命令行参数 argv
  • .description(): 设置 description 值
  • .usage(): 设置 usage 值

解析来自 process.argv 的 args 和 options,然后将剩下的参数(未定义的参数)赋值给 commander 对象的 args 属性(program.args),program.args 是一个数组。

3. download-git-repo

Download and extract a git repository (GitHub, GitLab, Bitbucket) from node