Skip to content

Commit 86e95a7

Browse files
committed
feat(cz-git): add scopeFilters options to filter scopes item
e.g [".DS_Store"] link #30
1 parent 4db5914 commit 86e95a7

6 files changed

Lines changed: 31 additions & 6 deletions

File tree

‎docs/guide/option-engineer.md‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@ If you define a `scope-enum` using the [commitlint](https://github.com/conventio
2323
- **description** : After customizing a specific **type**, **override module scope** command line display information
2424
- **type** : <br>`{ [type: string]: string[] | Array<{ name: string, value?: string }> } | undefined`
2525
- **default** : `undefined`
26-
- **example** : `scopeOverrides: { "test": ['e2eTest, 'unitTest'] }`
26+
- **example** : `scopeOverrides: { "test": ["e2eTest", "unitTest"] }`
2727
- **use** : Displays custom module scope selection when selecting module scope after selecting ==specific== commit **type** : `type`
2828

2929
:::tip
3030
If you define `scopeOverrides` then define generic `scopes`
3131
:::
3232

33+
## scopeFilters
34+
35+
- **description** : Filter select of prompt to select module scopes by the scope.value
36+
- **type** : string[]
37+
- **default** : `[".DS_Store"]`
38+
3339
## enableMultipleScopes
3440

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

7379
- **description** : a specific **type** that allows BREAKING CHANGES
7480
- **type** : `string[]`
75-
- **default** : `['feat', 'fix']`
81+
- **default** : `["feat", "fix"]`
7682

7783
## upperCaseSubject
7884

‎docs/zh/guide/option-engineer.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ sitemap:
2424
- **描述** : 自定义选择了特定**类型**后 **覆盖模块范围** 命令行显示信息
2525
- **类型** : <br>`{ [type: string]: string[] | Array<{ name: string, value?: string }> } | undefined`
2626
- **默认** : `undefined`
27-
- **例子** : `scopeOverrides: { "test": ['e2eTest, 'unitTest'] }`
27+
- **例子** : `scopeOverrides: { "test": ["e2eTest", "unitTest"] }`
2828
- **使用** : 针对选择 ==特定== 的 commit **类型** `type` 后选择模块范围时显示 自定义的模块范围选择
2929

3030
:::tip
3131
如果定义`scopeOverrides` 就要定义通用的 `scopes`
3232
:::
3333

34+
## scopeFilters
35+
36+
- **描述** : Filter select of prompt to select module scopes by the scope.value
37+
- **描述** : 根据 scope.value 过滤模块范围中的选项
38+
- **类型** : string[]
39+
- **默认** : `[".DS_Store"]`
40+
3441
## enableMultipleScopes
3542

3643
- **描述** : 是否开启在选择 **模块范围** 时使用多选模式

‎packages/cz-git/src/generator/option.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const generateOptions = (config: UserConfig): CommitizenGitOptions => {
2828
useEmoji: Boolean(emoji) || promptConfig.useEmoji || defaultConfig.useEmoji,
2929
scopes: promptConfig.scopes ?? getEnumList(config?.rules?.["scope-enum"] as any),
3030
scopeOverrides: promptConfig.scopeOverrides ?? defaultConfig.scopeOverrides,
31+
scopeFilters: promptConfig.scopeFilters ?? defaultConfig.scopeFilters,
3132
enableMultipleScopes: Boolean(checkbox) || promptConfig.enableMultipleScopes || defaultConfig.enableMultipleScopes,
3233
scopeEnumSeparator: promptConfig.scopeEnumSeparator ?? defaultConfig.scopeEnumSeparator,
3334
allowCustomScopes: promptConfig.allowCustomScopes ?? !enumRuleIsActive(config?.rules?.["scope-enum"] as any),

‎packages/cz-git/src/generator/question.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
5656
options.customScopesAlias,
5757
options.allowCustomScopes,
5858
options.allowEmptyScopes,
59-
options.defaultScope as string
59+
options.defaultScope as string,
60+
options.scopeFilters
6061
);
6162
return fuzzyFilter(input, scopeSource);
6263
},

‎packages/cz-git/src/shared/types/options.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ export interface CommitizenGitOptions {
144144
*/
145145
scopeOverrides?: { [type: string]: ScopesType };
146146

147+
/**
148+
* @description: Filter select of prompt to select module scopes by the scope.value
149+
* @default: ['.DS_Store']
150+
*/
151+
scopeFilters?: string[];
152+
147153
/**
148154
* @description: Whether to enable scope multiple mode
149155
* @default: false
@@ -362,6 +368,7 @@ export const defaultConfig = Object.freeze({
362368
maxSubjectLength: Infinity,
363369
minSubjectLength: 0,
364370
scopeOverrides: undefined,
371+
scopeFilters: [".DS_Store"],
365372
defaultBody: "",
366373
defaultScope: "",
367374
defaultSubject: "",

‎packages/cz-git/src/shared/utils/util.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export const handleCustomTemplate = (
7777
customAlias = "custom",
7878
allowCustom = true,
7979
allowEmpty = true,
80-
defaultValue = ""
80+
defaultValue = "",
81+
scopeFilters = [".DS_Store"]
8182
) => {
8283
let result: Array<{ name: string; value: any }> = [
8384
{ name: emptyAlias, value: false },
@@ -121,7 +122,9 @@ export const handleCustomTemplate = (
121122
.concat(target);
122123
break;
123124
}
124-
return filterCustomEmptyByOption(result, allowCustom, allowEmpty);
125+
return filterCustomEmptyByOption(result, allowCustom, allowEmpty).filter(
126+
(i) => !scopeFilters.includes(i.value)
127+
);
125128
};
126129

127130
/**

0 commit comments

Comments
 (0)