Skip to content

Commit

Permalink
feat(cz-git): add markBreakingChangeMode options to add extra prompt
Browse files Browse the repository at this point in the history
it use exclamation (!) to denote breaking change
see: https://www.conventionalcommits.org/en/v1.0.0/#examples

link #38
  • Loading branch information
Zhengqbbb committed Jun 22, 2022
1 parent 62e84c3 commit da4b624
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
12 changes: 9 additions & 3 deletions packages/cz-git/src/generator/message.ts
Expand Up @@ -35,10 +35,14 @@ const getSingleParams = (answers: Answers, options: CommitizenGitOptions) => {
const addType = (type: string, colorize?: boolean) => (colorize ? style.green(type) : type);

const addScope = (scope?: string, colorize?: boolean) => {
const separator = ":";
if (!scope) return separator;
if (!scope) return "";
scope = colorize ? style.yellow(scope) : scope;
return `(${scope.trim()})${separator}`;
return `(${scope.trim()})`;
};

const addBreakchangeMark = (markBreaking?: string, colorize?: boolean) => {
const mark = colorize ? style.red("!") : "!";
return Boolean(markBreaking) || Boolean(process.env.break === "1") ? mark : "";
};

const addEmoji = (type: string, options: CommitizenGitOptions): string => {
Expand Down Expand Up @@ -85,6 +89,8 @@ export const generateMessage = (
const head =
addType(answers.type ?? "", colorize) +
addScope(singleScope || scope, colorize) +
addBreakchangeMark(answers.markBreaking, colorize) +
":" +
addEmoji(answers.type ?? "", options) +
addSubject(answers.subject, colorize);
const body = wrap(answers.body ?? "", wrapOptions);
Expand Down
5 changes: 3 additions & 2 deletions packages/cz-git/src/generator/option.ts
Expand Up @@ -25,18 +25,19 @@ export const generateOptions = (config: UserConfig): CommitizenGitOptions => {
themeColorCode: ___X_CMD_THEME_COLOR_CODE || promptConfig.themeColorCode || defaultConfig.themeColorCode,
types: promptConfig.types ?? defaultConfig.types,
typesAppend: promptConfig.typesAppend ?? defaultConfig.typesAppend,
useEmoji: Boolean(emoji) || promptConfig.useEmoji || defaultConfig.useEmoji,
useEmoji: Boolean(emoji === "1") || 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,
enableMultipleScopes: Boolean(checkbox === "1") || promptConfig.enableMultipleScopes || defaultConfig.enableMultipleScopes,
scopeEnumSeparator: promptConfig.scopeEnumSeparator ?? defaultConfig.scopeEnumSeparator,
allowCustomScopes: promptConfig.allowCustomScopes ?? !enumRuleIsActive(config?.rules?.["scope-enum"] as any),
allowEmptyScopes: promptConfig.allowEmptyScopes ?? !emptyRuleIsActive(config?.rules?.["scope-empty"] as any),
customScopesAlign: promptConfig.customScopesAlign ?? defaultConfig.customScopesAlign,
customScopesAlias: promptConfig.customScopesAlias ?? defaultConfig.customScopesAlias,
emptyScopesAlias: promptConfig.emptyScopesAlias ?? defaultConfig.emptyScopesAlias,
upperCaseSubject: promptConfig.upperCaseSubject ?? defaultConfig.upperCaseSubject,
markBreakingChangeMode: promptConfig.markBreakingChangeMode ?? defaultConfig.markBreakingChangeMode,
allowBreakingChanges: promptConfig.allowBreakingChanges ?? defaultConfig.allowBreakingChanges,
breaklineNumber: getMaxLength(config?.rules?.["body-max-line-length"] as any) === Infinity
? promptConfig.breaklineNumber ?? defaultConfig.breaklineNumber
Expand Down
11 changes: 10 additions & 1 deletion packages/cz-git/src/generator/question.ts
Expand Up @@ -165,13 +165,22 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
completeValue: options.defaultBody || undefined,
transformer: (input: string) => useThemeCode(input, options.themeColorCode)
},
{
type: "confirm",
name: "markBreaking",
message: options.messages?.markBreaking,
default: false,
when: () => options.markBreakingChangeMode === true
},
{
type: "complete-input",
name: "breaking",
message: options.messages?.breaking,
completeValue: options.defaultBody || undefined,
when: (answers: Answers) => {
if (
if (options.markBreakingChangeMode === true) {
return answers.markBreaking;
} else if (
options.allowBreakingChanges &&
answers.type &&
options.allowBreakingChanges.includes(answers.type)
Expand Down
14 changes: 14 additions & 0 deletions packages/cz-git/src/shared/types/options.ts
Expand Up @@ -46,6 +46,11 @@ export type Answers = {
* @default:Provide a LONGER description of the change (optional). Use "|" to break new line:\n
*/
body?: string;
/**
* @default: Is any BREAKING CHANGE (add "!" in header) (optional) ?
* @use need turn on options "markBreakingChangeMode"
*/
markBreaking?: string;
/**
* @default: List any BREAKING CHANGES (optional). Use "|" to break new line:\n
*/
Expand Down Expand Up @@ -197,6 +202,13 @@ export interface CommitizenGitOptions {
*/
upperCaseSubject?: boolean;

/**
* @description: Whether to add extra prompt BREAKCHANGE ask. to add an extra "!" to the header
* @see: https://cz-git.qbenben.com/recipes/breakingchange
* @default: false
*/
markBreakingChangeMode?: boolean;

/**
* @description: Allow breaking changes in the included types output box
* @default: ['feat', 'fix']
Expand Down Expand Up @@ -332,6 +344,7 @@ export const defaultConfig = Object.freeze({
customScope: "Denote the SCOPE of this change:",
subject: "Write a SHORT, IMPERATIVE tense description of the change:\n",
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
markBreaking: 'Is any BREAKING CHANGE (add "!" in header) (optional) ?',
breaking: 'List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
footerPrefixsSelect: "Select the ISSUES type of change (optional):",
customFooterPrefixs: "Input ISSUES prefix:",
Expand Down Expand Up @@ -363,6 +376,7 @@ export const defaultConfig = Object.freeze({
customScopesAlias: "custom",
emptyScopesAlias: "empty",
upperCaseSubject: false,
markBreakingChangeMode: false,
allowBreakingChanges: ['feat', 'fix'],
breaklineNumber: 100,
breaklineChar: "|",
Expand Down

0 comments on commit da4b624

Please sign in to comment.