UNPKG

mk-paas-cli

Version:

MK PAAS CLI TOOL

65 lines (59 loc) 1.53 kB
const { prompt } = require('inquirer') const { writeFile } = require('fs') const { tplListTable } = require(`${__dirname}/../utils/tplListTable`) const chalk = require('chalk') const tplList = require(`${__dirname}/../templates.json`) const question = [ { type: 'input', name: 'name', message: '新增模板名称:', validate (val) { if (tplList[val]) { return '模板已经存在了!' } else if (val === '') { return '模板名字必填!' } else { return true } }, }, { type: 'input', name: 'place', message: '模板的Owner/name:', validate (val) { if (val !== '') { return true } return '模板的Owner/name是必填的!' }, }, { type: 'input', name: 'branch', message: '模板分支:', default: 'master', }, { type: 'list', name: 'type', message: '模板存放仓库类型 github or gitlab:', choices: ['gitlab', 'github'], default: 'gitlab', }, ] module.exports = prompt(question).then(({ name, place, branch, type }) => { tplList[name] = {} tplList[name]['owner/name'] = place tplList[name]['branch'] = branch tplList[name]['type'] = type writeFile(`${__dirname}/../templates.json`, JSON.stringify(tplList), 'utf-8', (err) => { if (err) { console.log(chalk.red(`😵 模板添加失败 错误信息:${err}`)) process.exit() } tplListTable(tplList, chalk.green(`🎉 ${name}模板添加成功!`)) }) })