@ygyg/yg-cli
Version:
A simple CLI for front-end engineering automation construction tool.
73 lines (70 loc) • 1.96 kB
JavaScript
const inquirer = require('inquirer'); // 常用的交互式命令行用户界面的集合。表现是控制台输出提问
const utils = require('./utils');
// const inquirer = require('inquirer'); // 常用的交互式命令行用户界面的集合。表现是控制台输出提问
// const path = require('path');
// 获得了参数,可以在这里做响应的业务处理
async function blnExistChannelServer(x) {
if (!!x && x.indexOf(':') !== -1) {
return true;
}
return false;
}
async function blnExistServer(x) {
console.log('x=', x);
if (!!x) {
return true;
}
return false;
}
async function blnNeedChannel() {
const needChannel = await utils.needChannel();
utils.logStep(`channel is need: ${needChannel}`);
return needChannel;
}
async function getPrompt() {
return (await blnNeedChannel())
? [
{
type: 'input',
message: '请输入<渠道:环境>,默认为空',
name: 'channelserver',
},
{
type: 'list',
message: '请选择渠道名称',
name: 'channel',
choices: async function() {
return await utils.getChannels();
},
default: 'www',
when: async (res) =>
!Boolean(await blnExistChannelServer(res.channelserver)),
},
{
type: 'list',
message: '测试环境',
name: 'server',
choices: async function() {
return await utils.getEnvs();
},
default: 'alpha',
when: async (res) =>
!Boolean(await blnExistChannelServer(res.channelserver)),
},
]
: [
{
type: 'list',
message: '请选择测试<环境>,默认为alpha',
name: 'server',
choices: async function() {
return await utils.getEnvs();
},
default: 'alpha',
},
];
}
module.exports = async function() {
var prom = await getPrompt();
return await inquirer.prompt(prom);
};