cz-conventional-changelog
Advanced tools
Comparing version 2.1.0 to 3.0.0
166
engine.js
@@ -1,2 +0,2 @@ | ||
"format cjs"; | ||
'format cjs'; | ||
@@ -7,2 +7,3 @@ var wrap = require('word-wrap'); | ||
var rightPad = require('right-pad'); | ||
var chalk = require('chalk'); | ||
@@ -15,11 +16,32 @@ var filter = function(array) { | ||
var headerLength = function(answers) { | ||
return ( | ||
answers.type.length + 2 + (answers.scope ? answers.scope.length + 2 : 0) | ||
); | ||
}; | ||
var maxSummaryLength = function(options, answers) { | ||
return options.maxHeaderWidth - headerLength(answers); | ||
}; | ||
var filterSubject = function(subject) { | ||
subject = subject.trim(); | ||
if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) { | ||
subject = | ||
subject.charAt(0).toLowerCase() + subject.slice(1, subject.length); | ||
} | ||
while (subject.endsWith('.')) { | ||
subject = subject.slice(0, subject.length - 1); | ||
} | ||
return subject; | ||
}; | ||
// This can be any kind of SystemJS compatible module. | ||
// We use Commonjs here, but ES6 or AMD would do just | ||
// fine. | ||
module.exports = function (options) { | ||
module.exports = function(options) { | ||
var types = options.types; | ||
var length = longest(Object.keys(types)).length + 1; | ||
var choices = map(types, function (type, key) { | ||
var choices = map(types, function(type, key) { | ||
return { | ||
@@ -44,4 +66,2 @@ name: rightPad(key + ':', length) + ' ' + type.description, | ||
prompter: function(cz, commit) { | ||
console.log('\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n'); | ||
// Let's ask some questions of the user | ||
@@ -58,17 +78,59 @@ // so that we can populate our commit | ||
name: 'type', | ||
message: 'Select the type of change that you\'re committing:', | ||
choices: choices | ||
}, { | ||
message: "Select the type of change that you're committing:", | ||
choices: choices, | ||
default: options.defaultType | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'scope', | ||
message: 'What is the scope of this change (e.g. component or file name)? (press enter to skip)\n' | ||
}, { | ||
message: | ||
'What is the scope of this change (e.g. component or file name): (press enter to skip)', | ||
default: options.defaultScope, | ||
filter: function(value) { | ||
return value.trim().toLowerCase(); | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'subject', | ||
message: 'Write a short, imperative tense description of the change:\n' | ||
}, { | ||
message: function(answers) { | ||
return ( | ||
'Write a short, imperative tense description of the change (max ' + | ||
maxSummaryLength(options, answers) + | ||
' chars):\n' | ||
); | ||
}, | ||
default: options.defaultSubject, | ||
validate: function(subject, answers) { | ||
var filteredSubject = filterSubject(subject); | ||
return filteredSubject.length == 0 | ||
? 'subject is required' | ||
: filteredSubject.length <= maxSummaryLength(options, answers) | ||
? true | ||
: 'Subject length must be less than or equal to ' + | ||
maxSummaryLength(options, answers) + | ||
' characters. Current length is ' + | ||
filteredSubject.length + | ||
' characters.'; | ||
}, | ||
transformer: function(subject, answers) { | ||
var filteredSubject = filterSubject(subject); | ||
var color = | ||
filteredSubject.length <= maxSummaryLength(options, answers) | ||
? chalk.green | ||
: chalk.red; | ||
return color('(' + filteredSubject.length + ') ' + subject); | ||
}, | ||
filter: function(subject) { | ||
return filterSubject(subject); | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'body', | ||
message: 'Provide a longer description of the change: (press enter to skip)\n' | ||
}, { | ||
message: | ||
'Provide a longer description of the change: (press enter to skip)\n', | ||
default: options.defaultBody | ||
}, | ||
{ | ||
type: 'confirm', | ||
@@ -78,4 +140,21 @@ name: 'isBreaking', | ||
default: false | ||
}, { | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'breakingBody', | ||
default: '-', | ||
message: | ||
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n', | ||
when: function(answers) { | ||
return answers.isBreaking && !answers.body; | ||
}, | ||
validate: function(breakingBody, answers) { | ||
return ( | ||
breakingBody.trim().length > 0 || | ||
'Body is required for BREAKING CHANGE' | ||
); | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'breaking', | ||
@@ -86,9 +165,24 @@ message: 'Describe the breaking changes:\n', | ||
} | ||
}, { | ||
}, | ||
{ | ||
type: 'confirm', | ||
name: 'isIssueAffected', | ||
message: 'Does this change affect any open issues?', | ||
default: false | ||
}, { | ||
default: options.defaultIssues ? true : false | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'issuesBody', | ||
default: '-', | ||
message: | ||
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n', | ||
when: function(answers) { | ||
return ( | ||
answers.isIssueAffected && !answers.body && !answers.breakingBody | ||
); | ||
} | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'issues', | ||
@@ -98,35 +192,33 @@ message: 'Add issue references (e.g. "fix #123", "re #123".):\n', | ||
return answers.isIssueAffected; | ||
} | ||
}, | ||
default: options.defaultIssues ? options.defaultIssues : undefined | ||
} | ||
]).then(function(answers) { | ||
var maxLineWidth = 100; | ||
var wrapOptions = { | ||
trim: true, | ||
cut: false, | ||
newline: '\n', | ||
indent:'', | ||
width: maxLineWidth | ||
indent: '', | ||
width: options.maxLineWidth | ||
}; | ||
// parentheses are only needed when a scope is present | ||
var scope = answers.scope.trim(); | ||
scope = scope ? '(' + answers.scope.trim() + ')' : ''; | ||
var scope = answers.scope ? '(' + answers.scope + ')' : ''; | ||
// Hard limit this line | ||
var head = (answers.type + scope + ': ' + answers.subject.trim()).slice(0, maxLineWidth); | ||
// Hard limit this line in the validate | ||
var head = answers.type + scope + ': ' + answers.subject; | ||
// Wrap these lines at 100 characters | ||
var body = wrap(answers.body, wrapOptions); | ||
// Wrap these lines at options.maxLineWidth characters | ||
var body = answers.body ? wrap(answers.body, wrapOptions) : false; | ||
// Apply breaking change prefix, removing it if already present | ||
var breaking = answers.breaking ? answers.breaking.trim() : ''; | ||
breaking = breaking ? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '') : ''; | ||
breaking = wrap(breaking, wrapOptions); | ||
breaking = breaking | ||
? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '') | ||
: ''; | ||
breaking = breaking ? wrap(breaking, wrapOptions) : false; | ||
var issues = answers.issues ? wrap(answers.issues, wrapOptions) : ''; | ||
var issues = answers.issues ? wrap(answers.issues, wrapOptions) : false; | ||
var footer = filter([ breaking, issues ]).join('\n\n'); | ||
commit(head + '\n\n' + body + '\n\n' + footer); | ||
commit(filter([head, body, breaking, issues]).join('\n\n')); | ||
}); | ||
@@ -133,0 +225,0 @@ } |
46
index.js
@@ -1,8 +0,46 @@ | ||
"format cjs"; | ||
'format cjs'; | ||
var engine = require('./engine'); | ||
var conventionalCommitTypes = require('conventional-commit-types'); | ||
var configLoader = require('commitizen').configLoader; | ||
module.exports = engine({ | ||
types: conventionalCommitTypes.types | ||
}); | ||
var config = configLoader.load(); | ||
var options = { | ||
types: conventionalCommitTypes.types, | ||
defaultType: process.env.CZ_TYPE || config.defaultType, | ||
defaultScope: process.env.CZ_SCOPE || config.defaultScope, | ||
defaultSubject: process.env.CZ_SUBJECT || config.defaultSubject, | ||
defaultBody: process.env.CZ_BODY || config.defaultBody, | ||
defaultIssues: process.env.CZ_ISSUES || config.defaultIssues, | ||
maxHeaderWidth: | ||
(process.env.CZ_MAX_HEADER_WIDTH && | ||
parseInt(process.env.CZ_MAX_HEADER_WIDTH)) || | ||
config.maxHeaderWidth || | ||
100, | ||
maxLineWidth: | ||
(process.env.CZ_MAX_LINE_WIDTH && | ||
parseInt(process.env.CZ_MAX_LINE_WIDTH)) || | ||
config.maxLineWidth || | ||
100 | ||
}; | ||
(function(options) { | ||
try { | ||
var commitlintLoad = require('@commitlint/load'); | ||
commitlintLoad().then(function(clConfig) { | ||
if (clConfig.rules) { | ||
var maxHeaderLengthRule = clConfig.rules['header-max-length']; | ||
if ( | ||
typeof maxHeaderLengthRule === 'object' && | ||
maxHeaderLengthRule.length >= 3 && | ||
!process.env.CZ_MAX_HEADER_WIDTH && | ||
!config.maxHeaderWidth | ||
) { | ||
options.maxHeaderWidth = maxHeaderLengthRule[2]; | ||
} | ||
} | ||
}); | ||
} catch (err) {} | ||
})(options); | ||
module.exports = engine(options); |
{ | ||
"name": "cz-conventional-changelog", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Commitizen adapter following the conventional-changelog format.", | ||
@@ -8,4 +8,5 @@ "main": "index.js", | ||
"commit": "git-cz", | ||
"test": "echo 'Tests need to be setup!'", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
"test": "mocha *.test.js", | ||
"format": "prettier --write *.js", | ||
"semantic-release": "semantic-release" | ||
}, | ||
@@ -17,5 +18,10 @@ "homepage": "https://github.com/commitizen/cz-conventional-changelog", | ||
}, | ||
"engineStrict": true, | ||
"engines": { | ||
"node": ">= 10" | ||
}, | ||
"author": "Jim Cummins <jimthedev@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"chalk": "^2.4.1", | ||
"conventional-commit-types": "^2.0.0", | ||
@@ -28,5 +34,16 @@ "lodash.map": "^4.5.1", | ||
"devDependencies": { | ||
"commitizen": "2.9.6", | ||
"semantic-release": "^6.3.2" | ||
"@types/chai": "^4.1.7", | ||
"@types/mocha": "^5.2.7", | ||
"chai": "^4.2.0", | ||
"commitizen": "^4.0.2", | ||
"cosmiconfig": "^5.2.1", | ||
"mocha": "^6.2.0", | ||
"mock-require": "^3.0.3", | ||
"prettier": "^1.15.3", | ||
"semantic-release": "^15.13.3", | ||
"semver": "^6.2.0" | ||
}, | ||
"optionalDependencies": { | ||
"@commitlint/load": ">6.1.1" | ||
}, | ||
"config": { | ||
@@ -37,2 +54,2 @@ "commitizen": { | ||
} | ||
} | ||
} |
@@ -8,2 +8,42 @@ # cz-conventional-changelog | ||
Part of the [commitizen](https://github.com/commitizen/cz-cli) family. Prompts for [conventional changelog](https://github.com/stevemao/conventional-changelog-angular/blob/master/index.js) standard. | ||
Part of the [commitizen](https://github.com/commitizen/cz-cli) family. Prompts for [conventional changelog](https://github.com/conventional-changelog/conventional-changelog) standard. | ||
## Configuration | ||
### package.json | ||
Like commitizen, you specify the configuration of cz-conventional-changelog through the package.json's `config.commitizen` key. | ||
```json5 | ||
{ | ||
// ... default values | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog", | ||
"maxHeaderWidth": 100, | ||
"maxLineWidth": 100, | ||
"defaultType": "", | ||
"defaultScope": "", | ||
"defaultSubject": "", | ||
"defaultBody": "", | ||
"defaultIssues": "" | ||
} | ||
} | ||
// ... | ||
} | ||
``` | ||
### Environment variables | ||
The following environment varibles can be used to override any default configuration or package.json based configuration. | ||
* CZ_TYPE = defaultType | ||
* CZ_SCOPE = defaultScope | ||
* CZ_SUBJECT = defaultSubject | ||
* CZ_BODY = defaultBody | ||
* CZ_MAX_HEADER_WIDTH = maxHeaderWidth | ||
* CZ_MAX_LINE_WIDTH = maxLineWidth | ||
### 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. | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 7 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28189
9
775
49
7
10
12
1
+ Addedchalk@^2.4.1
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@commitlint/config-validator@19.5.0(transitive)
+ Added@commitlint/execute-rule@19.5.0(transitive)
+ Added@commitlint/load@19.5.0(transitive)
+ Added@commitlint/resolve-extends@19.5.0(transitive)
+ Added@commitlint/types@19.5.0(transitive)
+ Added@types/conventional-commits-parser@5.0.0(transitive)
+ Added@types/node@22.9.0(transitive)
+ Addedajv@8.17.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedargparse@2.0.1(transitive)
+ Addedcallsites@3.1.0(transitive)
+ Addedchalk@2.4.25.3.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcosmiconfig@9.0.0(transitive)
+ Addedcosmiconfig-typescript-loader@5.1.0(transitive)
+ Addedenv-paths@2.2.1(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-uri@3.0.3(transitive)
+ Addedglobal-directory@4.0.1(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedimport-fresh@3.3.0(transitive)
+ Addedimport-meta-resolve@4.1.0(transitive)
+ Addedini@4.1.1(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedjiti@1.21.6(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedjson-parse-even-better-errors@2.3.1(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedlines-and-columns@1.2.4(transitive)
+ Addedlodash.isplainobject@4.0.6(transitive)
+ Addedlodash.merge@4.6.2(transitive)
+ Addedlodash.mergewith@4.6.2(transitive)
+ Addedlodash.uniq@4.5.0(transitive)
+ Addedparent-module@1.0.1(transitive)
+ Addedparse-json@5.2.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addedresolve-from@4.0.05.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedtypescript@5.6.3(transitive)
+ Addedundici-types@6.19.8(transitive)