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 gitCommitTypes
* @param gitCommitScopes * @param gitCommitScopes
* @param lang
*/ */
export async function gitCommit( export async function gitCommit(
gitCommitTypes: CliOption['gitCommitTypes'], gitCommitTypes: CliOption['gitCommitTypes'],
gitCommitScopes: CliOption['gitCommitScopes'] gitCommitScopes: CliOption['gitCommitScopes'],
lang?: string
) { ) {
const typesChoices = gitCommitTypes.map(([value, msg]) => { const typesChoices = gitCommitTypes.map(([value, msg]) => {
const nameWithSuffix = `${value}:`; const nameWithSuffix = `${value}:`;
@ -41,19 +43,22 @@ export async function gitCommit(
{ {
name: 'types', name: 'types',
type: 'select', type: 'select',
message: 'Please select a type', message: lang === 'en-us' ? 'Please select a type' : '请选择提交类型',
choices: typesChoices choices: typesChoices
}, },
{ {
name: 'scopes', name: 'scopes',
type: 'select', type: 'select',
message: 'Please select a scope', message: lang === 'en-us' ? 'Please select a scope' : '请选择提交范围',
choices: scopesChoices choices: scopesChoices
}, },
{ {
name: 'description', name: 'description',
type: 'text', 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

@ -18,13 +18,22 @@ interface CommandArg {
/** Generate changelog by total tags */ /** Generate changelog by total tags */
total?: boolean; 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 * If not set, it will use the default value
* *
* Multiple values use "," to separate them * Multiple values use "," to separate them
*/ */
cleanupDir?: string; 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() { export async function setupCli() {
@ -44,6 +53,10 @@ export async function setupCli() {
'-c, --cleanupDir <dir>', '-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' '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(); .help();
const commands: CommandWithAction<CommandArg> = { const commands: CommandWithAction<CommandArg> = {
@ -61,8 +74,8 @@ export async function setupCli() {
}, },
'git-commit': { 'git-commit': {
desc: 'git commit, generate commit message which match Conventional Commits standard', desc: 'git commit, generate commit message which match Conventional Commits standard',
action: async () => { action: async args => {
await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes); await gitCommit(cliOptions.gitCommitTypes, cliOptions.gitCommitScopes, args?.lang);
} }
}, },
'git-commit-verify': { 'git-commit-verify': {
@ -98,4 +111,6 @@ export async function setupCli() {
cli.parse(); cli.parse();
} }
setupCli(); (async () => {
await setupCli();
})();