Skip to content

Commit 37bb75a

Browse files
authored
Merge branch 'master' into greenkeeper/initial
2 parents 0664ed0 + aae2548 commit 37bb75a

File tree

10 files changed

+13175
-65
lines changed

10 files changed

+13175
-65
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[*]
2+
end_of_line = lf
3+
charset = utf-8
4+
indent_size = 2
5+
indent_style = space
6+
insert_final_newline = true
7+
max_line_length = 80
8+
trim_trailing_whitespace = true

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 80,
3+
"endOfLine": "lf",
4+
"singleQuote": true
5+
}

.travis.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
sudo: false
21
language: node_js
3-
cache:
4-
directories:
5-
- node_modules
6-
notifications:
7-
email: false
2+
83
node_js:
9-
- '4'
10-
before_install:
11-
- npm i -g npm@^2.0.0
12-
before_script:
13-
- npm prune
14-
after_success:
15-
- npm run semantic-release
4+
- 12
5+
- 10
6+
7+
jobs:
8+
include:
9+
- stage: release
10+
node_js: lts/*
11+
deploy:
12+
provider: script
13+
skip_cleanup: true
14+
script:
15+
- npm run semantic-release
16+
1617
branches:
1718
only:
1819
- master

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2015-2018 Commitizen Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,52 @@ Status:
77
[![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)
88
[![Build Status](https://img.shields.io/travis/commitizen/cz-conventional-changelog.svg?style=flat-square)](https://travis-ci.org/commitizen/cz-conventional-changelog)
99

10-
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.
10+
Part of the [commitizen](https://github.com/commitizen/cz-cli) family. Prompts for [conventional changelog](https://github.com/conventional-changelog/conventional-changelog) standard.
11+
12+
## Configuration
13+
14+
### package.json
15+
16+
Like commitizen, you specify the configuration of cz-conventional-changelog through the package.json's `config.commitizen` key.
17+
18+
```json5
19+
{
20+
// ... default values
21+
"config": {
22+
"commitizen": {
23+
"path": "./node_modules/cz-conventional-changelog",
24+
"maxHeaderWidth": 100,
25+
"maxLineWidth": 100,
26+
"defaultType": "",
27+
"defaultScope": "",
28+
"defaultSubject": "",
29+
"defaultBody": "",
30+
"defaultIssues": "",
31+
"types": {
32+
...
33+
"feat": {
34+
"description": "A new feature",
35+
"title": "Features"
36+
},
37+
...
38+
}
39+
}
40+
}
41+
// ...
42+
}
43+
```
44+
### Environment variables
45+
46+
The following environment varibles can be used to override any default configuration or package.json based configuration.
47+
48+
* CZ_TYPE = defaultType
49+
* CZ_SCOPE = defaultScope
50+
* CZ_SUBJECT = defaultSubject
51+
* CZ_BODY = defaultBody
52+
* CZ_MAX_HEADER_WIDTH = maxHeaderWidth
53+
* CZ_MAX_LINE_WIDTH = maxLineWidth
54+
55+
### Commitlint
56+
57+
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.
58+

engine.js

Lines changed: 147 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
1-
"format cjs";
1+
'format cjs';
22

33
var wrap = require('word-wrap');
44
var map = require('lodash.map');
55
var longest = require('longest');
6-
var rightPad = require('right-pad');
6+
var chalk = require('chalk');
77

88
var filter = function(array) {
99
return array.filter(function(x) {
1010
return x;
1111
});
1212
};
1313

14+
var headerLength = function(answers) {
15+
return (
16+
answers.type.length + 2 + (answers.scope ? answers.scope.length + 2 : 0)
17+
);
18+
};
19+
20+
var maxSummaryLength = function(options, answers) {
21+
return options.maxHeaderWidth - headerLength(answers);
22+
};
23+
24+
var filterSubject = function(subject) {
25+
subject = subject.trim();
26+
if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
27+
subject =
28+
subject.charAt(0).toLowerCase() + subject.slice(1, subject.length);
29+
}
30+
while (subject.endsWith('.')) {
31+
subject = subject.slice(0, subject.length - 1);
32+
}
33+
return subject;
34+
};
35+
1436
// This can be any kind of SystemJS compatible module.
1537
// We use Commonjs here, but ES6 or AMD would do just
1638
// fine.
17-
module.exports = function (options) {
18-
39+
module.exports = function(options) {
1940
var types = options.types;
2041

2142
var length = longest(Object.keys(types)).length + 1;
22-
var choices = map(types, function (type, key) {
43+
var choices = map(types, function(type, key) {
2344
return {
24-
name: rightPad(key + ':', length) + ' ' + type.description,
45+
name: (key + ':').padEnd(length) + ' ' + type.description,
2546
value: key
2647
};
2748
});
@@ -39,8 +60,6 @@ module.exports = function (options) {
3960
// By default, we'll de-indent your commit
4061
// template and will keep empty lines.
4162
prompter: function(cz, commit) {
42-
console.log('\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n');
43-
4463
// Let's ask some questions of the user
4564
// so that we can populate our commit
4665
// template.
@@ -52,60 +71,150 @@ module.exports = function (options) {
5271
{
5372
type: 'list',
5473
name: 'type',
55-
message: 'Select the type of change that you\'re committing:',
56-
choices: choices
57-
}, {
74+
message: "Select the type of change that you're committing:",
75+
choices: choices,
76+
default: options.defaultType
77+
},
78+
{
5879
type: 'input',
5980
name: 'scope',
60-
message: 'Denote the scope of this change ($location, $browser, $compile, etc.):\n'
61-
}, {
81+
message:
82+
'What is the scope of this change (e.g. component or file name): (press enter to skip)',
83+
default: options.defaultScope,
84+
filter: function(value) {
85+
return options.disableScopeLowerCase
86+
? value.trim()
87+
: value.trim().toLowerCase();
88+
}
89+
},
90+
{
6291
type: 'input',
6392
name: 'subject',
64-
message: 'Write a short, imperative tense description of the change:\n'
65-
}, {
93+
message: function(answers) {
94+
return (
95+
'Write a short, imperative tense description of the change (max ' +
96+
maxSummaryLength(options, answers) +
97+
' chars):\n'
98+
);
99+
},
100+
default: options.defaultSubject,
101+
validate: function(subject, answers) {
102+
var filteredSubject = filterSubject(subject);
103+
return filteredSubject.length == 0
104+
? 'subject is required'
105+
: filteredSubject.length <= maxSummaryLength(options, answers)
106+
? true
107+
: 'Subject length must be less than or equal to ' +
108+
maxSummaryLength(options, answers) +
109+
' characters. Current length is ' +
110+
filteredSubject.length +
111+
' characters.';
112+
},
113+
transformer: function(subject, answers) {
114+
var filteredSubject = filterSubject(subject);
115+
var color =
116+
filteredSubject.length <= maxSummaryLength(options, answers)
117+
? chalk.green
118+
: chalk.red;
119+
return color('(' + filteredSubject.length + ') ' + subject);
120+
},
121+
filter: function(subject) {
122+
return filterSubject(subject);
123+
}
124+
},
125+
{
66126
type: 'input',
67127
name: 'body',
68-
message: 'Provide a longer description of the change:\n'
69-
}, {
128+
message:
129+
'Provide a longer description of the change: (press enter to skip)\n',
130+
default: options.defaultBody
131+
},
132+
{
133+
type: 'confirm',
134+
name: 'isBreaking',
135+
message: 'Are there any breaking changes?',
136+
default: false
137+
},
138+
{
139+
type: 'input',
140+
name: 'breakingBody',
141+
default: '-',
142+
message:
143+
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n',
144+
when: function(answers) {
145+
return answers.isBreaking && !answers.body;
146+
},
147+
validate: function(breakingBody, answers) {
148+
return (
149+
breakingBody.trim().length > 0 ||
150+
'Body is required for BREAKING CHANGE'
151+
);
152+
}
153+
},
154+
{
70155
type: 'input',
71156
name: 'breaking',
72-
message: 'List any breaking changes:\n'
73-
}, {
157+
message: 'Describe the breaking changes:\n',
158+
when: function(answers) {
159+
return answers.isBreaking;
160+
}
161+
},
162+
163+
{
164+
type: 'confirm',
165+
name: 'isIssueAffected',
166+
message: 'Does this change affect any open issues?',
167+
default: options.defaultIssues ? true : false
168+
},
169+
{
170+
type: 'input',
171+
name: 'issuesBody',
172+
default: '-',
173+
message:
174+
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n',
175+
when: function(answers) {
176+
return (
177+
answers.isIssueAffected && !answers.body && !answers.breakingBody
178+
);
179+
}
180+
},
181+
{
74182
type: 'input',
75183
name: 'issues',
76-
message: 'List any issues closed by this change:\n'
184+
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
185+
when: function(answers) {
186+
return answers.isIssueAffected;
187+
},
188+
default: options.defaultIssues ? options.defaultIssues : undefined
77189
}
78190
]).then(function(answers) {
79-
80-
var maxLineWidth = 100;
81-
82191
var wrapOptions = {
83192
trim: true,
193+
cut: false,
84194
newline: '\n',
85-
indent:'',
86-
width: maxLineWidth
195+
indent: '',
196+
width: options.maxLineWidth
87197
};
88198

89199
// parentheses are only needed when a scope is present
90-
var scope = answers.scope.trim();
91-
scope = scope ? '(' + answers.scope.trim() + ')' : '';
200+
var scope = answers.scope ? '(' + answers.scope + ')' : '';
92201

93-
// Hard limit this line
94-
var head = (answers.type + scope + ': ' + answers.subject.trim()).slice(0, maxLineWidth);
202+
// Hard limit this line in the validate
203+
var head = answers.type + scope + ': ' + answers.subject;
95204

96-
// Wrap these lines at 100 characters
97-
var body = wrap(answers.body, wrapOptions);
205+
// Wrap these lines at options.maxLineWidth characters
206+
var body = answers.body ? wrap(answers.body, wrapOptions) : false;
98207

99208
// Apply breaking change prefix, removing it if already present
100-
var breaking = answers.breaking.trim();
101-
breaking = breaking ? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '') : '';
102-
breaking = wrap(breaking, wrapOptions);
103-
104-
var issues = wrap(answers.issues, wrapOptions);
209+
var breaking = answers.breaking ? answers.breaking.trim() : '';
210+
breaking = breaking
211+
? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '')
212+
: '';
213+
breaking = breaking ? wrap(breaking, wrapOptions) : false;
105214

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

108-
commit(head + '\n\n' + body + '\n\n' + footer);
217+
commit(filter([head, body, breaking, issues]).join('\n\n'));
109218
});
110219
}
111220
};

0 commit comments

Comments
 (0)