-
Notifications
You must be signed in to change notification settings - Fork 204
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
Showing
6 changed files
with
214 additions
and
214 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 |
---|---|---|
@@ -1,76 +1,76 @@ | ||
const { existsSync } = require("fs"); | ||
const { existsSync } = require('fs') | ||
|
||
const { showDir, showExt, moduleTypes } = require("./shared/base.cjs"); | ||
const { showDir, showExt, moduleTypes } = require('./shared/base.cjs') | ||
|
||
/** | ||
* 自动创建 | ||
* @param {import('plop').NodePlopAPI} plop | ||
*/ | ||
function create(plop) { | ||
let exist = null; | ||
let modulePath = null; | ||
let exist = null | ||
let modulePath = null | ||
|
||
plop.setGenerator("controller", { | ||
description: "自动创建", | ||
prompts: [ | ||
{ | ||
name: "type", | ||
type: "list", | ||
default: "component", | ||
message: "您希望生成哪种类型的模块?", | ||
choices: moduleTypes, | ||
}, | ||
{ | ||
name: "isMarkdown", | ||
type: "confirm", | ||
message: "是否 markdown 类型?", | ||
default: false, | ||
// 如果是 page 类型需要询问是否为 markdown 类型 | ||
when({ type }) { | ||
return type === "page"; | ||
}, | ||
}, | ||
{ | ||
name: "name", | ||
type: "input", | ||
message({ type }) { | ||
return `请输入 ${type} 的命名`; | ||
}, | ||
}, | ||
{ | ||
name: "shouldReset", | ||
type: "confirm", | ||
default: false, | ||
message({ type }) { | ||
return `目标 ${type} 已存在,是否重置?`; | ||
}, | ||
// 确认模块是否已存在,是则询问是否重置 | ||
when({ type, name, isMarkdown }) { | ||
const dir = showDir(type); | ||
const ext = showExt(type, isMarkdown); | ||
modulePath = `src/${dir}/${name}.${ext}`; | ||
exist = existsSync(modulePath); | ||
if (exist) { | ||
return true; | ||
} | ||
}, | ||
}, | ||
], | ||
actions(answer) { | ||
const { type, shouldReset } = answer; | ||
if (exist && !shouldReset) { | ||
throw new Error(`${type} 创建失败`); | ||
} | ||
return [ | ||
{ | ||
type: "add", | ||
force: true, | ||
path: `../${modulePath}`, | ||
templateFile: `./template/${type}.hbs`, | ||
}, | ||
]; | ||
}, | ||
}); | ||
plop.setGenerator('controller', { | ||
description: '自动创建', | ||
prompts: [ | ||
{ | ||
name: 'type', | ||
type: 'list', | ||
default: 'component', | ||
message: '您希望生成哪种类型的模块?', | ||
choices: moduleTypes, | ||
}, | ||
{ | ||
name: 'isMarkdown', | ||
type: 'confirm', | ||
message: '是否 markdown 类型?', | ||
default: false, | ||
// 如果是 page 类型需要询问是否为 markdown 类型 | ||
when({ type }) { | ||
return type === 'page' | ||
}, | ||
}, | ||
{ | ||
name: 'name', | ||
type: 'input', | ||
message({ type }) { | ||
return `请输入 ${type} 的命名` | ||
}, | ||
}, | ||
{ | ||
name: 'shouldReset', | ||
type: 'confirm', | ||
default: false, | ||
message({ type }) { | ||
return `目标 ${type} 已存在,是否重置?` | ||
}, | ||
// 确认模块是否已存在,是则询问是否重置 | ||
when({ type, name, isMarkdown }) { | ||
const dir = showDir(type) | ||
const ext = showExt(type, isMarkdown) | ||
modulePath = `src/${dir}/${name}.${ext}` | ||
exist = existsSync(modulePath) | ||
if (exist) { | ||
return true | ||
} | ||
}, | ||
}, | ||
], | ||
actions(answer) { | ||
const { type, shouldReset } = answer | ||
if (exist && !shouldReset) { | ||
throw new Error(`${type} 创建失败`) | ||
} | ||
return [ | ||
{ | ||
type: 'add', | ||
force: true, | ||
path: `../${modulePath}`, | ||
templateFile: `./template/${type}.hbs`, | ||
}, | ||
] | ||
}, | ||
}) | ||
} | ||
|
||
module.exports = create; | ||
module.exports = create |
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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
const { execSync } = require("child_process"); | ||
const { execSync } = require('child_process') | ||
|
||
/** | ||
* 自动更新依赖 | ||
* @param {import('plop').NodePlopAPI} plop | ||
*/ | ||
function depsFresh(plop) { | ||
plop.setGenerator("controller", { | ||
description: "自动更新依赖", | ||
prompts: [ | ||
{ | ||
name: "type", | ||
type: "list", | ||
default: "patch", | ||
message: "你希望发布一个什么版本?", | ||
choices: ["patch", "minor", "major"], | ||
}, | ||
{ | ||
name: "shouldWrite", | ||
type: "confirm", | ||
default: false, | ||
message: "是否直接更新?", | ||
}, | ||
], | ||
actions(answer) { | ||
const { type, shouldWrite } = answer; | ||
plop.setGenerator('controller', { | ||
description: '自动更新依赖', | ||
prompts: [ | ||
{ | ||
name: 'type', | ||
type: 'list', | ||
default: 'patch', | ||
message: '你希望发布一个什么版本?', | ||
choices: ['patch', 'minor', 'major'], | ||
}, | ||
{ | ||
name: 'shouldWrite', | ||
type: 'confirm', | ||
default: false, | ||
message: '是否直接更新?', | ||
}, | ||
], | ||
actions(answer) { | ||
const { type, shouldWrite } = answer | ||
|
||
execSync(`npx taze ${type} ${shouldWrite ? "-w" : ""}`, { | ||
stdio: "inherit", | ||
}); | ||
return []; | ||
}, | ||
}); | ||
execSync(`npx taze ${type} ${shouldWrite ? '-w' : ''}`, { | ||
stdio: 'inherit', | ||
}) | ||
return [] | ||
}, | ||
}) | ||
} | ||
|
||
module.exports = depsFresh; | ||
module.exports = depsFresh |
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 |
---|---|---|
@@ -1,40 +1,40 @@ | ||
const { execSync } = require("child_process"); | ||
const { execSync } = require('child_process') | ||
|
||
/** | ||
* 自动发版 | ||
* @param {import('plop').NodePlopAPI} plop | ||
*/ | ||
function release(plop) { | ||
plop.setGenerator("controller", { | ||
description: "自动发版", | ||
prompts: [ | ||
{ | ||
name: "type", | ||
type: "list", | ||
default: "patch", | ||
message: "你希望发布一个什么版本?", | ||
choices: [ | ||
"patch", | ||
"minor", | ||
"major", | ||
"prepatch", | ||
"premajor", | ||
"preminor", | ||
"prerelease", | ||
], | ||
}, | ||
], | ||
actions(answer) { | ||
const { type } = answer; | ||
execSync( | ||
`npx changelogen --${type} --release && git push --follow-tags`, | ||
{ | ||
stdio: "inherit", | ||
}, | ||
); | ||
return []; | ||
}, | ||
}); | ||
plop.setGenerator('controller', { | ||
description: '自动发版', | ||
prompts: [ | ||
{ | ||
name: 'type', | ||
type: 'list', | ||
default: 'patch', | ||
message: '你希望发布一个什么版本?', | ||
choices: [ | ||
'patch', | ||
'minor', | ||
'major', | ||
'prepatch', | ||
'premajor', | ||
'preminor', | ||
'prerelease', | ||
], | ||
}, | ||
], | ||
actions(answer) { | ||
const { type } = answer | ||
execSync( | ||
`npx changelogen --${type} --release && git push --follow-tags`, | ||
{ | ||
stdio: 'inherit', | ||
}, | ||
) | ||
return [] | ||
}, | ||
}) | ||
} | ||
|
||
module.exports = release; | ||
module.exports = release |
Oops, something went wrong.