Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Pr/44 (#55)
Browse files Browse the repository at this point in the history
Pr/44
  • Loading branch information
streamich authored Jul 1, 2019
2 parents cbb826a + 45489c8 commit 2beb13b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .git-cz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"disableEmoji": false
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ in your repo. Below is default config:

```js
module.exports = {
"disableEmoji": false,
"list": [
"test",
"feat",
Expand Down
23 changes: 16 additions & 7 deletions lib/formatCommitMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
head = answers.type + scope + ': ' + answers.subject;
} else {
const emoji = config.types[answers.type].emoji;
const emojiPrefix = emoji ? emoji + ' ' : '';

head = answers.type + scope + ': ' + emojiPrefix + answers.subject;
}

const affectsLine = makeAffectsLine(answers);

// Wrap these lines at MAX_LINE_WIDTH character
Expand All @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions lib/questions/type.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 2beb13b

Please sign in to comment.