We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
可以使用命令行封装一些常用的脚手架,来创建脚手架,效果好,并且B格高。
创建脚手架可以参考 create-react-app create-bfd-app 现成的命令行脚手架。
使用Node开发命令行工具需要注意以下几点
#!/usr/bin/env node --harmony
如果在 入口文件里面使用了ES6的一些语法, 则后面要加上 --harmony , 否则可以不加。
在根节点下添加一个配置 bin
{ "name": "npm-cli-demo01", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, // 记得添加这个配置, snippet 是安装后的命令名称 "bin": { "snippet": "./index.js" }, "author": "", "license": "ISC", "dependencies": { "chalk": "^1.1.3", "co": "^4.6.0", "co-prompt": "^1.0.0", "commander": "^2.9.0", "superagent": "^3.4.1" } }
$ npm install -g $ snippet Hello, world! $ which snippet /usr/local/bin/snippet $ readlink /usr/local/bin/snippet ../lib/node_modules/bitbucket-snippet/index.js
作用,实际上是将我们脚本链接到 path 变量的位置,所以我们能够在任何地方使用它。
其他几点,则参照这边技术文章, 讲解的很详细。并且做了一个基本的命令行工具DEMO。
编写命令行工具,可以写出很多功能,比如发邮件,生成代码,生成脚手架, 一些命令行的增强等,什么功能,就看自己怎么想。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Node封装命令行工具
可以使用命令行封装一些常用的脚手架,来创建脚手架,效果好,并且B格高。
创建脚手架可以参考 create-react-app create-bfd-app 现成的命令行脚手架。
一、总结
使用Node开发命令行工具需要注意以下几点
1. 入口文件 end point ,需要在最顶部加上
2. 在package.json
在根节点下添加一个配置 bin
3. 安装命令测试
$ npm install -g $ snippet Hello, world! $ which snippet /usr/local/bin/snippet $ readlink /usr/local/bin/snippet ../lib/node_modules/bitbucket-snippet/index.js
二、其他
其他几点,则参照这边技术文章, 讲解的很详细。并且做了一个基本的命令行工具DEMO。
编写命令行工具,可以写出很多功能,比如发邮件,生成代码,生成脚手架, 一些命令行的增强等,什么功能,就看自己怎么想。
The text was updated successfully, but these errors were encountered: