From df66875dc0a8be1c17abb7ab7d66b0f55f4e9ddb Mon Sep 17 00:00:00 2001 From: Zoffy Zhang Date: Fri, 31 Jul 2020 19:05:40 +0800 Subject: [PATCH] feat(engine): add support for disableSubjectLowerCase --- README.md | 4 +++- engine.js | 10 +++++----- engine.test.js | 20 ++++++++++++++++++++ index.js | 2 ++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b59d9c90..3659d643 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro "config": { "commitizen": { "path": "./node_modules/cz-conventional-changelog", + "disableScopeLowerCase": false, + "disableSubjectLowerCase": false, "maxHeaderWidth": 100, "maxLineWidth": 100, "defaultType": "", @@ -39,6 +41,7 @@ Like commitizen, you specify the configuration of cz-conventional-changelog thro // ... } ``` + ### Environment variables The following environment varibles can be used to override any default configuration or package.json based configuration. @@ -53,4 +56,3 @@ The following environment varibles can be used to override any default configura ### Commitlint If using the [commitlint](https://github.com/conventional-changelog/commitlint) js library, the "maxHeaderWidth" configuration property will default to the configuration of the "header-max-length" rule instead of the hard coded value of 100. This can be ovewritten by setting the 'maxHeaderWidth' configuration in package.json or the CZ_MAX_HEADER_WIDTH environment variable. - diff --git a/engine.js b/engine.js index 75dac053..24a42b7c 100644 --- a/engine.js +++ b/engine.js @@ -21,9 +21,9 @@ var maxSummaryLength = function(options, answers) { return options.maxHeaderWidth - headerLength(answers); }; -var filterSubject = function(subject) { +var filterSubject = function(subject, disableSubjectLowerCase) { subject = subject.trim(); - if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) { + if (!disableSubjectLowerCase && subject.charAt(0).toLowerCase() !== subject.charAt(0)) { subject = subject.charAt(0).toLowerCase() + subject.slice(1, subject.length); } @@ -99,7 +99,7 @@ module.exports = function(options) { }, default: options.defaultSubject, validate: function(subject, answers) { - var filteredSubject = filterSubject(subject); + var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase); return filteredSubject.length == 0 ? 'subject is required' : filteredSubject.length <= maxSummaryLength(options, answers) @@ -111,7 +111,7 @@ module.exports = function(options) { ' characters.'; }, transformer: function(subject, answers) { - var filteredSubject = filterSubject(subject); + var filteredSubject = filterSubject(subject, options.disableSubjectLowerCase); var color = filteredSubject.length <= maxSummaryLength(options, answers) ? chalk.green @@ -119,7 +119,7 @@ module.exports = function(options) { return color('(' + filteredSubject.length + ') ' + subject); }, filter: function(subject) { - return filterSubject(subject); + return filterSubject(subject, options.disableSubjectLowerCase); } }, { diff --git a/engine.test.js b/engine.test.js index 4a42becd..aacd134f 100644 --- a/engine.test.js +++ b/engine.test.js @@ -101,6 +101,23 @@ describe('commit message', function() { ) ).to.equal(`${type}(${upperCaseScope}): ${subject}\n\n${body}`); }); + it('header and body w/ uppercase subject', function() { + var upperCaseSubject = subject.toLocaleUpperCase(); + expect( + commitMessage( + { + type, + scope, + subject: upperCaseSubject, + body + }, + { + ...defaultOptions, + disableSubjectLowerCase: true + } + ) + ).to.equal(`${type}(${scope}): ${upperCaseSubject}\n\n${body}`); + }); it('header, body and issues w/ out scope', function() { expect( commitMessage({ @@ -317,6 +334,9 @@ describe('defaults', function() { it('disableScopeLowerCase default', function() { expect(questionDefault('disableScopeLowerCase')).to.be.undefined; }); + it('disableSubjectLowerCase default', function() { + expect(questionDefault('disableSubjectLowerCase')).to.be.undefined; + }); }); describe('prompts', function() { diff --git a/index.js b/index.js index d86155bc..7a4586d2 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,8 @@ var options = { defaultIssues: process.env.CZ_ISSUES || config.defaultIssues, disableScopeLowerCase: process.env.DISABLE_SCOPE_LOWERCASE || config.disableScopeLowerCase, + disableSubjectLowerCase: + process.env.DISABLE_SUBJECT_LOWERCASE || config.disableSubjectLowerCase, maxHeaderWidth: (process.env.CZ_MAX_HEADER_WIDTH && parseInt(process.env.CZ_MAX_HEADER_WIDTH)) ||