Skip to content

Commit c7b7e11

Browse files
committed
fix(wrapping): Fix fields to wrap instead of truncate at 100 characters
Fields should not be truncated at 100 characters. Instead, they should wrap. The exception is the first, or summary line of the commit message which is truncated to 100 characters since it is a summary. This closes commitizen/cz-cli#4
1 parent e5a1939 commit c7b7e11

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

index.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"format cjs";
2+
3+
var wrap = require('./node_modules/word-wrap/index');
4+
15
// This can be any kind of SystemJS compatible module.
26
// We use Commonjs here, but ES6 or AMD would do just
37
// fine.
@@ -16,7 +20,7 @@ module.exports = {
1620
// template and will keep empty lines.
1721
prompter: function(cz, commit) {
1822

19-
console.log('\nAll commit message lines will be cropped at 100 characters.\n');
23+
console.log('\nLine 1 will be cropped at 100 characters. All other lines will be wrapped after 100 characters.\n');
2024

2125
// Let's ask some questions of the user
2226
// so that we can populate our commit
@@ -74,10 +78,24 @@ module.exports = {
7478
message: 'List any breaking changes or issues closed by this change:\n'
7579
}
7680
], function(answers) {
81+
82+
var maxLineWidth = 100;
83+
84+
var wrapOptions = {
85+
trim: true,
86+
newline: '\n',
87+
indent:'',
88+
width: maxLineWidth
89+
};
90+
91+
// Hard limit this line
92+
var head = (answers.type + '(' + answers.scope.trim() + '): ' + answers.subject.trim()).slice(0, maxLineWidth);
93+
94+
// Wrap these lines at 100 characters
95+
var body = wrap(answers.body, wrapOptions);
96+
var footer = wrap(answers.footer, wrapOptions);
7797

78-
// Plug the answers into our template
79-
// By default, we dedent this for you
80-
commit(answers.type + '(' + answers.scope + '): ' + answers.subject.slice(0, 100) + '\n\n' + answers.body.slice(0, 100) + '\n\n' + answers.footer.slice(0, 100));
98+
commit(head + '\n\n' + body + '\n\n' + footer);
8199
});
82100
}
83101
}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
{
22
"name": "cz-conventional-changelog",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Commitizen adapter following the conventional-changelog format.",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
9+
"homepage": "https://github.com/commitizen/cz-conventional-changelog",
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/commitizen/cz-conventional-changelog.git"
13+
},
914
"author": "Jim Cummins <[email protected]>",
1015
"license": "MIT",
11-
"dependencies": {}
16+
"dependencies": {
17+
"word-wrap": "^1.0.3"
18+
}
1219
}

0 commit comments

Comments
 (0)