-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
无星
committed
Nov 13, 2021
1 parent
16b7138
commit 50920ce
Showing
3 changed files
with
36 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
|
@@ -34,6 +35,14 @@ program | |
add(name,url) | ||
}); | ||
|
||
// 移除模板 | ||
program | ||
.command('remove-template <name>') | ||
.description('移除本地模板') | ||
.action((name)=>{ | ||
del(name) | ||
}); | ||
|
||
// 添加git hook | ||
program | ||
.command('add-githooks') | ||
|
@@ -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) |