Skip to content

Commit

Permalink
Merge branch 'master' into greenkeeper/initial
Browse files Browse the repository at this point in the history
  • Loading branch information
dmwelch committed Aug 24, 2020
2 parents 0664ed0 + aae2548 commit 37bb75a
Show file tree
Hide file tree
Showing 10 changed files with 13,175 additions and 65 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*]
end_of_line = lf
charset = utf-8
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 80,
"endOfLine": "lf",
"singleQuote": true
}
27 changes: 14 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false

node_js:
- '4'
before_install:
- npm i -g npm@^2.0.0
before_script:
- npm prune
after_success:
- npm run semantic-release
- 12
- 10

jobs:
include:
- stage: release
node_js: lts/*
deploy:
provider: script
skip_cleanup: true
script:
- npm run semantic-release

branches:
only:
- master
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2015-2018 Commitizen Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,52 @@ Status:
[![npm downloads](https://img.shields.io/npm/dm/cz-conventional-changelog.svg?style=flat-square)](http://npm-stat.com/charts.html?package=cz-conventional-changelog&from=2015-08-01)
[![Build Status](https://img.shields.io/travis/commitizen/cz-conventional-changelog.svg?style=flat-square)](https://travis-ci.org/commitizen/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": "",
"types": {
...
"feat": {
"description": "A new feature",
"title": "Features"
},
...
}
}
}
// ...
}
```
### 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.

185 changes: 147 additions & 38 deletions engine.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
"format cjs";
'format cjs';

var wrap = require('word-wrap');
var map = require('lodash.map');
var longest = require('longest');
var rightPad = require('right-pad');
var chalk = require('chalk');

var filter = function(array) {
return array.filter(function(x) {
return x;
});
};

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 {
name: rightPad(key + ':', length) + ' ' + type.description,
name: (key + ':').padEnd(length) + ' ' + type.description,
value: key
};
});
Expand All @@ -39,8 +60,6 @@ module.exports = function (options) {
// By default, we'll de-indent your commit
// template and will keep empty lines.
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
// so that we can populate our commit
// template.
Expand All @@ -52,60 +71,150 @@ module.exports = function (options) {
{
type: 'list',
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: 'Denote the scope of this change ($location, $browser, $compile, etc.):\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 options.disableScopeLowerCase
? value.trim()
: 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:\n'
}, {
message:
'Provide a longer description of the change: (press enter to skip)\n',
default: options.defaultBody
},
{
type: 'confirm',
name: 'isBreaking',
message: 'Are there any breaking changes?',
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',
message: 'List any breaking changes:\n'
}, {
message: 'Describe the breaking changes:\n',
when: function(answers) {
return answers.isBreaking;
}
},

{
type: 'confirm',
name: 'isIssueAffected',
message: 'Does this change affect any open issues?',
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',
message: 'List any issues closed by this change:\n'
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
when: function(answers) {
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.trim();
breaking = breaking ? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '') : '';
breaking = wrap(breaking, wrapOptions);

var issues = wrap(answers.issues, wrapOptions);
var breaking = answers.breaking ? answers.breaking.trim() : '';
breaking = breaking
? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '')
: '';
breaking = breaking ? wrap(breaking, wrapOptions) : false;

var footer = filter([ breaking, issues ]).join('\n\n');
var issues = answers.issues ? wrap(answers.issues, wrapOptions) : false;

commit(head + '\n\n' + body + '\n\n' + footer);
commit(filter([head, body, breaking, issues]).join('\n\n'));
});
}
};
Expand Down

0 comments on commit 37bb75a

Please sign in to comment.