Skip to content

Commit

Permalink
feat(cz-git): use defaultScope can star item of scope list
Browse files Browse the repository at this point in the history
If `defaultScope` matches the list item `value`.
It will be pinned to the top of scope list

link #16
  • Loading branch information
Zhengqbbb committed Apr 23, 2022
1 parent 73b0d98 commit b899d2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion 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 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 b899d2c

Please sign in to comment.