Skip to content

feat: line length options #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ module.exports = function (options) {
};
});

var maxHeadWidth = options.maxLineWidths.head;
var maxBodyWidth = options.maxLineWidths.body;

return {
// When a user runs `git cz`, prompter will
// be executed. We pass you cz, which currently
Expand All @@ -39,7 +42,7 @@ 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');
console.log('\nLine 1 will be cropped at ' + maxHeadWidth + ' characters. All other lines will be wrapped after ' + maxBodyWidth + ' characters.\n');

// Let's ask some questions of the user
// so that we can populate our commit
Expand Down Expand Up @@ -93,21 +96,19 @@ module.exports = function (options) {
}
]).then(function(answers) {

var maxLineWidth = 100;

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

// parentheses are only needed when a scope is present
var scope = answers.scope.trim();
scope = scope ? '(' + answers.scope.trim() + ')' : '';

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

// Wrap these lines at 100 characters
var body = wrap(answers.body, wrapOptions);
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
var engine = require('./engine');
var conventionalCommitTypes = require('conventional-commit-types');

var findConfig = require('find-config');
var get = require('lodash.get');

var maxLineWidths = Object.assign(
{ head: 100, body: 100 },
get(
findConfig.require('package.json', { home: false }),
'config.cz-conventional-changelog.maxLineWidths'));

module.exports = engine({
types: conventionalCommitTypes.types
types: conventionalCommitTypes.types,
maxLineWidths: maxLineWidths
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"license": "MIT",
"dependencies": {
"conventional-commit-types": "^2.0.0",
"find-config": "^1.0.0",
"lodash.get": "^4.4.2",
"lodash.map": "^4.5.1",
"longest": "^1.0.1",
"right-pad": "^1.0.1",
Expand Down