Skip to content

Commit

Permalink
feat(cz-git,czg): add scopesSearchValue boolean option field #83 (#85)
Browse files Browse the repository at this point in the history
* feat(cz-git): add `scopesSearchValue` boolean option field

default scope list fuzzy search types `name` key of list.
if choose `true` will search `value` key of list.
@use If have long description of scope. can use it to enhanced search.
@default: `false`

BREAKING CHANGE: rename option `typesSearchValueKey` to `typesSearchValue`
  * Already processed for normal compatibility
  • Loading branch information
Zhengqbbb authored Dec 4, 2022
1 parent febeba9 commit 867eb87
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .commitlintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
'table:docs': 'docs: update project using table' + coAuthoredBy,
},
themeColorCode: '38;5;043',
issuePrefixs: [
issuePrefixes: [
{ value: 'link', name: 'link: Work in processing to ISSUES' },
{ value: 'closed', name: 'closed: ISSUES has been processed' },
],
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/config/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const enConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
head: [
['meta', { name: 'twitter:description', content: descriptionEN }],
['meta', { name: 'twitter:image', content: ogImg }],
['meta', { name: 'og:description', content: descriptionEN }],
['meta', { name: 'og:url', content: site }],
['meta', { name: 'og:locale', content: 'en_US' }],
['meta', { name: 'og:image', content: ogImg }],
['meta', { property: 'og:description', content: descriptionEN }],
['meta', { property: 'og:url', content: site }],
['meta', { property: 'og:locale', content: 'en_US' }],
['meta', { property: 'og:image', content: ogImg }],
],
}
2 changes: 1 addition & 1 deletion docs/.vitepress/config/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const shareConfig = defineConfig({
['meta', { name: 'twitter:creator', content: '@zhengqbbb' }],
['meta', { name: 'twitter:site', content: '@zhengqbbb' }],
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
['meta', { name: 'og:type', content: 'article' }],
['meta', { property: 'og:type', content: 'article' }],
['meta', { name: 'application-name', content: name }],
['meta', { name: 'apple-mobile-web-app-title', content: name }],
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'default' }],
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/config/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export const zhConfig: LocaleSpecificConfig<DefaultTheme.Config> = {
head: [
['meta', { name: 'twitter:description', content: descriptionCN }],
['meta', { name: 'twitter:image', content: ogImgCN }],
['meta', { name: 'og:description', content: descriptionCN }],
['meta', { name: 'og:url', content: siteCN }],
['meta', { name: 'og:locale', content: 'zh_CN' }],
['meta', { name: 'og:image', content: ogImgCN }],
['meta', { property: 'og:description', content: descriptionCN }],
['meta', { property: 'og:url', content: siteCN }],
['meta', { property: 'og:locale', content: 'zh_CN' }],
['meta', { property: 'og:image', content: ogImgCN }],
],
}
8 changes: 7 additions & 1 deletion docs/config/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,18 @@ Try running command to **enable output emoji mode in the current session**
}
```

## typesSearchValueKey
## typesSearchValue

- **description** : Default types list fuzzy search `value` key. Set `false` will search `name` key.
- **type** : `boolean`
- **default** : `true`

## scopesSearchValue

- **description** : Default `scopes` list fuzzy search `name` key. Set `true` will search `value` key.
- **type** : `boolean`
- **default** : `false`

## customScopesAlign

- **description** : Set the **location** of empty option (empty) and custom option (custom) in **selection range**
Expand Down
10 changes: 8 additions & 2 deletions docs/zh/config/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ export ___X_CMD_THEME_COLOR_CODE="38;5;043"
}
```

## typesSearchValueKey
## typesSearchValue

- **描述** : 默认 `types` 列表的模糊搜索针对 `value` 字段。设置为 `false` 后针对 `name` 字段
- **描述** : 默认 `types` 类别列表的模糊搜索针对列表 `value` 字段。设置为 `false` 后针对列表 `name` 字段
- **类型** : `boolean`
- **默认** : `true`

## scopesSearchValue

- **描述** : 默认 `scopes` 范围列表的模糊搜索针对列表 `name` 字段。设置为 `true` 后针对列表 `value` 字段
- **类型** : `boolean`
- **默认** : `false`

## customScopesAlign

- **描述** : 设置 **选择范围** 中 为空选项(empty) 和 自定义选项(custom) 的 **位置**
Expand Down
3 changes: 2 additions & 1 deletion packages/cz-git/src/generator/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ 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,
typesSearchValue: promptConfig.typesSearchValueKey ?? promptConfig.typesSearchValue ?? defaultConfig.typesSearchValue,
useEmoji: Boolean(emoji === '1') || promptConfig.useEmoji || defaultConfig.useEmoji,
emojiAlign: promptConfig.emojiAlign || defaultConfig.emojiAlign,
scopes: promptConfig.scopes ?? getEnumList(config?.rules?.['scope-enum'] as any),
scopesSearchValue: promptConfig.scopesSearchValue ?? defaultConfig.scopesSearchValue,
scopeOverrides: promptConfig.scopeOverrides ?? defaultConfig.scopeOverrides,
scopeFilters: promptConfig.scopeFilters ?? defaultConfig.scopeFilters,
enableMultipleScopes: Boolean(checkbox === '1') || promptConfig.enableMultipleScopes || defaultConfig.enableMultipleScopes,
Expand Down
7 changes: 5 additions & 2 deletions packages/cz-git/src/generator/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.types?.concat(options.typesAppend || []) || [],
options.defaultType,
)
const searchTarget = options.typesSearchValueKey
const searchTarget = options.typesSearchValue
? 'value'
: 'name'
return fuzzyFilter(input, typeSource, searchTarget)
Expand Down Expand Up @@ -67,7 +67,10 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.defaultScope as string,
options.scopeFilters,
)
return fuzzyFilter(input, scopeSource)
const searchTarget = options.scopesSearchValue
? 'value'
: 'name'
return fuzzyFilter(input, scopeSource, searchTarget)
},
validate: (input: string | Array<string>) => {
if (options.allowEmptyScopes)
Expand Down
21 changes: 16 additions & 5 deletions packages/cz-git/src/shared/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,13 @@ export interface CommitizenGitOptions {
typesAppend?: TypesOption[]

/**
* @description: default types list fuzzy search types `value` options.
* if choose `false` will search `name` options
* @description: default types list fuzzy search types `value` key of list.
* if choose `false` will search `name` key of list
* @use Using emoji unicode as `value` and that can't be searched
* @default: true
*/
typesSearchValue?: boolean
/** @deprecated Please use `typesSearchValue` field instead. */
typesSearchValueKey?: boolean

/**
Expand All @@ -214,6 +216,14 @@ export interface CommitizenGitOptions {
*/
scopes?: ScopesType

/**
* @description: default scope list fuzzy search types `name` key of list.
* if choose `true` will search `value` key of list.
* @use If have long description of scope. can use it to enhanced search.
* @default: false
*/
scopesSearchValue?: boolean

/**
* @description: Provides an overriding select of prompt to select module scopes under specific type
* @note use this option should set `scopes` option to realize distinguish
Expand Down Expand Up @@ -490,11 +500,14 @@ export const defaultConfig = Object.freeze({
{ value: 'revert', name: 'revert: Reverts a previous commit', emoji: ':rewind:' },
],
typesAppend: [],
typesSearchValueKey: true,
typesSearchValue: true,
themeColorCode: '',
useEmoji: false,
emojiAlign: 'center',
scopes: [],
scopesSearchValue: false,
scopeOverrides: undefined,
scopeFilters: ['.DS_Store'],
enableMultipleScopes: false,
scopeEnumSeparator: ',',
allowCustomScopes: true,
Expand All @@ -519,8 +532,6 @@ export const defaultConfig = Object.freeze({
maxSubjectLength: Infinity,
isIgnoreCheckMaxSubjectLength: false,
minSubjectLength: 0,
scopeOverrides: undefined,
scopeFilters: ['.DS_Store'],
defaultType: '',
defaultScope: '',
defaultBody: '',
Expand Down

0 comments on commit 867eb87

Please sign in to comment.