参考地址1

参考地址2

一、npm package.json bin

1、package.json

{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"bin": {
"gen": "bin/gen.js"
},
"dependencies": {
"commander": "^2.15.1"
}
}

2、bin/gen.js

#!/usr/bin/env node
var argv = process.argv;
var filePath = __dirname;
var currentPath = process.cwd(); console.log(argv)
console.log(filePath)
console.log(currentPath)

二、Commnader + inquirer + minimist + download-git-repo + ejs(Nunjucks、handlebars ) +  execa (child_process)

Commander 示例

#!/usr/bin/env node
var program = require('commander'); program
.version('0.0.1')
.option('-C, --chdir <path>', 'change the working directory')
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
.option('-T, --no-tests', 'ignore test hook')
.option('-p, --peppers', 'Add peppers')
.option('-P, --pineapple', 'Add pineapple')
.option('-b, --bbq-sauce', 'Add bbq sauce')
.option('--p, --fuck-you', 'fuckyou')
.option('build --env <fuckyou>', 'fuckyou2')
.parse(process.argv); if (program.peppers) console.log(' - peppers');
if (program.pineapple) console.log(' - pineapple');
if (program.bbqSauce) console.log(' - bbq');
if (program.fuckYou) console.log('fuckyou');
if (program.env && program.args.length != 0) {
console.log(program.args);
} program
.command('init')
.description('run remote setup commands')
.action(function() {
console.log('setup');
}); program
.command('exec <cmd>')
.description('run the given remote command')
.action(function(cmd) {
console.log('exec "%s"', cmd);
}); program
.command('teardown <dir> [otherDirs...]')
.description('run teardown commands')
.action(function(dir, otherDirs) {
console.log('dir "%s"', dir);
if (otherDirs) {
otherDirs.forEach(function (oDir) {
console.log('dir "%s"', oDir);
});
}
});

最新文章

  1. jQuery遍历checkbox
  2. oracle merge into用法
  3. Java虚拟机 safepoints 初探
  4. C#Color对象的使用介绍及颜色对照表
  5. 看Ue4角色代码——跳跃与实现二段跳
  6. mac 下安装 lua5.3 + cjson
  7. 实验12:Problem I: 成绩排序
  8. 解决win8下chrome浏览器打开提示没有注册类的方法
  9. [简单]poi word2007表格按模版样式填充行数据
  10. 动态创建地图文档MXD并发布地图服务
  11. C# 判断两张图片是否一致的快速方法
  12. ios学习-delegate、传值、跳转页面
  13. 异常:ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed...
  14. mynotebook
  15. Unity3D ——强大的跨平台3D游戏开发工具(二)
  16. Java各种工具下载
  17. java中的链表编写
  18. 使用FastJson进行对象和JSON转换属性命名规则为下划线和驼峰的问题
  19. L1-Day13
  20. MongoDB、PyMongo数据操作

热门文章

  1. Altium Protel PCB Layer
  2. Visual Studio 2013在线文档地址备案
  3. Visual Studio的工程结构解析
  4. 【转载】利用Matlab制作钟表
  5. zookeeper疑难杂症
  6. centos7 yum安装配置redis 并设置密码
  7. VC++ 6.0下OpengGL配置以及glut配置
  8. 如何设置ESXi中的虚拟机随主机一同启动?
  9. Java中字符串相等与大小比較
  10. 转adb Shell root 权限