Skip to content

Commit

Permalink
feat(cz-git): support types fuzzy search types[name] options
Browse files Browse the repository at this point in the history
add `typesSearchValueKey` option
default types list fuzzy search types `value` options.
if choose `false` will search `name` options

link #57
  • Loading branch information
Zhengqbbb committed Aug 18, 2022
1 parent 8fb63b0 commit ba4ce71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/cz-git/src/generator/option.ts
Expand Up @@ -24,6 +24,7 @@ export const generateOptions = (config: UserConfig): CommitizenGitOptions => {
themeColorCode: ___X_CMD_THEME_COLOR_CODE || promptConfig.themeColorCode || defaultConfig.themeColorCode,
types: promptConfig.types ?? defaultConfig.types,
typesAppend: promptConfig.typesAppend ?? defaultConfig.typesAppend,
typesSearchValueKey: promptConfig.typesSearchValueKey ?? defaultConfig.typesSearchValueKey,
useEmoji: Boolean(emoji === '1') || promptConfig.useEmoji || defaultConfig.useEmoji,
emojiAlign: promptConfig.emojiAlign || defaultConfig.emojiAlign,
scopes: promptConfig.scopes ?? getEnumList(config?.rules?.['scope-enum'] as any),
Expand Down
5 changes: 4 additions & 1 deletion packages/cz-git/src/generator/question.ts
Expand Up @@ -39,7 +39,10 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.types?.concat(options.typesAppend || []) || [],
options.defaultType,
)
return fuzzyFilter(input, typeSource, 'value')
const searchTarget = options.typesSearchValueKey
? 'value'
: 'name'
return fuzzyFilter(input, typeSource, searchTarget)
},
},
{
Expand Down
7 changes: 7 additions & 0 deletions packages/cz-git/src/shared/types/options.ts
Expand Up @@ -138,6 +138,12 @@ export interface CommitizenGitOptions {
*/
typesAppend?: TypesOption[]

/**
* @description: default types list fuzzy search types `value` options. if choose `false` will search `name` options
* @default: true
*/
typesSearchValueKey?: boolean

/**
* @description: Use emoji ?| it will be use typesOption.emoji code
* @default: false
Expand Down Expand Up @@ -380,6 +386,7 @@ export const defaultConfig = Object.freeze({
{ value: 'revert', name: 'revert: Reverts a previous commit', emoji: ':rewind:' },
],
typesAppend: [],
typesSearchValueKey: true,
themeColorCode: '',
useEmoji: false,
emojiAlign: 'center',
Expand Down

0 comments on commit ba4ce71

Please sign in to comment.