cz-conventional-changelog 2.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -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
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "printWidth": 80,
3
+ "endOfLine": "lf",
4
+ "singleQuote": true
5
+ }
package/.travis.yml CHANGED
@@ -1,18 +1,19 @@
1
- sudo: false
2
1
  language: node_js
3
- cache:
4
- directories:
5
- - node_modules
6
- notifications:
7
- email: false
2
+
8
3
  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
+
16
17
  branches:
17
18
  only:
18
19
  - master
package/LICENSE ADDED
@@ -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.
package/README.md CHANGED
@@ -5,4 +5,44 @@ Status:
5
5
  [![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)
6
6
  [![Build Status](https://img.shields.io/travis/commitizen/cz-conventional-changelog.svg?style=flat-square)](https://travis-ci.org/commitizen/cz-conventional-changelog)
7
7
 
8
- 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.
8
+ Part of the [commitizen](https://github.com/commitizen/cz-cli) family. Prompts for [conventional changelog](https://github.com/conventional-changelog/conventional-changelog) standard.
9
+
10
+ ## Configuration
11
+
12
+ ### package.json
13
+
14
+ Like commitizen, you specify the configuration of cz-conventional-changelog through the package.json's `config.commitizen` key.
15
+
16
+ ```json5
17
+ {
18
+ // ... default values
19
+ "config": {
20
+ "commitizen": {
21
+ "path": "./node_modules/cz-conventional-changelog",
22
+ "maxHeaderWidth": 100,
23
+ "maxLineWidth": 100,
24
+ "defaultType": "",
25
+ "defaultScope": "",
26
+ "defaultSubject": "",
27
+ "defaultBody": "",
28
+ "defaultIssues": ""
29
+ }
30
+ }
31
+ // ...
32
+ }
33
+ ```
34
+ ### Environment variables
35
+
36
+ The following environment varibles can be used to override any default configuration or package.json based configuration.
37
+
38
+ * CZ_TYPE = defaultType
39
+ * CZ_SCOPE = defaultScope
40
+ * CZ_SUBJECT = defaultSubject
41
+ * CZ_BODY = defaultBody
42
+ * CZ_MAX_HEADER_WIDTH = maxHeaderWidth
43
+ * CZ_MAX_LINE_WIDTH = maxLineWidth
44
+
45
+ ### Commitlint
46
+
47
+ 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.
48
+
package/engine.js CHANGED
@@ -1,9 +1,10 @@
1
- "format cjs";
1
+ 'format cjs';
2
2
 
3
3
  var wrap = require('word-wrap');
4
4
  var map = require('lodash.map');
5
5
  var longest = require('longest');
6
6
  var rightPad = require('right-pad');
7
+ var chalk = require('chalk');
7
8
 
8
9
  var filter = function(array) {
9
10
  return array.filter(function(x) {
@@ -11,15 +12,36 @@ var filter = function(array) {
11
12
  });
12
13
  };
13
14
 
15
+ var headerLength = function(answers) {
16
+ return (
17
+ answers.type.length + 2 + (answers.scope ? answers.scope.length + 2 : 0)
18
+ );
19
+ };
20
+
21
+ var maxSummaryLength = function(options, answers) {
22
+ return options.maxHeaderWidth - headerLength(answers);
23
+ };
24
+
25
+ var filterSubject = function(subject) {
26
+ subject = subject.trim();
27
+ if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
28
+ subject =
29
+ subject.charAt(0).toLowerCase() + subject.slice(1, subject.length);
30
+ }
31
+ while (subject.endsWith('.')) {
32
+ subject = subject.slice(0, subject.length - 1);
33
+ }
34
+ return subject;
35
+ };
36
+
14
37
  // This can be any kind of SystemJS compatible module.
15
38
  // We use Commonjs here, but ES6 or AMD would do just
16
39
  // fine.
17
- module.exports = function (options) {
18
-
40
+ module.exports = function(options) {
19
41
  var types = options.types;
20
42
 
21
43
  var length = longest(Object.keys(types)).length + 1;
22
- var choices = map(types, function (type, key) {
44
+ var choices = map(types, function(type, key) {
23
45
  return {
24
46
  name: rightPad(key + ':', length) + ' ' + type.description,
25
47
  value: key
@@ -39,8 +61,6 @@ module.exports = function (options) {
39
61
  // By default, we'll de-indent your commit
40
62
  // template and will keep empty lines.
41
63
  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
-
44
64
  // Let's ask some questions of the user
45
65
  // so that we can populate our commit
46
66
  // template.
@@ -52,60 +72,148 @@ module.exports = function (options) {
52
72
  {
53
73
  type: 'list',
54
74
  name: 'type',
55
- message: 'Select the type of change that you\'re committing:',
56
- choices: choices
57
- }, {
75
+ message: "Select the type of change that you're committing:",
76
+ choices: choices,
77
+ default: options.defaultType
78
+ },
79
+ {
58
80
  type: 'input',
59
81
  name: 'scope',
60
- message: 'Denote the scope of this change ($location, $browser, $compile, etc.):\n'
61
- }, {
82
+ message:
83
+ 'What is the scope of this change (e.g. component or file name): (press enter to skip)',
84
+ default: options.defaultScope,
85
+ filter: function(value) {
86
+ return value.trim().toLowerCase();
87
+ }
88
+ },
89
+ {
62
90
  type: 'input',
63
91
  name: 'subject',
64
- message: 'Write a short, imperative tense description of the change:\n'
65
- }, {
92
+ message: function(answers) {
93
+ return (
94
+ 'Write a short, imperative tense description of the change (max ' +
95
+ maxSummaryLength(options, answers) +
96
+ ' chars):\n'
97
+ );
98
+ },
99
+ default: options.defaultSubject,
100
+ validate: function(subject, answers) {
101
+ var filteredSubject = filterSubject(subject);
102
+ return filteredSubject.length == 0
103
+ ? 'subject is required'
104
+ : filteredSubject.length <= maxSummaryLength(options, answers)
105
+ ? true
106
+ : 'Subject length must be less than or equal to ' +
107
+ maxSummaryLength(options, answers) +
108
+ ' characters. Current length is ' +
109
+ filteredSubject.length +
110
+ ' characters.';
111
+ },
112
+ transformer: function(subject, answers) {
113
+ var filteredSubject = filterSubject(subject);
114
+ var color =
115
+ filteredSubject.length <= maxSummaryLength(options, answers)
116
+ ? chalk.green
117
+ : chalk.red;
118
+ return color('(' + filteredSubject.length + ') ' + subject);
119
+ },
120
+ filter: function(subject) {
121
+ return filterSubject(subject);
122
+ }
123
+ },
124
+ {
66
125
  type: 'input',
67
126
  name: 'body',
68
- message: 'Provide a longer description of the change:\n'
69
- }, {
127
+ message:
128
+ 'Provide a longer description of the change: (press enter to skip)\n',
129
+ default: options.defaultBody
130
+ },
131
+ {
132
+ type: 'confirm',
133
+ name: 'isBreaking',
134
+ message: 'Are there any breaking changes?',
135
+ default: false
136
+ },
137
+ {
138
+ type: 'input',
139
+ name: 'breakingBody',
140
+ default: '-',
141
+ message:
142
+ 'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n',
143
+ when: function(answers) {
144
+ return answers.isBreaking && !answers.body;
145
+ },
146
+ validate: function(breakingBody, answers) {
147
+ return (
148
+ breakingBody.trim().length > 0 ||
149
+ 'Body is required for BREAKING CHANGE'
150
+ );
151
+ }
152
+ },
153
+ {
70
154
  type: 'input',
71
155
  name: 'breaking',
72
- message: 'List any breaking changes:\n'
73
- }, {
156
+ message: 'Describe the breaking changes:\n',
157
+ when: function(answers) {
158
+ return answers.isBreaking;
159
+ }
160
+ },
161
+
162
+ {
163
+ type: 'confirm',
164
+ name: 'isIssueAffected',
165
+ message: 'Does this change affect any open issues?',
166
+ default: options.defaultIssues ? true : false
167
+ },
168
+ {
169
+ type: 'input',
170
+ name: 'issuesBody',
171
+ default: '-',
172
+ message:
173
+ 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n',
174
+ when: function(answers) {
175
+ return (
176
+ answers.isIssueAffected && !answers.body && !answers.breakingBody
177
+ );
178
+ }
179
+ },
180
+ {
74
181
  type: 'input',
75
182
  name: 'issues',
76
- message: 'List any issues closed by this change:\n'
183
+ message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
184
+ when: function(answers) {
185
+ return answers.isIssueAffected;
186
+ },
187
+ default: options.defaultIssues ? options.defaultIssues : undefined
77
188
  }
78
189
  ]).then(function(answers) {
79
-
80
- var maxLineWidth = 100;
81
-
82
190
  var wrapOptions = {
83
191
  trim: true,
192
+ cut: false,
84
193
  newline: '\n',
85
- indent:'',
86
- width: maxLineWidth
194
+ indent: '',
195
+ width: options.maxLineWidth
87
196
  };
88
197
 
89
198
  // parentheses are only needed when a scope is present
90
- var scope = answers.scope.trim();
91
- scope = scope ? '(' + answers.scope.trim() + ')' : '';
199
+ var scope = answers.scope ? '(' + answers.scope + ')' : '';
92
200
 
93
- // Hard limit this line
94
- var head = (answers.type + scope + ': ' + answers.subject.trim()).slice(0, maxLineWidth);
201
+ // Hard limit this line in the validate
202
+ var head = answers.type + scope + ': ' + answers.subject;
95
203
 
96
- // Wrap these lines at 100 characters
97
- var body = wrap(answers.body, wrapOptions);
204
+ // Wrap these lines at options.maxLineWidth characters
205
+ var body = answers.body ? wrap(answers.body, wrapOptions) : false;
98
206
 
99
207
  // 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);
208
+ var breaking = answers.breaking ? answers.breaking.trim() : '';
209
+ breaking = breaking
210
+ ? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '')
211
+ : '';
212
+ breaking = breaking ? wrap(breaking, wrapOptions) : false;
105
213
 
106
- var footer = filter([ breaking, issues ]).join('\n\n');
214
+ var issues = answers.issues ? wrap(answers.issues, wrapOptions) : false;
107
215
 
108
- commit(head + '\n\n' + body + '\n\n' + footer);
216
+ commit(filter([head, body, breaking, issues]).join('\n\n'));
109
217
  });
110
218
  }
111
219
  };
package/engine.test.js ADDED
@@ -0,0 +1,555 @@
1
+ var chai = require('chai');
2
+ var chalk = require('chalk');
3
+ var engine = require('./engine');
4
+ var mock = require('mock-require');
5
+ var semver = require('semver');
6
+
7
+ var types = require('conventional-commit-types').types;
8
+
9
+ var expect = chai.expect;
10
+ chai.should();
11
+
12
+ var defaultOptions = {
13
+ types,
14
+ maxLineWidth: 100,
15
+ maxHeaderWidth: 100
16
+ };
17
+
18
+ var type = 'func';
19
+ var scope = 'everything';
20
+ var subject = 'testing123';
21
+ var subject2 = 'after the fall, I was gone';
22
+ var longBody =
23
+ 'a a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a' +
24
+ 'a a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a' +
25
+ 'a a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a aa a';
26
+ var longBodySplit =
27
+ longBody.slice(0, defaultOptions.maxLineWidth).trim() +
28
+ '\n' +
29
+ longBody
30
+ .slice(defaultOptions.maxLineWidth, 2 * defaultOptions.maxLineWidth)
31
+ .trim() +
32
+ '\n' +
33
+ longBody.slice(defaultOptions.maxLineWidth * 2, longBody.length).trim();
34
+ var body = 'A quick brown fox jumps over the dog';
35
+ var issues = 'a issues is not a person that kicks things';
36
+ var longIssues =
37
+ 'b b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b' +
38
+ 'b b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b' +
39
+ 'b b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b bb b';
40
+ var breakingChange = 'BREAKING CHANGE: ';
41
+ var breaking = 'asdhdfkjhbakjdhjkashd adhfajkhs asdhkjdsh ahshd';
42
+ var longIssuesSplit =
43
+ longIssues.slice(0, defaultOptions.maxLineWidth).trim() +
44
+ '\n' +
45
+ longIssues
46
+ .slice(defaultOptions.maxLineWidth, defaultOptions.maxLineWidth * 2)
47
+ .trim() +
48
+ '\n' +
49
+ longIssues.slice(defaultOptions.maxLineWidth * 2, longIssues.length).trim();
50
+
51
+ describe('commit message', function() {
52
+ it('only header w/ out scope', function() {
53
+ expect(
54
+ commitMessage({
55
+ type,
56
+ subject
57
+ })
58
+ ).to.equal(`${type}: ${subject}`);
59
+ });
60
+ it('only header w/ scope', function() {
61
+ expect(
62
+ commitMessage({
63
+ type,
64
+ scope,
65
+ subject
66
+ })
67
+ ).to.equal(`${type}(${scope}): ${subject}`);
68
+ });
69
+ it('header and body w/ out scope', function() {
70
+ expect(
71
+ commitMessage({
72
+ type,
73
+ subject,
74
+ body
75
+ })
76
+ ).to.equal(`${type}: ${subject}\n\n${body}`);
77
+ });
78
+ it('header and body w/ scope', function() {
79
+ expect(
80
+ commitMessage({
81
+ type,
82
+ scope,
83
+ subject,
84
+ body
85
+ })
86
+ ).to.equal(`${type}(${scope}): ${subject}\n\n${body}`);
87
+ });
88
+ it('header, body and issues w/ out scope', function() {
89
+ expect(
90
+ commitMessage({
91
+ type,
92
+ subject,
93
+ body,
94
+ issues
95
+ })
96
+ ).to.equal(`${type}: ${subject}\n\n${body}\n\n${issues}`);
97
+ });
98
+ it('header, body and issues w/ scope', function() {
99
+ expect(
100
+ commitMessage({
101
+ type,
102
+ scope,
103
+ subject,
104
+ body,
105
+ issues
106
+ })
107
+ ).to.equal(`${type}(${scope}): ${subject}\n\n${body}\n\n${issues}`);
108
+ });
109
+ it('header, body and long issues w/ out scope', function() {
110
+ expect(
111
+ commitMessage({
112
+ type,
113
+ subject,
114
+ body,
115
+ issues: longIssues
116
+ })
117
+ ).to.equal(`${type}: ${subject}\n\n${body}\n\n${longIssuesSplit}`);
118
+ });
119
+ it('header, body and long issues w/ scope', function() {
120
+ expect(
121
+ commitMessage({
122
+ type,
123
+ scope,
124
+ subject,
125
+ body,
126
+ issues: longIssues
127
+ })
128
+ ).to.equal(
129
+ `${type}(${scope}): ${subject}\n\n${body}\n\n${longIssuesSplit}`
130
+ );
131
+ });
132
+ it('header and long body w/ out scope', function() {
133
+ expect(
134
+ commitMessage({
135
+ type,
136
+ subject,
137
+ body: longBody
138
+ })
139
+ ).to.equal(`${type}: ${subject}\n\n${longBodySplit}`);
140
+ });
141
+ it('header and long body w/ scope', function() {
142
+ expect(
143
+ commitMessage({
144
+ type,
145
+ scope,
146
+ subject,
147
+ body: longBody
148
+ })
149
+ ).to.equal(`${type}(${scope}): ${subject}\n\n${longBodySplit}`);
150
+ });
151
+ it('header, long body and issues w/ out scope', function() {
152
+ expect(
153
+ commitMessage({
154
+ type,
155
+ subject,
156
+ body: longBody,
157
+ issues
158
+ })
159
+ ).to.equal(`${type}: ${subject}\n\n${longBodySplit}\n\n${issues}`);
160
+ });
161
+ it('header, long body and issues w/ scope', function() {
162
+ expect(
163
+ commitMessage({
164
+ type,
165
+ scope,
166
+ subject,
167
+ body: longBody,
168
+ issues
169
+ })
170
+ ).to.equal(
171
+ `${type}(${scope}): ${subject}\n\n${longBodySplit}\n\n${issues}`
172
+ );
173
+ });
174
+ it('header, long body and long issues w/ out scope', function() {
175
+ expect(
176
+ commitMessage({
177
+ type,
178
+ subject,
179
+ body: longBody,
180
+ issues: longIssues
181
+ })
182
+ ).to.equal(`${type}: ${subject}\n\n${longBodySplit}\n\n${longIssuesSplit}`);
183
+ });
184
+ it('header, long body and long issues w/ scope', function() {
185
+ expect(
186
+ commitMessage({
187
+ type,
188
+ scope,
189
+ subject,
190
+ body: longBody,
191
+ issues: longIssues
192
+ })
193
+ ).to.equal(
194
+ `${type}(${scope}): ${subject}\n\n${longBodySplit}\n\n${longIssuesSplit}`
195
+ );
196
+ });
197
+ it('header, long body, breaking change, and long issues w/ scope', function() {
198
+ expect(
199
+ commitMessage({
200
+ type,
201
+ scope,
202
+ subject,
203
+ body: longBody,
204
+ breaking,
205
+ issues: longIssues
206
+ })
207
+ ).to.equal(
208
+ `${type}(${scope}): ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
209
+ );
210
+ });
211
+ it('header, long body, breaking change (with prefix entered), and long issues w/ scope', function() {
212
+ expect(
213
+ commitMessage({
214
+ type,
215
+ scope,
216
+ subject,
217
+ body: longBody,
218
+ breaking: `${breakingChange}${breaking}`,
219
+ issues: longIssues
220
+ })
221
+ ).to.equal(
222
+ `${type}(${scope}): ${subject}\n\n${longBodySplit}\n\n${breakingChange}${breaking}\n\n${longIssuesSplit}`
223
+ );
224
+ });
225
+ });
226
+
227
+ describe('validation', function() {
228
+ it('subject exceeds max length', function() {
229
+ expect(() =>
230
+ commitMessage({
231
+ type,
232
+ scope,
233
+ subject: longBody
234
+ })
235
+ ).to.throw(
236
+ 'length must be less than or equal to ' +
237
+ `${defaultOptions.maxLineWidth - type.length - scope.length - 4}`
238
+ );
239
+ });
240
+ it('empty subject', function() {
241
+ expect(() =>
242
+ commitMessage({
243
+ type,
244
+ scope,
245
+ subject: ''
246
+ })
247
+ ).to.throw('subject is required');
248
+ });
249
+ });
250
+
251
+ describe('defaults', function() {
252
+ it('defaultType default', function() {
253
+ expect(questionDefault('type')).to.be.undefined;
254
+ });
255
+ it('defaultType options', function() {
256
+ expect(
257
+ questionDefault('type', customOptions({ defaultType: type }))
258
+ ).to.equal(type);
259
+ });
260
+ it('defaultScope default', function() {
261
+ expect(questionDefault('scope')).to.be.undefined;
262
+ });
263
+ it('defaultScope options', () =>
264
+ expect(
265
+ questionDefault('scope', customOptions({ defaultScope: scope }))
266
+ ).to.equal(scope));
267
+
268
+ it('defaultSubject default', () =>
269
+ expect(questionDefault('subject')).to.be.undefined);
270
+ it('defaultSubject options', function() {
271
+ expect(
272
+ questionDefault(
273
+ 'subject',
274
+ customOptions({
275
+ defaultSubject: subject
276
+ })
277
+ )
278
+ ).to.equal(subject);
279
+ });
280
+ it('defaultBody default', function() {
281
+ expect(questionDefault('body')).to.be.undefined;
282
+ });
283
+ it('defaultBody options', function() {
284
+ expect(
285
+ questionDefault('body', customOptions({ defaultBody: body }))
286
+ ).to.equal(body);
287
+ });
288
+ it('defaultIssues default', function() {
289
+ expect(questionDefault('issues')).to.be.undefined;
290
+ });
291
+ it('defaultIssues options', function() {
292
+ expect(
293
+ questionDefault(
294
+ 'issues',
295
+ customOptions({
296
+ defaultIssues: issues
297
+ })
298
+ )
299
+ ).to.equal(issues);
300
+ });
301
+ });
302
+
303
+ describe('prompts', function() {
304
+ it('commit subject prompt for commit w/ out scope', function() {
305
+ expect(questionPrompt('subject', { type })).to.contain(
306
+ `(max ${defaultOptions.maxHeaderWidth - type.length - 2} chars)`
307
+ );
308
+ });
309
+ it('commit subject prompt for commit w/ scope', function() {
310
+ expect(questionPrompt('subject', { type, scope })).to.contain(
311
+ `(max ${defaultOptions.maxHeaderWidth -
312
+ type.length -
313
+ scope.length -
314
+ 4} chars)`
315
+ );
316
+ });
317
+ });
318
+
319
+ describe('transformation', function() {
320
+ it('subject w/ character count', () =>
321
+ expect(
322
+ questionTransformation('subject', {
323
+ type,
324
+ subject
325
+ })
326
+ ).to.equal(chalk.green(`(${subject.length}) ${subject}`)));
327
+ it('long subject w/ character count', () =>
328
+ expect(
329
+ questionTransformation('subject', {
330
+ type,
331
+ subject: longBody
332
+ })
333
+ ).to.equal(chalk.red(`(${longBody.length}) ${longBody}`)));
334
+ });
335
+
336
+ describe('filter', function() {
337
+ it('lowercase scope', () =>
338
+ expect(questionFilter('scope', 'HelloMatt')).to.equal('hellomatt'));
339
+ it('lowerfirst subject trimmed and trailing dots striped', () =>
340
+ expect(questionFilter('subject', ' A subject... ')).to.equal(
341
+ 'a subject'
342
+ ));
343
+ });
344
+
345
+ describe('when', function() {
346
+ it('breaking by default', () =>
347
+ expect(questionWhen('breaking', {})).to.be.undefined);
348
+ it('breaking when isBreaking', () =>
349
+ expect(
350
+ questionWhen('breaking', {
351
+ isBreaking: true
352
+ })
353
+ ).to.be.true);
354
+ it('issues by default', () =>
355
+ expect(questionWhen('issues', {})).to.be.undefined);
356
+ it('issues when isIssueAffected', () =>
357
+ expect(
358
+ questionWhen('issues', {
359
+ isIssueAffected: true
360
+ })
361
+ ).to.be.true);
362
+ });
363
+
364
+ describe('commitlint config header-max-length', function() {
365
+ //commitlint config parser only supports Node 6.0.0 and higher
366
+ if (semver.gte(process.version, '6.0.0')) {
367
+ function mockOptions(headerMaxLength) {
368
+ var options = undefined;
369
+ mock('./engine', function(opts) {
370
+ options = opts;
371
+ });
372
+ if (headerMaxLength) {
373
+ mock('cosmiconfig', function() {
374
+ return {
375
+ load: function(cwd) {
376
+ return {
377
+ filepath: cwd + '/.commitlintrc.js',
378
+ config: {
379
+ rules: {
380
+ 'header-max-length': [2, 'always', headerMaxLength]
381
+ }
382
+ }
383
+ };
384
+ }
385
+ };
386
+ });
387
+ }
388
+
389
+ mock.reRequire('./index');
390
+ try {
391
+ return mock
392
+ .reRequire('@commitlint/load')()
393
+ .then(function() {
394
+ return options;
395
+ });
396
+ } catch (err) {
397
+ return Promise.resolve(options);
398
+ }
399
+ }
400
+
401
+ afterEach(function() {
402
+ delete require.cache[require.resolve('./index')];
403
+ delete require.cache[require.resolve('@commitlint/load')];
404
+ delete process.env.CZ_MAX_HEADER_WIDTH;
405
+ mock.stopAll();
406
+ });
407
+
408
+ it('with no environment or commitizen config override', function() {
409
+ return mockOptions(72).then(function(options) {
410
+ expect(options).to.have.property('maxHeaderWidth', 72);
411
+ });
412
+ });
413
+
414
+ it('with environment variable override', function() {
415
+ process.env.CZ_MAX_HEADER_WIDTH = '105';
416
+ return mockOptions(72).then(function(options) {
417
+ expect(options).to.have.property('maxHeaderWidth', 105);
418
+ });
419
+ });
420
+
421
+ it('with commitizen config override', function() {
422
+ mock('commitizen', {
423
+ configLoader: {
424
+ load: function() {
425
+ return {
426
+ maxHeaderWidth: 103
427
+ };
428
+ }
429
+ }
430
+ });
431
+ return mockOptions(72).then(function(options) {
432
+ expect(options).to.have.property('maxHeaderWidth', 103);
433
+ });
434
+ });
435
+ } else {
436
+ //Node 4 doesn't support commitlint so the config value should remain the same
437
+ it('default value for Node 4', function() {
438
+ return mockOptions(72).then(function(options) {
439
+ expect(options).to.have.property('maxHeaderWidth', 100);
440
+ });
441
+ });
442
+ }
443
+ });
444
+ function commitMessage(answers, options) {
445
+ options = options || defaultOptions;
446
+ var result = null;
447
+ engine(options).prompter(
448
+ {
449
+ prompt: function(questions) {
450
+ return {
451
+ then: function(finalizer) {
452
+ processQuestions(questions, answers, options);
453
+ finalizer(answers);
454
+ }
455
+ };
456
+ }
457
+ },
458
+ function(message) {
459
+ result = message;
460
+ }
461
+ );
462
+ return result;
463
+ }
464
+
465
+ function processQuestions(questions, answers, options) {
466
+ for (var i in questions) {
467
+ var question = questions[i];
468
+ var answer = answers[question.name];
469
+ var validation =
470
+ answer === undefined || !question.validate
471
+ ? true
472
+ : question.validate(answer, answers);
473
+ if (validation !== true) {
474
+ throw new Error(
475
+ validation ||
476
+ `Answer '${answer}' to question '${question.name}' was invalid`
477
+ );
478
+ }
479
+ if (question.filter && answer) {
480
+ answers[question.name] = question.filter(answer);
481
+ }
482
+ }
483
+ }
484
+
485
+ function getQuestions(options) {
486
+ options = options || defaultOptions;
487
+ var result = null;
488
+ engine(options).prompter({
489
+ prompt: function(questions) {
490
+ result = questions;
491
+ return {
492
+ then: function() {}
493
+ };
494
+ }
495
+ });
496
+ return result;
497
+ }
498
+
499
+ function getQuestion(name, options) {
500
+ options = options || defaultOptions;
501
+ var questions = getQuestions(options);
502
+ for (var i in questions) {
503
+ if (questions[i].name === name) {
504
+ return questions[i];
505
+ }
506
+ }
507
+ return false;
508
+ }
509
+
510
+ function questionPrompt(name, answers, options) {
511
+ options = options || defaultOptions;
512
+ var question = getQuestion(name, options);
513
+ return question.message && typeof question.message === 'string'
514
+ ? question.message
515
+ : question.message(answers);
516
+ }
517
+
518
+ function questionTransformation(name, answers, options) {
519
+ options = options || defaultOptions;
520
+ var question = getQuestion(name, options);
521
+ return (
522
+ question.transformer &&
523
+ question.transformer(answers[name], answers, options)
524
+ );
525
+ }
526
+
527
+ function questionFilter(name, answer, options) {
528
+ options = options || defaultOptions;
529
+ var question = getQuestion(name, options);
530
+ return (
531
+ question.filter &&
532
+ question.filter(typeof answer === 'string' ? answer : answer[name])
533
+ );
534
+ }
535
+
536
+ function questionDefault(name, options) {
537
+ options = options || defaultOptions;
538
+ var question = getQuestion(name, options);
539
+ return question.default;
540
+ }
541
+
542
+ function questionWhen(name, answers, options) {
543
+ options = options || defaultOptions;
544
+ var question = getQuestion(name, options);
545
+ return question.when(answers);
546
+ }
547
+
548
+ function customOptions(options) {
549
+ Object.keys(defaultOptions).forEach(key => {
550
+ if (options[key] === undefined) {
551
+ options[key] = defaultOptions[key];
552
+ }
553
+ });
554
+ return options;
555
+ }
package/index.js CHANGED
@@ -1,8 +1,46 @@
1
- "format cjs";
1
+ 'format cjs';
2
2
 
3
3
  var engine = require('./engine');
4
4
  var conventionalCommitTypes = require('conventional-commit-types');
5
+ var configLoader = require('commitizen').configLoader;
5
6
 
6
- module.exports = engine({
7
- types: conventionalCommitTypes.types
8
- });
7
+ var config = configLoader.load();
8
+ var options = {
9
+ types: conventionalCommitTypes.types,
10
+ defaultType: process.env.CZ_TYPE || config.defaultType,
11
+ defaultScope: process.env.CZ_SCOPE || config.defaultScope,
12
+ defaultSubject: process.env.CZ_SUBJECT || config.defaultSubject,
13
+ defaultBody: process.env.CZ_BODY || config.defaultBody,
14
+ defaultIssues: process.env.CZ_ISSUES || config.defaultIssues,
15
+ maxHeaderWidth:
16
+ (process.env.CZ_MAX_HEADER_WIDTH &&
17
+ parseInt(process.env.CZ_MAX_HEADER_WIDTH)) ||
18
+ config.maxHeaderWidth ||
19
+ 100,
20
+ maxLineWidth:
21
+ (process.env.CZ_MAX_LINE_WIDTH &&
22
+ parseInt(process.env.CZ_MAX_LINE_WIDTH)) ||
23
+ config.maxLineWidth ||
24
+ 100
25
+ };
26
+
27
+ (function(options) {
28
+ try {
29
+ var commitlintLoad = require('@commitlint/load');
30
+ commitlintLoad().then(function(clConfig) {
31
+ if (clConfig.rules) {
32
+ var maxHeaderLengthRule = clConfig.rules['header-max-length'];
33
+ if (
34
+ typeof maxHeaderLengthRule === 'object' &&
35
+ maxHeaderLengthRule.length >= 3 &&
36
+ !process.env.CZ_MAX_HEADER_WIDTH &&
37
+ !config.maxHeaderWidth
38
+ ) {
39
+ options.maxHeaderWidth = maxHeaderLengthRule[2];
40
+ }
41
+ }
42
+ });
43
+ } catch (err) {}
44
+ })(options);
45
+
46
+ module.exports = engine(options);
package/package.json CHANGED
@@ -1,33 +1,51 @@
1
1
  {
2
2
  "name": "cz-conventional-changelog",
3
- "version": "2.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Commitizen adapter following the conventional-changelog format.",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "commit": "git-cz",
8
- "test": "echo 'Tests need to be setup!'",
9
- "semantic-release": "semantic-release pre && npm publish && semantic-release post"
8
+ "test": "mocha *.test.js",
9
+ "format": "prettier --write *.js",
10
+ "semantic-release": "semantic-release"
10
11
  },
11
12
  "homepage": "https://github.com/commitizen/cz-conventional-changelog",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "https://github.com/commitizen/cz-conventional-changelog.git"
15
16
  },
17
+ "engineStrict": true,
18
+ "engines": {
19
+ "node": ">= 10"
20
+ },
16
21
  "author": "Jim Cummins <jimthedev@gmail.com>",
17
22
  "license": "MIT",
18
23
  "dependencies": {
24
+ "chalk": "^2.4.1",
25
+ "commitizen": "^4.0.3",
19
26
  "conventional-commit-types": "^2.0.0",
20
27
  "lodash.map": "^4.5.1",
21
- "longest": "^1.0.1",
22
- "pad-right": "^0.2.2",
28
+ "longest": "^2.0.1",
23
29
  "right-pad": "^1.0.1",
24
30
  "word-wrap": "^1.0.3"
25
31
  },
26
32
  "devDependencies": {
27
- "commitizen": "2.9.6",
28
- "semantic-release": "^6.3.2"
33
+ "@types/chai": "^4.1.7",
34
+ "@types/mocha": "^5.2.7",
35
+ "chai": "^4.2.0",
36
+ "cosmiconfig": "^5.2.1",
37
+ "mocha": "^6.2.0",
38
+ "mock-require": "^3.0.3",
39
+ "prettier": "^1.15.3",
40
+ "semantic-release": "^15.13.3",
41
+ "semver": "^6.2.0"
42
+ },
43
+ "optionalDependencies": {
44
+ "@commitlint/load": ">6.1.1"
29
45
  },
30
- "czConfig": {
31
- "path": "./"
46
+ "config": {
47
+ "commitizen": {
48
+ "path": "./index.js"
49
+ }
32
50
  }
33
- }
51
+ }
package/.npmignore DELETED
@@ -1,27 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
-
5
- # Runtime data
6
- pids
7
- *.pid
8
- *.seed
9
-
10
- # Directory for instrumented libs generated by jscoverage/JSCover
11
- lib-cov
12
-
13
- # Coverage directory used by tools like istanbul
14
- coverage
15
-
16
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17
- .grunt
18
-
19
- # node-waf configuration
20
- .lock-wscript
21
-
22
- # Compiled binary addons (http://nodejs.org/api/addons.html)
23
- build/Release
24
-
25
- # Dependency directory
26
- # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27
- node_modules