ax-template-cli
Version:
该脚手架支持vue,react拉取
63 lines (59 loc) • 2.34 kB
JavaScript
const program = require('commander');
const download = require('download-git-repo');
//version 版本号
//name 新项目名称
program
.version('1.1.10', '-v, --version')
.command('init <buildName> <templateName> <projectName>')
.action((buildName, templateName, projectName) => {
switch (buildName) {
case 'webpack':
if (templateName === 'react') {
console.log('clone template ...');
download(
'github:ajaxpost/ax-cli',
projectName,
function (err) {
console.log(err ? 'Error' : 'Success');
}
);
} else if (templateName === 'vue') {
console.log('暂时不支持 webpack + vue,你可以试试 vite + vue');
} else {
console.error('A template name that does not exist');
}
break;
case 'vite':
if (templateName === 'vue') {
console.log('clone template ...');
download(
'github:ajaxpost/vite-vue-template',
projectName,
function (err) {
console.log(err ? 'Error' : 'Success');
}
);
} else if (templateName === 'react') {
console.log('clone template ...');
download(
'github:ajaxpost/vite-react-template',
projectName,
function (err) {
console.log(err ? 'Error' : 'Success');
}
);
} else {
console.error('A template name that does not exist');
}
break;
default:
console.error('A template name that does not exist');
break;
}
});
program.parse(process.argv);
// #! /usr/bin/env node是执行这个文件时使用node方式执行
// program.version是解析别人输入jkc-cli -v时输出的内容: 1.0.0
// command解析输入jkc-cli init vue my-vue-project,init后面两个参数,一个模板名,一个项目名
// action是根据上面的两个参数做相应的逻辑处理,判断模板名,去相应的git仓库下载代码。download的第一个参数下载地址不是填我们git的网址,按照我的格式填就行,第二个参数是生成的项目名,第三个参数是错误的回调执行函数。