package.json
{
"name": "js-w4-v2",
"version": "1.0.15",
"description": "Auto webpack4 + vue2 project template",
"main": "index.js",
"bin": {
"js-w4-v2": "./index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jack0888/js-w4-v2.git"
},
"keywords": [
"js-w4-v2"
],
"author": "yjwang088@163.com",
"dependencies": {
"commander": "^2.17.1",
"git-clone": "^0.1.0",
"shelljs": "^0.8.2",
"tracer": "^0.9.1"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/jack0888//issues"
},
"homepage": "https://github.com/jack0888/#readme"
}
index.js
#!/usr/bin/env node
const clone = require('git-clone')
const program = require('commander')
const shell = require('shelljs');
const log = require('tracer').colorConsole()
program
.version('1.0.15')
.description('Auto webpack4 + vue2 project template')
program
.command('* init')
.action(function() {
log.info('目前js-w4-v2只有一种模板,示例:js-w4-v2 init')
let pwd = shell.pwd()
let url = `https://github.com/jack0888/js-w4-v2.git`;
log.info(`正在${url}拉取模板代码 ...`)
clone(url, pwd + ``, null, function() {
shell.rm('-rf', pwd + `/.git`)
log.info('模板工程建立完成')
})
})
program.parse(process.argv)
ps: 传参写法
program
.version('1.0.15')
.description('Auto webpack4 + vue2 project template')
program
.command('* init <project> <tpl>')
.action(function(tpl, project) {
log.info('目前js-w4-v2支持amd和webpack两种模板,示例:js-w4-v2 init myproject --amd | --webpack')
if (tpl && project) {
let pwd = shell.pwd()
let url;
if(tpl == '--amd'){
url = `https://github.com/jack0888/js-w4-v2.git`;
}else{
url = `https://github.com/jack0888/js-w4-v2.git`;
}
log.info(`正在${url}拉取模板代码 ...`)
clone(url, pwd + `/${project}`, null, function() {
shell.rm('-rf', pwd + `/${project}/.git`)
log.info('模板工程建立完成')
})
} else {
log.error('正确命令例子:js-w4-v2 init myproject --amd | --webpack')
}
})