feat(scripts): git-commit 命令添加--lang参数,支持中文提示

This commit is contained in:
chufan 2024-07-12 23:59:17 +08:00
parent a454b620f1
commit 1aa79752ef
2 changed files with 28 additions and 8 deletions

View File

@ -16,10 +16,12 @@ interface PromptObject {
*
* @param gitCommitTypes
* @param gitCommitScopes
* @param lang
*/
export async function gitCommit(
gitCommitTypes: CliOption['gitCommitTypes'],
gitCommitScopes: CliOption['gitCommitScopes']
gitCommitScopes: CliOption['gitCommitScopes'],
lang?: string
) {
const typesChoices = gitCommitTypes.map(([value, msg]) => {
const nameWithSuffix = `${value}:`;
@ -41,19 +43,22 @@ export async function gitCommit(
{
name: 'types',
type: 'select',
message: 'Please select a type',
message: lang === 'en-us' ? 'Please select a type' : '请选择提交类型',
choices: typesChoices
},
{
name: 'scopes',
type: 'select',
message: 'Please select a scope',
message: lang === 'en-us' ? 'Please select a scope' : '请选择提交范围',
choices: scopesChoices
},
{
name: 'description',
type: 'text',
message: `Please enter a description (add prefix ${yellow('!')} to indicate breaking change)`
message:
lang === 'en-us'
? `Please enter a description (add prefix ${yellow('!')} to indicate breaking change)`
: '请输入描述信息(!开头表示破坏性改动)'
}
]);

View File

@ -25,6 +25,15 @@ interface CommandArg {
* Multiple values use "," to separate them
*/
cleanupDir?: string;
/** Support for different language prompts, and the default is en-us */
lang?: string;
}
/** 支持的语言 */
enum SaCliLanguage {
Chinese = 'zh-cn',
English = 'en-us'
}
export async function setupCli() {
@ -44,6 +53,10 @@ export async function setupCli() {
'-c, --cleanupDir <dir>',
'The glob pattern of dirs to cleanup, If not set, it will use the default value, Multiple values use "," to separate them'
)
.option('-l, --lang', 'Support for different language prompts, and the default is en-us', {
default: SaCliLanguage.English,
type: [String]
})
.help();
const commands: CommandWithAction<CommandArg> = {
@ -61,8 +74,8 @@ export async function setupCli() {
},
'git-commit': {
desc: 'git commit, generate commit message which match Conventional Commits standard',
action: async () => {
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes);
action: async args => {
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes, args?.lang);
}
},
'git-commit-verify': {
@ -98,4 +111,6 @@ export async function setupCli() {
cli.parse();
}
setupCli();
(async () => {
await setupCli();
})();