(state)
| 15 | }; |
| 16 | |
| 17 | const formatCommitMessage = (state) => { |
| 18 | const {config, answers} = state; |
| 19 | const wrapOptions = { |
| 20 | indent: '', |
| 21 | trim: true, |
| 22 | width: MAX_LINE_WIDTH |
| 23 | }; |
| 24 | |
| 25 | const emoji = config.types[answers.type].emoji; |
| 26 | const scope = answers.scope ? '(' + answers.scope.trim() + ')' : ''; |
| 27 | const subject = answers.subject.trim(); |
| 28 | const type = answers.type; |
| 29 | |
| 30 | const format = config.format || '{type}{scope}: {emoji}{subject}'; |
| 31 | |
| 32 | const affectsLine = makeAffectsLine(answers); |
| 33 | |
| 34 | // Wrap these lines at MAX_LINE_WIDTH character |
| 35 | const body = wrap((answers.body || '') + affectsLine, wrapOptions); |
| 36 | const breaking = wrap(answers.breaking, wrapOptions); |
| 37 | const issues = wrap(answers.issues, wrapOptions); |
| 38 | |
| 39 | // @note(emoji) Add space after emoji (breakingChangePrefix/closedIssueEmoji) |
| 40 | const head = format |
| 41 | .replace(/\{emoji\}/g, config.disableEmoji ? '' : emoji + ' ') |
| 42 | .replace(/\{scope\}/g, scope) |
| 43 | .replace(/\{subject\}/g, subject) |
| 44 | .replace(/\{type\}/g, type); |
| 45 | |
| 46 | let msg = head; |
| 47 | |
| 48 | if (body) { |
| 49 | msg += '\n\n' + body; |
| 50 | } |
| 51 | |
| 52 | if (breaking) { |
| 53 | const breakingEmoji = config.disableEmoji ? '' : config.breakingChangePrefix; |
| 54 | |
| 55 | msg += '\n\nBREAKING CHANGE: ' + breakingEmoji + breaking; |
| 56 | } |
| 57 | |
| 58 | if (issues) { |
| 59 | const closedIssueEmoji = config.disableEmoji ? '' : config.closedIssuePrefix; |
| 60 | |
| 61 | msg += '\n\n' + closedIssueEmoji + config.closedIssueMessage + issues; |
| 62 | } |
| 63 | |
| 64 | return msg; |
| 65 | }; |
| 66 | |
| 67 | module.exports = formatCommitMessage; |
no test coverage detected
searching dependent graphs…