@littlelane/hf-cli
Version:
Project initialization scaffolding tool based on github, gitlab, gitee code repository templates
52 lines (41 loc) • 1.08 kB
JavaScript
const co = require('co');
const prompt = require('co-prompt');
const fs = require('fs');
const table = require('../table');
const tip = require('../tip');
const tpls = require('../../templates.json');
const writeFile = (err) => {
if (err) {
console.log(err);
tip.fail('删除模板异常,请重新运行!');
process.exit();
}
tip.success('模板删除成功!');
if (JSON.stringify(tpls) !== '{}') {
table(tpls);
} else {
tip.info('还未添加该模板!');
}
process.exit();
};
const resolve = (tplName) => {
// 删除对应的模板
if (tpls[tplName]) {
delete tpls[tplName];
} else {
tip.fail('模板不经存在!');
process.exit();
}
// 写入template.json
fs.writeFile(__dirname + '../../templates.json', JSON.stringify(tpls), 'utf-8', writeFile);
};
module.exports = () => {
co(function* () {
// 分步接收用户输入的参数
const tplName = yield prompt('模板名字: ');
return new Promise((resolve, reject) => {
resolve(tplName);
});
}).then(resolve);
};