From 448873e2221a91b67d1e65a76467282118460a1a Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 11 Jun 2019 16:26:26 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20added=20disableEmojis=20?= =?UTF-8?q?on=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + lib/formatCommitMessage.js | 23 ++++++++++++++++------- lib/questions/type.js | 9 +++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 61f70ecd..15f4e10f 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ in your repo. Below is default config: ```js module.exports = { + "disableEmoji": false, "list": [ "test", "feat", diff --git a/lib/formatCommitMessage.js b/lib/formatCommitMessage.js index 46cb827f..af269fe9 100644 --- a/lib/formatCommitMessage.js +++ b/lib/formatCommitMessage.js @@ -19,17 +19,22 @@ const formatCommitMessage = (state) => { trim: true, width: MAX_LINE_WIDTH }; - - const emoji = config.types[answers.type].emoji; - const emojiPrefix = emoji ? emoji + ' ' : ''; - + let head = ''; let scope = ''; if (answers.scope && answers.scope !== 'none') { scope = `(${answers.scope})`; } - const head = answers.type + scope + ': ' + emojiPrefix + answers.subject; + if (!config.disableEmoji) { + const emoji = config.types[answers.type].emoji; + const emojiPrefix = emoji ? emoji + ' ' : ''; + + head = answers.type + scope + ': ' + emojiPrefix + answers.subject; + } + + head = answers.type + scope + ': ' + answers.subject; + const affectsLine = makeAffectsLine(answers); // Wrap these lines at MAX_LINE_WIDTH character @@ -44,11 +49,15 @@ const formatCommitMessage = (state) => { } if (breaking) { - msg += '\n\nBREAKING CHANGE: ' + config.breakingChangePrefix + breaking; + const breakingEmoji = config.disableEmoji ? config.breakingChangePrefix : ''; + + msg += '\n\nBREAKING CHANGE: ' + breakingEmoji + breaking; } if (issues) { - msg += '\n\n' + config.closedIssuePrefix + 'Closes: ' + issues; + const closedIssueEmoji = config.disableEmoji ? config.closedIssuePrefix : ''; + + msg += '\n\n' + closedIssueEmoji + 'Closes: ' + issues; } return msg; diff --git a/lib/questions/type.js b/lib/questions/type.js index fd04b67a..891c0c0c 100644 --- a/lib/questions/type.js +++ b/lib/questions/type.js @@ -1,18 +1,19 @@ const pad = require('pad-right'); -const typeToListItem = ({description, emoji, value}) => { - const prefix = emoji ? emoji + ' ' : ''; +const typeToListItem = ({types, disableEmoji}, type) => { + const {description, emoji, value} = types[type]; + const prefix = emoji && !disableEmoji ? emoji + ' ' : ''; return { name: prefix + pad(value + ':', 12, ' ') + description, value - } + }; }; exports.createQuestion = (state) => { const {config} = state; const question = { - choices: config.list.map((type) => typeToListItem(config.types[type])), + choices: config.list.map((type) => typeToListItem(config, type)), message: 'Select the type of change that you\'re committing:', name: 'type', type: 'list'