Skip to content

Commit

Permalink
fix(engine): removed maxBodyLineWidth property
Browse files Browse the repository at this point in the history
  • Loading branch information
sajithneyo committed Aug 1, 2020
1 parent f828405 commit 5504430
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 42 deletions.
77 changes: 36 additions & 41 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ var map = require('lodash.map');
var longest = require('longest');
var chalk = require('chalk');

var filter = function(array) {
return array.filter(function(x) {
var filter = function (array) {
return array.filter(function (x) {
return x;
});
};

var headerLength = function(answers) {
var headerLength = function (answers) {
return (
answers.type.length + 2 + (answers.scope ? answers.scope.length + 2 : 0)
);
};

var maxSummaryLength = function(options, answers) {
var maxSummaryLength = function (options, answers) {
return options.maxHeaderWidth - headerLength(answers);
};

var filterSubject = function(subject) {
var filterSubject = function (subject) {
subject = subject.trim();
if (subject.charAt(0).toLowerCase() !== subject.charAt(0)) {
subject =
Expand All @@ -36,14 +36,14 @@ var filterSubject = function(subject) {
// This can be any kind of SystemJS compatible module.
// We use Commonjs here, but ES6 or AMD would do just
// fine.
module.exports = function(options) {
module.exports = function (options) {
var types = options.types;

var length = longest(Object.keys(types)).length + 1;
var choices = map(types, function(type, key) {
var choices = map(types, function (type, key) {
return {
name: (key + ':').padEnd(length) + ' ' + type.description,
value: key
value: key,
};
});

Expand All @@ -59,7 +59,7 @@ module.exports = function(options) {
//
// By default, we'll de-indent your commit
// template and will keep empty lines.
prompter: function(cz, commit) {
prompter: function (cz, commit) {
// Let's ask some questions of the user
// so that we can populate our commit
// template.
Expand All @@ -73,32 +73,32 @@ module.exports = function(options) {
name: 'type',
message: "Select the type of change that you're committing:",
choices: choices,
default: options.defaultType
default: options.defaultType,
},
{
type: 'input',
name: 'scope',
message:
'What is the scope of this change (e.g. component or file name): (press enter to skip)',
default: options.defaultScope,
filter: function(value) {
filter: function (value) {
return options.disableScopeLowerCase
? value.trim()
: value.trim().toLowerCase();
}
},
},
{
type: 'input',
name: 'subject',
message: function(answers) {
message: function (answers) {
return (
'Write a short, imperative tense description of the change (max ' +
maxSummaryLength(options, answers) +
' chars):\n'
);
},
default: options.defaultSubject,
validate: function(subject, answers) {
validate: function (subject, answers) {
var filteredSubject = filterSubject(subject);
return filteredSubject.length == 0
? 'subject is required'
Expand All @@ -110,99 +110,94 @@ module.exports = function(options) {
filteredSubject.length +
' characters.';
},
transformer: function(subject, answers) {
transformer: function (subject, answers) {
var filteredSubject = filterSubject(subject);
var color =
filteredSubject.length <= maxSummaryLength(options, answers)
? chalk.green
: chalk.red;
return color('(' + filteredSubject.length + ') ' + subject);
},
filter: function(subject) {
filter: function (subject) {
return filterSubject(subject);
}
},
},
{
type: 'input',
name: 'body',
message: function(answers) {
return (
'Provide a longer description of the change (max ' +
options.maxBodyLineWidth +
' chars per line): (press enter to skip)\n'
);
},
message:
'Provide a longer description of the change: (press enter to skip)\n',
default: options.defaultBody,
transformer: function(body) {
transformer: function (body) {
var color = chalk.green;
return color('(' + body.length + ') ' + body);
}
},
},
{
type: 'confirm',
name: 'isBreaking',
message: 'Are there any breaking changes?',
default: false
default: false,
},
{
type: 'input',
name: 'breakingBody',
default: '-',
message:
'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself:\n',
when: function(answers) {
when: function (answers) {
return answers.isBreaking && !answers.body;
},
validate: function(breakingBody, answers) {
validate: function (breakingBody, answers) {
return (
breakingBody.trim().length > 0 ||
'Body is required for BREAKING CHANGE'
);
}
},
},
{
type: 'input',
name: 'breaking',
message: 'Describe the breaking changes:\n',
when: function(answers) {
when: function (answers) {
return answers.isBreaking;
}
},
},

{
type: 'confirm',
name: 'isIssueAffected',
message: 'Does this change affect any open issues?',
default: options.defaultIssues ? true : false
default: options.defaultIssues ? true : false,
},
{
type: 'input',
name: 'issuesBody',
default: '-',
message:
'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:\n',
when: function(answers) {
when: function (answers) {
return (
answers.isIssueAffected && !answers.body && !answers.breakingBody
);
}
},
},
{
type: 'input',
name: 'issues',
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
when: function(answers) {
when: function (answers) {
return answers.isIssueAffected;
},
default: options.defaultIssues ? options.defaultIssues : undefined
}
]).then(function(answers) {
default: options.defaultIssues ? options.defaultIssues : undefined,
},
]).then(function (answers) {
var wrapOptions = {
trim: true,
cut: false,
newline: '\n',
indent: '',
width: options.maxLineWidth
width: options.maxLineWidth,
};

// parentheses are only needed when a scope is present
Expand All @@ -225,6 +220,6 @@ module.exports = function(options) {

commit(filter([head, body, breaking, issues]).join('\n\n'));
});
}
},
};
};
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var options = {
parseInt(process.env.CZ_MAX_LINE_WIDTH)) ||
config.maxLineWidth ||
100,
maxBodyLineWidth: config.maxBodyLineWidth || 80
};

(function(options) {
Expand Down

0 comments on commit 5504430

Please sign in to comment.