mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2026-05-28 11:13:15 +08:00
feat(packages): check git staging area before showing commit prompts
This commit is contained in:
@@ -17,7 +17,14 @@ interface PromptObject {
|
|||||||
* @param lang
|
* @param lang
|
||||||
*/
|
*/
|
||||||
export async function gitCommit(lang: Lang = 'en-us') {
|
export async function gitCommit(lang: Lang = 'en-us') {
|
||||||
const { gitCommitMessages, gitCommitTypes, gitCommitScopes } = locales[lang];
|
const { gitCommitMessages, gitCommitNoStaged, gitCommitTypes, gitCommitScopes } = locales[lang];
|
||||||
|
|
||||||
|
const stagedFiles = await execCommand('git', ['diff', '--cached', '--name-only']);
|
||||||
|
|
||||||
|
if (!stagedFiles) {
|
||||||
|
console.error(gitCommitNoStaged);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const typesChoices = gitCommitTypes.map(([value, msg]) => {
|
const typesChoices = gitCommitTypes.map(([value, msg]) => {
|
||||||
const nameWithSuffix = `${value}:`;
|
const nameWithSuffix = `${value}:`;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export const locales = {
|
|||||||
['release', '发布项目新版本'],
|
['release', '发布项目新版本'],
|
||||||
['other', '其他的变更']
|
['other', '其他的变更']
|
||||||
] as [string, string][],
|
] as [string, string][],
|
||||||
|
gitCommitNoStaged: `${bgRed(' 错误 ')} ${red('暂存区没有文件,请先使用 git add 添加文件后再提交!')}`,
|
||||||
gitCommitVerify: `${bgRed(' 错误 ')} ${red('git 提交信息必须符合 Conventional Commits 标准!')}\n\n${green(
|
gitCommitVerify: `${bgRed(' 错误 ')} ${red('git 提交信息必须符合 Conventional Commits 标准!')}\n\n${green(
|
||||||
'推荐使用命令 `pnpm commit` 生成符合 Conventional Commits 标准的提交信息。\n获取有关 Conventional Commits 的更多信息,请访问此链接: https://conventionalcommits.org'
|
'推荐使用命令 `pnpm commit` 生成符合 Conventional Commits 标准的提交信息。\n获取有关 Conventional Commits 的更多信息,请访问此链接: https://conventionalcommits.org'
|
||||||
)}`
|
)}`
|
||||||
@@ -75,6 +76,7 @@ export const locales = {
|
|||||||
['release', 'release project'],
|
['release', 'release project'],
|
||||||
['other', 'other changes']
|
['other', 'other changes']
|
||||||
] as [string, string][],
|
] as [string, string][],
|
||||||
|
gitCommitNoStaged: `${bgRed(' ERROR ')} ${red('No files in staging area, please use git add to stage files first!')}`,
|
||||||
gitCommitVerify: `${bgRed(' ERROR ')} ${red('git commit message must match the Conventional Commits standard!')}\n\n${green(
|
gitCommitVerify: `${bgRed(' ERROR ')} ${red('git commit message must match the Conventional Commits standard!')}\n\n${green(
|
||||||
'Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org'
|
'Recommended to use the command `pnpm commit` to generate Conventional Commits compliant commit information.\nGet more info about Conventional Commits, follow this link: https://conventionalcommits.org'
|
||||||
)}`
|
)}`
|
||||||
|
|||||||
Reference in New Issue
Block a user