diff --git a/engine.js b/engine.js index ad1e0304..cd45fa9e 100644 --- a/engine.js +++ b/engine.js @@ -5,6 +5,12 @@ var map = require('lodash.map'); var longest = require('longest'); var rightPad = require('right-pad'); +var filter = function(array) { + return array.filter(function(x) { + return x; + }); +}; + // This can be any kind of SystemJS compatible module. // We use Commonjs here, but ES6 or AMD would do just // fine. @@ -32,7 +38,8 @@ 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) { + 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 @@ -48,6 +55,14 @@ module.exports = function (options) { name: 'type', message: 'Select the type of change that you\'re committing:', choices: choices + }, { + type: 'confirm', + name: 'skipCI', + message: 'Should CI (tests or builds) be skipped for this commit?', + default: true, + when: function (answers) { + return answers.type === 'docs' || answers.type === 'chore' + } }, { type: 'input', name: 'scope', @@ -62,10 +77,14 @@ module.exports = function (options) { message: 'Provide a longer description of the change:\n' }, { type: 'input', - name: 'footer', - message: 'List any breaking changes or issues closed by this change:\n' + name: 'breaking', + message: 'List any breaking changes:\n' + }, { + type: 'input', + name: 'issues', + message: 'List any issues closed by this change:\n' } - ]).then(function(answers) { + ]).then(function (answers) { var maxLineWidth = 100; @@ -80,12 +99,32 @@ module.exports = function (options) { var scope = answers.scope.trim(); scope = scope ? '(' + answers.scope.trim() + ')' : ''; + var hasSkip = ['[ci skip]', '[skip ci]'].some(v => { + return ( + answers.subject.indexOf(v) > -1 || + answers.body.indexOf(v) > -1 + ) + }); + + var addSkip = !hasSkip && answers.skipCI + // 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, addSkip ? maxLineWidth - 10 : maxLineWidth); + + if (addSkip) head += ' [ci skip]'; // Wrap these lines at 100 characters var body = wrap(answers.body, wrapOptions); - var footer = wrap(answers.footer, wrapOptions); + + // Apply breaking change prefix, removing it if already present + var breaking = answers.breaking.trim(); + breaking = breaking ? 'BREAKING CHANGE: ' + breaking.replace(/^BREAKING CHANGE: /, '') : ''; + breaking = wrap(breaking, wrapOptions); + + var issues = wrap(answers.issues, wrapOptions); + + var footer = filter([ breaking, issues ]).join('\n\n'); commit(head + '\n\n' + body + '\n\n' + footer); }); diff --git a/package.json b/package.json index d6fae469..fe2d2fc5 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "word-wrap": "^1.0.3" }, "devDependencies": { - "commitizen": "2.9.5", + "commitizen": "2.9.6", "semantic-release": "^6.3.2" }, "czConfig": {