diff --git a/.gitignore b/.gitignore index a47e9eb..391388a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ .idea/ node_modules/ npm-debug.log -yarn.lock \ No newline at end of file +yarn.lock +.vscode/ diff --git a/package.json b/package.json index edb4686..4e63b60 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/defaults.js b/src/defaults.js new file mode 100644 index 0000000..0657744 --- /dev/null +++ b/src/defaults.js @@ -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 +}; diff --git a/src/index.js b/src/index.js index ff11148..cdb8bec 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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 diff --git a/src/prompt/questions.js b/src/prompt/questions.js index 684e306..66d2512 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -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' @@ -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',