Skip to content

Commit

Permalink
Merge pull request #10 from streamich/feat-improve
Browse files Browse the repository at this point in the history
Feat improve
  • Loading branch information
streamich authored May 23, 2018
2 parents f5771fb + c134004 commit e2e70fd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.idea/
node_modules/
npm-debug.log
yarn.lock
yarn.lock
.vscode/
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"app-root-path": "^2.0.1",
"inquirer": "^3.1.1",
"shelljs": "^0.7.8",
"word-wrap": "^1.2.3"
"word-wrap": "^1.2.3",
"pad-right": "^0.2.2"
},
"optionalDependencies": {
"lerna": "^2.0.0-rc.5"
Expand Down
66 changes: 66 additions & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const types = {
chore: {
description: 'Build process or auxiliary tool changes',
emoji: '👻',
value: 'chore'
},
ci: {
description: 'CI related changes',
emoji: '🤖',
value: 'ci'
},
docs: {
description: 'Documentation only changes',
emoji: '✍️',
value: 'docs'
},
feat: {
description: 'A new feature',
emoji: '🎸',
value: 'feat'
},
fix: {
description: 'A bug fix',
emoji: '🐛',
value: 'fix'
},
perf: {
description: 'A code change that improves performance',
emoji: '🔥',
value: 'perf'
},
refactor: {
description: 'A code change that neither fixes a bug or adds a feature',
emoji: '👌',
value: 'refactor'
},
style: {
description: 'Markup-only changes (white-space, formatting, missing semi-colons, etc)',
emoji: '💄',
value: 'style'
},
test: {
description: 'Adding missing tests',
emoji: '💍',
value: 'test'
}
};

const list = [
'test',
'feat',
'fix',
'chore',
'docs',
'refactor',
'style',
'ci',
'perf'
];

module.exports = {
list,
maxMessageLength: 50,
minMessageLength: 3,
types
};
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const inquirer = require('inquirer');
const wrap = require('word-wrap');
const appRoot = require('app-root-path');
const defaults = require('./defaults');
const {
makePackagesQuestion,
questions
Expand Down Expand Up @@ -47,7 +48,9 @@ module.exports = {
width: MAX_LINE_WIDTH
};

const head = answers.type + ': ' + answers.subject;
const emoji = defaults.types[answers.type].emoji;
const emojiPrefix = emoji ? emoji + ' ' : '';
const head = answers.type + ': ' + emojiPrefix + answers.subject;
const affectsLine = makeAffectsLine(answers);

// Wrap these lines at MAX_LINE_WIDTH character
Expand Down
51 changes: 14 additions & 37 deletions src/prompt/questions.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
const MAX_SUBJECT_LENGTH = 50;
const MIN_SUBJECT_LENGTH = 3;
const pad = require('pad-right');
const defaults = require('../defaults');

const MAX_SUBJECT_LENGTH = defaults.maxMessageLength;
const MIN_SUBJECT_LENGTH = defaults.minMessageLength;
const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${MIN_SUBJECT_LENGTH} characters`;

const typeToListItem = ({description, emoji, value}) => ({
name: (emoji || '❔') + ' ' + pad(value + ':', 12, ' ') + description,
value
});

const questions = [
{
choices: [
{
name: 'feat: A new feature',
value: 'feat'
},
{
name: 'fix: A bug fix',
value: 'fix'
},
{
name: 'docs: Documentation only changes',
value: 'docs'
},
{
name: 'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)',
value: 'style'
},
{
name: 'refactor: A code change that neither fixes a bug or adds a feature',
value: 'refactor'
},
{
name: 'perf: A code change that improves performance',
value: 'perf'
},
{
name: 'test: Adding missing tests',
value: 'test'
},
{
name: 'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation',
value: 'chore'
}
],
choices: defaults.list.map((type) => typeToListItem(defaults.types[type])),
message: 'Select the type of change that you\'re committing:',
name: 'type',
type: 'list'
Expand All @@ -54,7 +29,9 @@ const questions = [
return subject;
},
leadingLabel: (answers) => `${answers.type}:`,
maxLength: MAX_SUBJECT_LENGTH,

// Minus 3 chars are for emoji + space.
maxLength: MAX_SUBJECT_LENGTH - 3,
message: 'Write a short, imperative mood description of the change:',
name: 'subject',
type: 'limitedInput',
Expand Down

0 comments on commit e2e70fd

Please sign in to comment.