Skip to content

Commit

Permalink
feat: allow set scope as direct input to use (#113)
Browse files Browse the repository at this point in the history
setting config:
1. skipQuestions: ['scope']
2. defaultScope: '___CUSTOM___'
3. messages: {customScope: 'What is the scope of this change:'}
  • Loading branch information
Zhengqbbb committed Jul 8, 2023
1 parent 9ca09aa commit e9ca6f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/cz-git/src/generator/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ import {
getMinLength,
ruleIsWarning,
} from '../shared'
import type { CommitizenGitOptions, UserConfig } from '../shared'
import type { Answers, CommitizenGitOptions, UserConfig } from '../shared'

export function generateOptions(config: UserConfig): CommitizenGitOptions {
const { emoji, checkbox, czai, no_czai, cz_ainum, ___X_CMD_THEME_COLOR_CODE } = process.env
const promptConfig = config.prompt ?? {}

return {
alias: promptConfig.alias ?? defaultConfig.alias,
messages: promptConfig.messages ?? defaultConfig.messages,
messages: {
...defaultConfig.messages,
...promptConfig.messages,
} as Answers,
themeColorCode: ___X_CMD_THEME_COLOR_CODE || promptConfig.themeColorCode || defaultConfig.themeColorCode,
types: promptConfig.types ?? defaultConfig.types,
typesAppend: promptConfig.typesAppend ?? defaultConfig.typesAppend,
Expand Down
4 changes: 2 additions & 2 deletions packages/cz-git/src/generator/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
type: 'complete-input',
name: 'customScope',
message: options.messages?.customScope,
completeValue: options.defaultScope || undefined,
completeValue: (options.defaultScope && options.defaultScope !== '___CUSTOM___') ? options.defaultScope : undefined,
validate: (input: string | Array<string>) => {
if (options.allowEmptyScopes)
return true
Expand All @@ -106,7 +106,7 @@ export function generateQuestions(options: CommitizenGitOptions, cz: any) {
return input.length !== 0 ? true : style.red('[ERROR] scope is required')
},
when: (answers: Answers) => {
return answers.scope === '___CUSTOM___'
return answers.scope === '___CUSTOM___' || options.defaultScope === '___CUSTOM___'
},
transformer: (input: string) => useThemeCode(input, options.themeColorCode),
},
Expand Down

0 comments on commit e9ca6f7

Please sign in to comment.