diff --git a/engine.js b/engine.js index f8934628..23abaecb 100644 --- a/engine.js +++ b/engine.js @@ -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 = @@ -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, }; }); @@ -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. @@ -73,7 +73,7 @@ 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', @@ -81,16 +81,16 @@ module.exports = function(options) { 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) + @@ -98,7 +98,7 @@ module.exports = function(options) { ); }, default: options.defaultSubject, - validate: function(subject, answers) { + validate: function (subject, answers) { var filteredSubject = filterSubject(subject); return filteredSubject.length == 0 ? 'subject is required' @@ -110,7 +110,7 @@ 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) @@ -118,31 +118,26 @@ module.exports = function(options) { : 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', @@ -150,30 +145,30 @@ module.exports = function(options) { 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', @@ -181,28 +176,28 @@ module.exports = function(options) { 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 @@ -225,6 +220,6 @@ module.exports = function(options) { commit(filter([head, body, breaking, issues]).join('\n\n')); }); - } + }, }; }; diff --git a/index.js b/index.js index e43d4716..e1f4a137 100644 --- a/index.js +++ b/index.js @@ -24,7 +24,6 @@ var options = { parseInt(process.env.CZ_MAX_LINE_WIDTH)) || config.maxLineWidth || 100, - maxBodyLineWidth: config.maxBodyLineWidth || 80 }; (function(options) {