diff --git a/README.md b/README.md index 26271a6..b5dd989 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,8 @@ Here are the options you can set in your `.cz-config.js`: * **breakingPrefix**: {string, default 'BREAKING CHANGE:'}: Set a custom prefix for the breaking change block in commit messages. * **footerPrefix**: {string, default 'ISSUES CLOSED:'}: Set a custom prefix for the footer block in commit messages. Set to empty string to remove prefix. * **breaklineChar**: {string, default '|'}: It gets replaced with \n to create the breakline in your commit message. This is supported for fields `body` and `footer` at the moment. -* **upperCaseSubject**: { boolean, default false }: Capitalizes first subject letter if set to `true` +* **upperCaseSubject**: { boolean, default false }: Capitalizes first subject letter if set to `true` +* **askForBreakingChangeFirst**: { boolean, default false }: It asks for breaking change as first question when set to `true` ## Related tools - (https://github.com/commitizen/cz-cli) diff --git a/cz-config-EXAMPLE.js b/cz-config-EXAMPLE.js index 7b5fb33..245e40a 100644 --- a/cz-config-EXAMPLE.js +++ b/cz-config-EXAMPLE.js @@ -66,5 +66,6 @@ module.exports = { // limit subject length subjectLimit: 100, // breaklineChar: '|', // It is supported for fields body and footer. - // footerPrefix : 'ISSUES CLOSED:', // default value + // footerPrefix : 'ISSUES CLOSED:' + // askForBreakingChangeFirst : true, // default is false }; diff --git a/questions.js b/questions.js index ec39764..1d5d830 100644 --- a/questions.js +++ b/questions.js @@ -1,3 +1,4 @@ +const _ = require('lodash'); const buildCommit = require('./buildCommit'); const log = require('./logger'); @@ -133,7 +134,10 @@ module.exports = { message: messages.breaking, when(answers) { // eslint-disable-next-line max-len - if (config.allowBreakingChanges && config.allowBreakingChanges.indexOf(answers.type.toLowerCase()) >= 0) { + if ( + config.askForBreakingChangeFirst || + (config.allowBreakingChanges && config.allowBreakingChanges.indexOf(answers.type.toLowerCase()) >= 0) + ) { return true; } return false; // no breaking changes allowed unless specifed @@ -164,6 +168,15 @@ module.exports = { questions = questions.filter(item => !skipQuestions.includes(item.name)); + if (config.askForBreakingChangeFirst) { + const isBreaking = oneQuestion => oneQuestion.name === 'breaking'; + + const breakingQuestion = _.filter(questions, isBreaking); + const questionWithoutBreaking = _.reject(questions, isBreaking); + + questions = _.concat(breakingQuestion, questionWithoutBreaking); + } + return questions; }, }; diff --git a/spec/questionsSpec.js b/spec/questionsSpec.js index d05bd38..7244f5d 100644 --- a/spec/questionsSpec.js +++ b/spec/questionsSpec.js @@ -183,12 +183,23 @@ describe('cz-customizable', () => { allowTicketNumber: false, }; - // question 4 with expect(getQuestion(4).name).toEqual('ticketNumber'); expect(getQuestion(4).when()).toEqual(false); }); }); + describe('ask for breaking change first', () => { + it('when config askForBreakingChangeFirst is true', () => { + config = { + types: [{ value: 'feat', name: 'feat: my feat' }], + askForBreakingChangeFirst: true, + }; + + expect(getQuestion(1).name).toEqual('breaking'); + expect(getQuestion(1).when()).toEqual(true); + }); + }); + describe('TicketNumber', () => { it('disable TicketNumber question', () => { config = { @@ -196,7 +207,6 @@ describe('cz-customizable', () => { allowTicketNumber: false, }; - // question 4 with expect(getQuestion(4).name).toEqual('ticketNumber'); expect(getQuestion(4).when()).toEqual(false); }); @@ -210,7 +220,6 @@ describe('cz-customizable', () => { }, }; - // question 4 with expect(getQuestion(4).name).toEqual('ticketNumber'); expect(getQuestion(4).message).toEqual('ticket number'); });