Skip to content

Commit da4b624

Browse files
committed
feat(cz-git): add markBreakingChangeMode options to add extra prompt
it use exclamation (!) to denote breaking change see: https://www.conventionalcommits.org/en/v1.0.0/#examples link #38
1 parent 62e84c3 commit da4b624

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ const getSingleParams = (answers: Answers, options: CommitizenGitOptions) => {
3535
const addType = (type: string, colorize?: boolean) => (colorize ? style.green(type) : type);
3636

3737
const addScope = (scope?: string, colorize?: boolean) => {
38-
const separator = ":";
39-
if (!scope) return separator;
38+
if (!scope) return "";
4039
scope = colorize ? style.yellow(scope) : scope;
41-
return `(${scope.trim()})${separator}`;
40+
return `(${scope.trim()})`;
41+
};
42+
43+
const addBreakchangeMark = (markBreaking?: string, colorize?: boolean) => {
44+
const mark = colorize ? style.red("!") : "!";
45+
return Boolean(markBreaking) || Boolean(process.env.break === "1") ? mark : "";
4246
};
4347

4448
const addEmoji = (type: string, options: CommitizenGitOptions): string => {
@@ -85,6 +89,8 @@ export const generateMessage = (
8589
const head =
8690
addType(answers.type ?? "", colorize) +
8791
addScope(singleScope || scope, colorize) +
92+
addBreakchangeMark(answers.markBreaking, colorize) +
93+
":" +
8894
addEmoji(answers.type ?? "", options) +
8995
addSubject(answers.subject, colorize);
9096
const body = wrap(answers.body ?? "", wrapOptions);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ export const generateOptions = (config: UserConfig): CommitizenGitOptions => {
2525
themeColorCode: ___X_CMD_THEME_COLOR_CODE || promptConfig.themeColorCode || defaultConfig.themeColorCode,
2626
types: promptConfig.types ?? defaultConfig.types,
2727
typesAppend: promptConfig.typesAppend ?? defaultConfig.typesAppend,
28-
useEmoji: Boolean(emoji) || promptConfig.useEmoji || defaultConfig.useEmoji,
28+
useEmoji: Boolean(emoji === "1") || promptConfig.useEmoji || defaultConfig.useEmoji,
2929
scopes: promptConfig.scopes ?? getEnumList(config?.rules?.["scope-enum"] as any),
3030
scopeOverrides: promptConfig.scopeOverrides ?? defaultConfig.scopeOverrides,
3131
scopeFilters: promptConfig.scopeFilters ?? defaultConfig.scopeFilters,
32-
enableMultipleScopes: Boolean(checkbox) || promptConfig.enableMultipleScopes || defaultConfig.enableMultipleScopes,
32+
enableMultipleScopes: Boolean(checkbox === "1") || promptConfig.enableMultipleScopes || defaultConfig.enableMultipleScopes,
3333
scopeEnumSeparator: promptConfig.scopeEnumSeparator ?? defaultConfig.scopeEnumSeparator,
3434
allowCustomScopes: promptConfig.allowCustomScopes ?? !enumRuleIsActive(config?.rules?.["scope-enum"] as any),
3535
allowEmptyScopes: promptConfig.allowEmptyScopes ?? !emptyRuleIsActive(config?.rules?.["scope-empty"] as any),
3636
customScopesAlign: promptConfig.customScopesAlign ?? defaultConfig.customScopesAlign,
3737
customScopesAlias: promptConfig.customScopesAlias ?? defaultConfig.customScopesAlias,
3838
emptyScopesAlias: promptConfig.emptyScopesAlias ?? defaultConfig.emptyScopesAlias,
3939
upperCaseSubject: promptConfig.upperCaseSubject ?? defaultConfig.upperCaseSubject,
40+
markBreakingChangeMode: promptConfig.markBreakingChangeMode ?? defaultConfig.markBreakingChangeMode,
4041
allowBreakingChanges: promptConfig.allowBreakingChanges ?? defaultConfig.allowBreakingChanges,
4142
breaklineNumber: getMaxLength(config?.rules?.["body-max-line-length"] as any) === Infinity
4243
? promptConfig.breaklineNumber ?? defaultConfig.breaklineNumber

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,22 @@ export const generateQuestions = (options: CommitizenGitOptions, cz: any) => {
165165
completeValue: options.defaultBody || undefined,
166166
transformer: (input: string) => useThemeCode(input, options.themeColorCode)
167167
},
168+
{
169+
type: "confirm",
170+
name: "markBreaking",
171+
message: options.messages?.markBreaking,
172+
default: false,
173+
when: () => options.markBreakingChangeMode === true
174+
},
168175
{
169176
type: "complete-input",
170177
name: "breaking",
171178
message: options.messages?.breaking,
172179
completeValue: options.defaultBody || undefined,
173180
when: (answers: Answers) => {
174-
if (
181+
if (options.markBreakingChangeMode === true) {
182+
return answers.markBreaking;
183+
} else if (
175184
options.allowBreakingChanges &&
176185
answers.type &&
177186
options.allowBreakingChanges.includes(answers.type)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export type Answers = {
4646
* @default:Provide a LONGER description of the change (optional). Use "|" to break new line:\n
4747
*/
4848
body?: string;
49+
/**
50+
* @default: Is any BREAKING CHANGE (add "!" in header) (optional) ?
51+
* @use need turn on options "markBreakingChangeMode"
52+
*/
53+
markBreaking?: string;
4954
/**
5055
* @default: List any BREAKING CHANGES (optional). Use "|" to break new line:\n
5156
*/
@@ -197,6 +202,13 @@ export interface CommitizenGitOptions {
197202
*/
198203
upperCaseSubject?: boolean;
199204

205+
/**
206+
* @description: Whether to add extra prompt BREAKCHANGE ask. to add an extra "!" to the header
207+
* @see: https://cz-git.qbenben.com/recipes/breakingchange
208+
* @default: false
209+
*/
210+
markBreakingChangeMode?: boolean;
211+
200212
/**
201213
* @description: Allow breaking changes in the included types output box
202214
* @default: ['feat', 'fix']
@@ -332,6 +344,7 @@ export const defaultConfig = Object.freeze({
332344
customScope: "Denote the SCOPE of this change:",
333345
subject: "Write a SHORT, IMPERATIVE tense description of the change:\n",
334346
body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',
347+
markBreaking: 'Is any BREAKING CHANGE (add "!" in header) (optional) ?',
335348
breaking: 'List any BREAKING CHANGES (optional). Use "|" to break new line:\n',
336349
footerPrefixsSelect: "Select the ISSUES type of change (optional):",
337350
customFooterPrefixs: "Input ISSUES prefix:",
@@ -363,6 +376,7 @@ export const defaultConfig = Object.freeze({
363376
customScopesAlias: "custom",
364377
emptyScopesAlias: "empty",
365378
upperCaseSubject: false,
379+
markBreakingChangeMode: false,
366380
allowBreakingChanges: ['feat', 'fix'],
367381
breaklineNumber: 100,
368382
breaklineChar: "|",

0 commit comments

Comments
 (0)