-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from leonardoanalista/issue-30
fix: update this module to work with latest commitizen v2.8.1
- Loading branch information
Showing
7 changed files
with
389 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
|
||
|
||
var wrap = require('word-wrap'); | ||
|
||
|
||
module.exports = function buildCommit(answers) { | ||
|
||
var maxLineWidth = 100; | ||
|
||
var wrapOptions = { | ||
trim: true, | ||
newline: '\n', | ||
indent:'', | ||
width: maxLineWidth | ||
}; | ||
|
||
function addScope(scope) { | ||
if (!scope) return ': '; //it could be type === WIP. So there is no scope | ||
|
||
return '(' + scope.trim() + '): '; | ||
} | ||
|
||
function addSubject(subject) { | ||
return subject.trim(); | ||
} | ||
|
||
function escapeSpecialChars(result) { | ||
var specialChars = ['\`']; | ||
|
||
specialChars.map(function (item) { | ||
// For some strange reason, we have to pass additional '\' slash to commitizen. Total slashes are 4. | ||
// If user types "feat: `string`", the commit preview should show "feat: `\\string\\`". | ||
// Don't worry. The git log will be "feat: `string`" | ||
result = result.replace(new RegExp(item, 'g'), '\\\\`'); | ||
}); | ||
return result; | ||
} | ||
|
||
// Hard limit this line | ||
var head = (answers.type + addScope(answers.scope) + addSubject(answers.subject)).slice(0, maxLineWidth); | ||
|
||
// Wrap these lines at 100 characters | ||
var body = wrap(answers.body, wrapOptions) || ''; | ||
body = body.split('|').join('\n'); | ||
|
||
var breaking = wrap(answers.breaking, wrapOptions); | ||
var footer = wrap(answers.footer, wrapOptions); | ||
|
||
var result = head; | ||
if (body) { | ||
result += '\n\n' + body; | ||
} | ||
if (breaking) { | ||
result += '\n\n' + 'BREAKING CHANGE:\n' + breaking; | ||
} | ||
if (footer) { | ||
result += '\n\nISSUES CLOSED: ' + footer; | ||
} | ||
|
||
return escapeSpecialChars(result); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.