@bingosoft/cli
Version:
bingo framework cli
68 lines (63 loc) • 1.95 kB
JavaScript
const program = require("commander");
const inquirer = require("inquirer");
const argv = require('minimist')(process.argv.slice(2));
const {
main
} = require("../lib/bingo-cli-gen-sdk.js");
program
.name("bingo-cli gen-sdk") //设置help的名称
.usage("<options>") //设置help的必须参数
.option('-s, --swagger', 'swagger文件地址,支持本地文件或远程文件地址')
.option('-t, --template', '自定义模板目录,可选')
.option('-d, --destination', 'sdk生成目录,默认为当前路径./')
.parse(process.argv);
entry();
async function entry() { //入口函数
//判断有没有直接输入参数
if (!program.args.length) {
let sdkMessage = await getSdkMessage();
main(sdkMessage);
} else {
let swagger = argv.swagger || argv.s;
let template = argv.template || argv.t;
let destination = argv.destination || argv.d;
if (!swagger) {
program.help();
return;
}
if (!destination) {
destination = "./";
}
main({
swagger,
template,
destination
});
}
}
function getSdkMessage() {
return inquirer.prompt([{
name: "swagger",
message: "swagger地址",
default: "https://dfuse.bingosoft.net/wf-runtime/v2/api-docs"
},
{
name: "localTemplate",
message: "是否使用本地模板目录",
type: "confirm"
},
{
name: "template",
message: "模板目录",
default: "./_templates",
when: function (answers) {
return answers.localTemplate
}
},
{
name: "destination",
message: "下载目录",
default: "./"
}
]);
}