From 1aa79752efc77c3f8402d74702894936fef19b29 Mon Sep 17 00:00:00 2001 From: chufan Date: Fri, 12 Jul 2024 23:59:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(scripts):=20git-commit=20=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=B7=BB=E5=8A=A0--lang=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/scripts/src/commands/git-commit.ts | 13 ++++++++---- packages/scripts/src/index.ts | 23 +++++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/scripts/src/commands/git-commit.ts b/packages/scripts/src/commands/git-commit.ts index 875ea969..66dc47c1 100644 --- a/packages/scripts/src/commands/git-commit.ts +++ b/packages/scripts/src/commands/git-commit.ts @@ -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)` + : '请输入描述信息(!开头表示破坏性改动)' } ]); diff --git a/packages/scripts/src/index.ts b/packages/scripts/src/index.ts index 909dda3d..028eee70 100755 --- a/packages/scripts/src/index.ts +++ b/packages/scripts/src/index.ts @@ -18,13 +18,22 @@ interface CommandArg { /** Generate changelog by total tags */ total?: boolean; /** - * The glob pattern of dirs to cleanup + * The glob pattern of dirs to clean up * * If not set, it will use the default value * * 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 ', '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 = { @@ -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(); +})();