UNPKG

mk-paas-cli

Version:

MK PAAS CLI TOOL

37 lines (32 loc) 950 B
const { prompt } = require('inquirer') const { writeFile } = require('fs') const { tplListTable } = require(`${__dirname}/../utils/tplListTable`) const chalk = require('chalk') const tplList = require(`${__dirname}/../templates`) const question = [ { type: 'input', name: 'name', message: '输入你要删除的模板:', validate (val) { if (tplList[val]) { return true } else if (val === '') { return '模板名字是必填的!' } else if (!tplList[val]) { return '该模板不存在.' } }, }, ] module.exports = prompt(question).then(({ name }) => { delete tplList[name] writeFile(`${__dirname}/../templates.json`, JSON.stringify(tplList), 'utf-8', (err) => { if (err) { console.log(chalk.red(`😵 模板删除失败 错误信息:${err}`)) process.exit() } tplListTable(tplList, chalk.green(`🎉 ${name}模板删除成功!`)) }) })