Skip to content

Commit

Permalink
Merge pull request #19 from Zhengqbbb/feature/issue_16 (close #16)
Browse files Browse the repository at this point in the history
feat(cz-git): use defaultScope can star item of scope list
fix(cz-git): fix custom scope skip allowEmptyScopes check
  • Loading branch information
Zhengqbbb authored Apr 23, 2022
2 parents 73b0d98 + f0d8c53 commit cb2734a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
5 changes: 5 additions & 0 deletions docs/guide/options-show.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ Using ==default value== can produce many ways to make the tool more suitable for
- **default** : `""`
- **use** : when you want the default value to appear on the command line just press the "Enter" key

:::tip
If `defaultScope` matches the scope list item `value`.
It will be pinned to the top of scope list.
:::

## defaultSubject

- **description** : Whether to use the display default value in the **short description**
Expand Down
4 changes: 4 additions & 0 deletions docs/zh/guide/options-show.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ lastUpdated: true
- **默认** : `""`
- **使用** : 当你想要命令行中出现的默认值只需要按下 "Enter" 键即可

:::tip
如果 `defaultScope` 与在选择范围列表项中的 `value` 相匹配就会进行星标置顶操作。
:::

## defaultSubject

- **描述** : 在 **简短描述** 中是否使用显示默认值
Expand Down
17 changes: 11 additions & 6 deletions packages/cz-git/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.emptyScopesAlias,
options.customScopesAlias,
options.allowCustomScopes,
options.allowEmptyScopes
options.allowEmptyScopes,
options.defaultScope as string
);
return scopes?.filter((item) => (input ? item.name?.includes(input) : true)) || true;
}
Expand All @@ -134,6 +135,10 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
name: "scope",
message: options.messages?.customScope,
default: options.defaultScope || undefined,
validate(input: string) {
if (options.allowEmptyScopes) return true;
return input.length ? true : "\u001B[1;31m[ERROR] scope is required\u001B[0m";
},
when(answers: Answers) {
return answers.scope === "___CUSTOM___";
}
Expand Down Expand Up @@ -169,14 +174,14 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
else tooltip = `${maxSubjectLength - subjectLength} more chars allowed`;
const tooltipColor =
minSubjectLength !== undefined &&
subjectLength >= minSubjectLength &&
subjectLength <= maxSubjectLength
subjectLength >= minSubjectLength &&
subjectLength <= maxSubjectLength
? "\u001B[90m"
: "\u001B[31m";
const subjectColor =
minSubjectLength !== undefined &&
subjectLength >= minSubjectLength &&
subjectLength <= maxSubjectLength
subjectLength >= minSubjectLength &&
subjectLength <= maxSubjectLength
? "\u001B[36m"
: "\u001B[31m";

Expand Down Expand Up @@ -228,7 +233,7 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
options.customIssuePrefixsAlias,
options.allowCustomIssuePrefixs,
options.allowEmptyIssuePrefixs
)
);
return issues?.filter((item) => (input ? item.name?.includes(input) : true)) || true;
}
},
Expand Down
12 changes: 11 additions & 1 deletion packages/cz-git/src/until/until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export const handleCustomTemplate = (
emptyAlias = "empty",
customAlias = "custom",
allowCustom = true,
allowEmpty = true
allowEmpty = true,
defaultValue = ""
) => {
let result: Array<{ name: string; value: any }> = [
{ name: emptyAlias, value: false },
Expand All @@ -90,6 +91,15 @@ export const handleCustomTemplate = (
];
if (!Array.isArray(target)) {
return result;
} else if (defaultValue !== "") {
// put the defaultValue to the top
const targetIndex = target.findIndex((i) => i.value === defaultValue);
if (targetIndex !== -1)
target = [
target[targetIndex],
...target.slice(0, targetIndex),
...target.slice(targetIndex + 1)
];
}
switch (align) {
case "top":
Expand Down

0 comments on commit cb2734a

Please sign in to comment.