Skip to content

Commit

Permalink
feat(cz-git): add typesAppend options to add extra types to default t…
Browse files Browse the repository at this point in the history
…ypes

- Use when you don't want to add bloated defaults and don't want to adjust the default order in
configuration
- `typesAppend: [ { value: "workflow", name: "workflow:  Workflow changes"} ]`
  • Loading branch information
Zhengqbbb committed Apr 7, 2022
1 parent 2aa9893 commit 8e8d4cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
7 changes: 5 additions & 2 deletions packages/cz-git/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const generateOptions = (clConfig: UserConfig): CommitizenGitOptions => {
return {
messages: pkgConfig.messages ?? clPromptConfig.messages ?? defaultConfig.messages,
types: pkgConfig.types ?? clPromptConfig.types ?? defaultConfig.types,
typesAppend: pkgConfig.typesAppend ?? clPromptConfig.typesAppend ?? defaultConfig.typesAppend,
useEmoji: pkgConfig.useEmoji ?? clPromptConfig.useEmoji ?? defaultConfig.useEmoji,
scopes: pkgConfig.scopes ?? clPromptConfig.scopes ?? getEnumList(clConfig?.rules?.["scope-enum"] as any),
scopeOverrides: pkgConfig.scopeOverrides ?? clPromptConfig.scopeOverrides ?? defaultConfig.scopeOverrides,
Expand Down Expand Up @@ -97,8 +98,10 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
type: "autocomplete",
name: "type",
message: options.messages?.type,
source: (_: unknown, input: string) =>
options.types?.filter((item) => (input ? item.value.includes(input) : true)) || true
source: (_: unknown, input: string) => {
const typesSource = options.types?.concat(options.typesAppend || []) || [];
return typesSource.filter((item) => (input ? item.value.includes(input) : true)) || true;
}
},
{
type: "autocomplete",
Expand Down
35 changes: 22 additions & 13 deletions packages/cz-git/src/share/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ export interface CommitizenGitOptions {
*/
types?: TypesOption[];

/**
* @description: Add extra types to default types
* @use Use when you don't want to add bloated defaults and don't want to adjust the default order in configuration
* @example `typesAppend: [ { value: "workflow", name: "workflow: Workflow changes"} ],`
* @default: []
*/
typesAppend?: TypesOption[];

/**
* @description: Use emoji ?| it will be use typesOption.emoji code
* @default: false
Expand All @@ -117,22 +125,22 @@ export interface CommitizenGitOptions {

/**
* @description: Provides a select of prompt to select module scopes
* @note: it auto import value from rule "scope-enum" with `@commitlint`
* @use: want to add scopes description or when you not use commitlint
* @note it auto import value from rule "scope-enum" with `@commitlint`
* @use want to add scopes description or when you not use commitlint
*/
scopes?: ScopesType;

/**
* @description: Provides an overriding select of prompt to select module scopes under specific typs
* @note: use this option should set `scopes` option to realize distinguish
* @note use this option should set `scopes` option to realize distinguish
* @example: [test] => provide select e2eTest unitTest
*/
scopeOverrides?: { [type: string]: ScopesType };

/**
* @description: Whether to show customizing when selecting scopes
* @note: it auto check rule "scope-enum" set the option with `@commitlint`
* @use: when you not use commitlint
* @note it auto check rule "scope-enum" set the option with `@commitlint`
* @use when you not use commitlint
* @default true
*/
allowCustomScopes?: boolean;
Expand Down Expand Up @@ -173,8 +181,8 @@ export interface CommitizenGitOptions {
/**
* @description: set body and BREAKING CHANGE max length to breakline
* @default: 100
* @note: it auto check rule "body-max-line-length" set the option with `@commitlint`.
* @use: when you not use commitlint
* @note it auto check rule "body-max-line-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
breaklineNumber?: number;

Expand Down Expand Up @@ -220,22 +228,22 @@ export interface CommitizenGitOptions {

/**
* @description: Force set max header length | Equivalent setting maxSubjectLength.
* @note: it auto check rule "header-max-length" set the option with `@commitlint`.
* @use: when you not use commitlint
* @note it auto check rule "header-max-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
maxHeaderLength?: number;

/**
* @description: Force set max subject length.
* @note: it auto check rule "subject-max-length" set the option with `@commitlint`.
* @use: when you not use commitlint
* @note it auto check rule "subject-max-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
maxSubjectLength?: number;

/**
* @description: Force set header width.
* @note: it auto check rule "subject-min-length" set the option with `@commitlint`.
* @use: when you not use commitlint
* @note it auto check rule "subject-min-length" set the option with `@commitlint`.
* @use when you not use commitlint
*/
minSubjectLength?: number;

Expand Down Expand Up @@ -296,6 +304,7 @@ export const defaultConfig = Object.freeze({
{ value: "chore", name: "chore: Other changes that don't modify src or test files", emoji: ":hammer:" },
{ value: "revert", name: "revert: Reverts a previous commit", emoji: ":rewind:" }
],
typesAppend: [],
useEmoji: false,
scopes: [],
allowCustomScopes: true,
Expand Down
3 changes: 2 additions & 1 deletion packages/cz-git/src/until/until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ const addScope = (scope?: string, colorize?: boolean) => {

const addEmoji = (type: string, options: CommitizenGitOptions): string => {
if (options.useEmoji && type !== "") {
const item = options.types?.find((i) => i.value === type);
const itemSource = options.types?.concat(options.typesAppend || []) || [];
const item = itemSource.find((i) => i.value === type);
return item?.emoji ? ` ${item.emoji} ` : " ";
} else {
return " ";
Expand Down

0 comments on commit 8e8d4cc

Please sign in to comment.