Skip to content

Commit 04577cd

Browse files
committed
feat(packages): Synchronize the useRouterPush of soybean
1 parent 308dfdd commit 04577cd

File tree

3 files changed

+98
-17
lines changed

3 files changed

+98
-17
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"build:test": "vite build --mode test",
3939
"cleanup": "sa cleanup",
4040
"commit": "sa git-commit",
41+
"commit:zh": "sa git-commit -l=zh-cn",
4142
"czh": "sa git-commit -l=zh-cn",
4243
"dev": "vite --mode test",
4344
"dev:prod": "vite --mode prod",

packages/scripts/src/commands/git-commit.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import path from 'node:path';
22
import { readFileSync } from 'node:fs';
33
import { prompt } from 'enquirer';
4-
import { bgRed, green, red, yellow } from 'kolorist';
54
import { execCommand } from '../shared';
6-
import type { CliOption } from '../types';
5+
import { locales } from '../locales';
6+
import type { Lang } from '../locales';
77

88
interface PromptObject {
99
types: string;
@@ -14,13 +14,11 @@ interface PromptObject {
1414
/**
1515
* Git commit with Conventional Commits standard
1616
*
17-
* @param gitCommitTypes
18-
* @param gitCommitScopes
17+
* @param lang
1918
*/
20-
export async function gitCommit(
21-
gitCommitTypes: CliOption['gitCommitTypes'],
22-
gitCommitScopes: CliOption['gitCommitScopes']
23-
) {
19+
export async function gitCommit(lang: Lang = 'en-us') {
20+
const { gitCommitMessages, gitCommitTypes, gitCommitScopes } = locales[lang];
21+
2422
const typesChoices = gitCommitTypes.map(([value, msg]) => {
2523
const nameWithSuffix = `${value}:`;
2624

@@ -41,19 +39,19 @@ export async function gitCommit(
4139
{
4240
name: 'types',
4341
type: 'select',
44-
message: 'Please select a type',
42+
message: gitCommitMessages.types,
4543
choices: typesChoices
4644
},
4745
{
4846
name: 'scopes',
4947
type: 'select',
50-
message: 'Please select a scope',
48+
message: gitCommitMessages.scopes,
5149
choices: scopesChoices
5250
},
5351
{
5452
name: 'description',
5553
type: 'text',
56-
message: `Please enter a description (add prefix ${yellow('!')} to indicate breaking change)`
54+
message: gitCommitMessages.description
5755
}
5856
]);
5957

@@ -67,20 +65,20 @@ export async function gitCommit(
6765
}
6866

6967
/** Git commit message verify */
70-
export async function gitCommitVerify() {
68+
export async function gitCommitVerify(lang: Lang = 'en-us', ignores: RegExp[] = []) {
7169
const gitPath = await execCommand('git', ['rev-parse', '--show-toplevel']);
7270

7371
const gitMsgPath = path.join(gitPath, '.git', 'COMMIT_EDITMSG');
7472

7573
const commitMsg = readFileSync(gitMsgPath, 'utf8').trim();
7674

75+
if (ignores.some(regExp => regExp.test(commitMsg))) return;
76+
7777
const REG_EXP = /(?<type>[a-z]+)(?:\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i;
7878

7979
if (!REG_EXP.test(commitMsg)) {
80-
throw new Error(
81-
`${bgRed(' ERROR ')} ${red('git commit message must match the Conventional Commits standard!')}\n\n${green(
82-
'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'
83-
)}`
84-
);
80+
const errorMsg = locales[lang].gitCommitVerify;
81+
82+
throw new Error(errorMsg);
8583
}
8684
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { bgRed, green, red, yellow } from 'kolorist';
2+
3+
export type Lang = 'zh-cn' | 'en-us';
4+
5+
export const locales = {
6+
'zh-cn': {
7+
gitCommitMessages: {
8+
types: '请选择提交类型',
9+
scopes: '请选择提交范围',
10+
description: `请输入描述信息(${yellow('!')}开头表示破坏性改动`
11+
},
12+
gitCommitTypes: [
13+
['feat', '新功能'],
14+
['feat-wip', '开发中的功能,比如某功能的部分代码'],
15+
['fix', '修复Bug'],
16+
['docs', '只涉及文档更新'],
17+
['typo', '代码或文档勘误,比如错误拼写'],
18+
['style', '修改代码风格,不影响代码含义的变更'],
19+
['refactor', '代码重构,既不修复 bug 也不添加功能的代码变更'],
20+
['perf', '可提高性能的代码更改'],
21+
['optimize', '优化代码质量的代码更改'],
22+
['test', '添加缺失的测试或更正现有测试'],
23+
['build', '影响构建系统或外部依赖项的更改'],
24+
['ci', '对 CI 配置文件和脚本的更改'],
25+
['chore', '没有修改src或测试文件的其他变更'],
26+
['revert', '还原先前的提交']
27+
] as [string, string][],
28+
gitCommitScopes: [
29+
['projects', '项目'],
30+
['packages', '包'],
31+
['components', '组件'],
32+
['hooks', '钩子函数'],
33+
['utils', '工具函数'],
34+
['types', 'TS类型声明'],
35+
['styles', '代码风格'],
36+
['deps', '项目依赖'],
37+
['release', '发布项目新版本'],
38+
['other', '其他的变更']
39+
] as [string, string][],
40+
gitCommitVerify: `${bgRed(' 错误 ')} ${red('git 提交信息必须符合 Conventional Commits 标准!')}\n\n${green(
41+
'推荐使用命令 `pnpm commit` 生成符合 Conventional Commits 标准的提交信息。\n获取有关 Conventional Commits 的更多信息,请访问此链接: https://conventionalcommits.org'
42+
)}`
43+
},
44+
'en-us': {
45+
gitCommitMessages: {
46+
types: 'Please select a type',
47+
scopes: 'Please select a scope',
48+
description: `Please enter a description (add prefix ${yellow('!')} to indicate breaking change)`
49+
},
50+
gitCommitTypes: [
51+
['feat', 'A new feature'],
52+
['feat-wip', 'Features in development, such as partial code for a certain feature'],
53+
['fix', 'A bug fix'],
54+
['docs', 'Documentation only changes'],
55+
['typo', 'Code or document corrections, such as spelling errors'],
56+
['style', 'Changes that do not affect the meaning of the code'],
57+
['refactor', 'A code change that neither fixes a bug nor adds a feature'],
58+
['perf', 'A code change that improves performance'],
59+
['optimize', 'A code change that optimizes code quality'],
60+
['test', 'Adding missing tests or correcting existing tests'],
61+
['build', 'Changes that affect the build system or external dependencies'],
62+
['ci', 'Changes to our CI configuration files and scripts'],
63+
['chore', "Other changes that don't modify src or test files"],
64+
['revert', 'Reverts a previous commit']
65+
] as [string, string][],
66+
gitCommitScopes: [
67+
['projects', 'project'],
68+
['packages', 'packages'],
69+
['components', 'components'],
70+
['hooks', 'hook functions'],
71+
['utils', 'utils functions'],
72+
['types', 'TS declaration'],
73+
['styles', 'style'],
74+
['deps', 'project dependencies'],
75+
['release', 'release project'],
76+
['other', 'other changes']
77+
] as [string, string][],
78+
gitCommitVerify: `${bgRed(' ERROR ')} ${red('git commit message must match the Conventional Commits standard!')}\n\n${green(
79+
'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'
80+
)}`
81+
}
82+
} satisfies Record<Lang, Record<string, unknown>>;

0 commit comments

Comments
 (0)