Skip to content

Commit

Permalink
feat(cz-git): add scopeFilters options to filter scopes item
Browse files Browse the repository at this point in the history
e.g [".DS_Store"]

link #30
  • Loading branch information
Zhengqbbb committed May 27, 2022
1 parent 4db5914 commit 86e95a7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
10 changes: 8 additions & 2 deletions docs/guide/option-engineer.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@ If you define a `scope-enum` using the [commitlint](https://github.com/conventio
- **description** : After customizing a specific **type**, **override module scope** command line display information
- **type** : <br>`{ [type: string]: string[] | Array<{ name: string, value?: string }> } | undefined`
- **default** : `undefined`
- **example** : `scopeOverrides: { "test": ['e2eTest, 'unitTest'] }`
- **example** : `scopeOverrides: { "test": ["e2eTest", "unitTest"] }`
- **use** : Displays custom module scope selection when selecting module scope after selecting ==specific== commit **type** : `type`

:::tip
If you define `scopeOverrides` then define generic `scopes`
:::

## scopeFilters

- **description** : Filter select of prompt to select module scopes by the scope.value
- **type** : string[]
- **default** : `[".DS_Store"]`

## enableMultipleScopes

- **description** : Whether to enable the use of **multiple scopes mode**
Expand Down Expand Up @@ -72,7 +78,7 @@ It will automatically detect whether the definition of the [commitlint](https://

- **description** : a specific **type** that allows BREAKING CHANGES
- **type** : `string[]`
- **default** : `['feat', 'fix']`
- **default** : `["feat", "fix"]`

## upperCaseSubject

Expand Down
9 changes: 8 additions & 1 deletion docs/zh/guide/option-engineer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ sitemap:
- **描述** : 自定义选择了特定**类型****覆盖模块范围** 命令行显示信息
- **类型** : <br>`{ [type: string]: string[] | Array<{ name: string, value?: string }> } | undefined`
- **默认** : `undefined`
- **例子** : `scopeOverrides: { "test": ['e2eTest, 'unitTest'] }`
- **例子** : `scopeOverrides: { "test": ["e2eTest", "unitTest"] }`
- **使用** : 针对选择 ==特定== 的 commit **类型** `type` 后选择模块范围时显示 自定义的模块范围选择

:::tip
如果定义`scopeOverrides` 就要定义通用的 `scopes`
:::

## scopeFilters

- **描述** : Filter select of prompt to select module scopes by the scope.value
- **描述** : 根据 scope.value 过滤模块范围中的选项
- **类型** : string[]
- **默认** : `[".DS_Store"]`

## enableMultipleScopes

- **描述** : 是否开启在选择 **模块范围** 时使用多选模式
Expand Down
1 change: 1 addition & 0 deletions packages/cz-git/src/generator/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const generateOptions = (config: UserConfig): CommitizenGitOptions => {
useEmoji: Boolean(emoji) || promptConfig.useEmoji || defaultConfig.useEmoji,
scopes: promptConfig.scopes ?? getEnumList(config?.rules?.["scope-enum"] as any),
scopeOverrides: promptConfig.scopeOverrides ?? defaultConfig.scopeOverrides,
scopeFilters: promptConfig.scopeFilters ?? defaultConfig.scopeFilters,
enableMultipleScopes: Boolean(checkbox) || promptConfig.enableMultipleScopes || defaultConfig.enableMultipleScopes,
scopeEnumSeparator: promptConfig.scopeEnumSeparator ?? defaultConfig.scopeEnumSeparator,
allowCustomScopes: promptConfig.allowCustomScopes ?? !enumRuleIsActive(config?.rules?.["scope-enum"] as any),
Expand Down
3 changes: 2 additions & 1 deletion packages/cz-git/src/generator/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.customScopesAlias,
options.allowCustomScopes,
options.allowEmptyScopes,
options.defaultScope as string
options.defaultScope as string,
options.scopeFilters
);
return fuzzyFilter(input, scopeSource);
},
Expand Down
7 changes: 7 additions & 0 deletions packages/cz-git/src/shared/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export interface CommitizenGitOptions {
*/
scopeOverrides?: { [type: string]: ScopesType };

/**
* @description: Filter select of prompt to select module scopes by the scope.value
* @default: ['.DS_Store']
*/
scopeFilters?: string[];

/**
* @description: Whether to enable scope multiple mode
* @default: false
Expand Down Expand Up @@ -362,6 +368,7 @@ export const defaultConfig = Object.freeze({
maxSubjectLength: Infinity,
minSubjectLength: 0,
scopeOverrides: undefined,
scopeFilters: [".DS_Store"],
defaultBody: "",
defaultScope: "",
defaultSubject: "",
Expand Down
7 changes: 5 additions & 2 deletions packages/cz-git/src/shared/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export const handleCustomTemplate = (
customAlias = "custom",
allowCustom = true,
allowEmpty = true,
defaultValue = ""
defaultValue = "",
scopeFilters = [".DS_Store"]
) => {
let result: Array<{ name: string; value: any }> = [
{ name: emptyAlias, value: false },
Expand Down Expand Up @@ -121,7 +122,9 @@ export const handleCustomTemplate = (
.concat(target);
break;
}
return filterCustomEmptyByOption(result, allowCustom, allowEmpty);
return filterCustomEmptyByOption(result, allowCustom, allowEmpty).filter(
(i) => !scopeFilters.includes(i.value)
);
};

/**
Expand Down

0 comments on commit 86e95a7

Please sign in to comment.