Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
fix(wrapping): Fix fields to wrap instead of truncate at 100 characters
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jimthedev committed May 6, 2015
1 parent e5a1939 commit c7b7e11
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
26 changes: 22 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"format cjs";

var wrap = require('./node_modules/word-wrap/index');

// This can be any kind of SystemJS compatible module.
// We use Commonjs here, but ES6 or AMD would do just
// fine.
Expand All @@ -16,7 +20,7 @@ module.exports = {
// template and will keep empty lines.
prompter: function(cz, commit) {

console.log('\nAll commit message lines will be cropped at 100 characters.\n');
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
Expand Down Expand Up @@ -74,10 +78,24 @@ module.exports = {
message: 'List any breaking changes or issues closed by this change:\n'
}
], function(answers) {

var maxLineWidth = 100;

var wrapOptions = {
trim: true,
newline: '\n',
indent:'',
width: maxLineWidth
};

// Hard limit this line
var head = (answers.type + '(' + answers.scope.trim() + '): ' + answers.subject.trim()).slice(0, maxLineWidth);

// Wrap these lines at 100 characters
var body = wrap(answers.body, wrapOptions);
var footer = wrap(answers.footer, wrapOptions);

// Plug the answers into our template
// By default, we dedent this for you
commit(answers.type + '(' + answers.scope + '): ' + answers.subject.slice(0, 100) + '\n\n' + answers.body.slice(0, 100) + '\n\n' + answers.footer.slice(0, 100));
commit(head + '\n\n' + body + '\n\n' + footer);
});
}
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"name": "cz-conventional-changelog",
"version": "1.0.1",
"version": "1.1.0",
"description": "Commitizen adapter following the conventional-changelog format.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"homepage": "https://github.com/commitizen/cz-conventional-changelog",
"repository": {
"type": "git",
"url": "https://github.com/commitizen/cz-conventional-changelog.git"
},
"author": "Jim Cummins <jimthedev@gmail.com>",
"license": "MIT",
"dependencies": {}
"dependencies": {
"word-wrap": "^1.0.3"
}
}

0 comments on commit c7b7e11

Please sign in to comment.