Skip to content

Commit

Permalink
feat: 重构
Browse files Browse the repository at this point in the history
  • Loading branch information
无星 committed Nov 13, 2021
1 parent 16b7138 commit 50920ce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/actions/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ const add = (name, url) => {
const customPath = path.join(__dirname,"../config/templates/custom.json")
// 转成json写入
fs.writeFileSync(customPath, JSON.stringify(result, null, '\t'))
successLog("成功写入,输入wxplatform-cli ls查看最新template")
successLog("成功写入,输入xingwu ls查看最新template")
}
module.exports = add
25 changes: 25 additions & 0 deletions src/actions/del.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const cusRegs = require('../config/templates/custom.json');
const templates = require('../config/templates/templates.json');
const { successLog, errorLog } = require('../utils/log')
const path = require('path');
const fs = require('fs-extra')
const _ = require('lodash')

function del (name) {
if (templates.hasOwnProperty(name)) {
errorLog(name + "为预设定模板,不可删除");
return;
} else if (!cusRegs.hasOwnProperty(name)) {
successLog(name + "模板不存在,请检查输入是否正确");
return;
}
// 添加
let result = _.omit(cusRegs, name)
// 转成json写入
const customPath = path.join(__dirname,"../config/templates/custom.json")
// 转成json写入
fs.writeFileSync(customPath, JSON.stringify(result, null, '\t'))
successLog("成功删除,输入xingwu ls查看最新template")
}

module.exports = del
61 changes: 10 additions & 51 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {figletLog} = require('./utils/log')
const init = require('./actions/init')
const list = require('./actions/list')
const add = require('./actions/add')
const del = require('./actions/del')
const addGitHooks = require('./actions/gitHooks')
// 读取packgaejson
const packageConfig = require('../package.json')
Expand Down Expand Up @@ -34,6 +35,14 @@ program
add(name,url)
});

// 移除模板
program
.command('remove-template <name>')
.description('移除本地模板')
.action((name)=>{
del(name)
});

// 添加git hook
program
.command('add-githooks')
Expand All @@ -53,59 +62,9 @@ program
list()
})



// 需求响应
program.on('--help', () => {
console.log('新需求?可反馈给[email protected]')
})
// 必须放到最后一行用于解析
program.parse(process.argv)
/*
const create = require('../lib/init')
const onList = require('../lib/onList')
const onAdd = require('../lib/onAdd')
const onDel = require('../lib/onDel')
// 用来进行命令行交互的
const { program } = require('commander')
// 读取packgaejson
const packageConfig = require('../package.json')
// 这样输出-V或--version就能看到版本号了
program.version(packageConfig.version)
// init
program
.command('init <name>')
.alias('i')
.description('新建项目的命令')
.action((name, cmd) => {
console.log('开始新建项目,项目名' + name)
create(name)
})
// 查看模板
program
.command('ls')
.description('查看当前所有模板')
.action(onList)
// 添加模板
program
.command('add <name> <url>')
.description('本地添加模板, 域名:所有者/项目名称#分支 例如 https://github.com:xingxiaowu/template-vue#master')
.action(onAdd);
// 移除模板
program
.command('del <name>')
.description('移除本地模板')
.action(onDel);
program.on('--help', () => {
console.log('新需求?可反馈给329106954@qq.com')
})
// 必须放到最后一行用于解析
program.parse(process.argv)
*/
program.parse(process.argv)

0 comments on commit 50920ce

Please sign in to comment.