From 909bae68802fbc994e4c72bfd875b5e47653da4d Mon Sep 17 00:00:00 2001 From: Va Da Date: Wed, 23 May 2018 19:13:31 +0100 Subject: [PATCH 1/6] feat: simplify messages, increase line length --- src/prompt/questions.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/prompt/questions.js b/src/prompt/questions.js index 684e306..31330d0 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -1,4 +1,4 @@ -const MAX_SUBJECT_LENGTH = 50; +const MAX_SUBJECT_LENGTH = 64; const MIN_SUBJECT_LENGTH = 3; const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${MIN_SUBJECT_LENGTH} characters`; @@ -18,7 +18,7 @@ const questions = [ value: 'docs' }, { - name: 'style: Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)', + name: 'style: Markup-only changes (white-space, formatting, missing semi-colons, etc)', value: 'style' }, { @@ -34,8 +34,12 @@ const questions = [ value: 'test' }, { - name: 'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation', + name: 'chore: Build process or auxiliary tool changes', value: 'chore' + }, + { + name: 'ci: CI related changes', + value: 'ci' } ], message: 'Select the type of change that you\'re committing:', From bb1967d932634deb46de93e9859419f0bd7d6a26 Mon Sep 17 00:00:00 2001 From: Va Da Date: Wed, 23 May 2018 19:26:06 +0100 Subject: [PATCH 2/6] refactor: move commit types into a separate module --- .gitignore | 3 ++- src/index.js | 7 +++++- src/prompt/questions.js | 47 ++++++++++------------------------------- src/types.js | 39 ++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 src/types.js 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/src/index.js b/src/index.js index ff11148..c4e0549 100644 --- a/src/index.js +++ b/src/index.js @@ -28,6 +28,10 @@ const makeAffectsLine = function (answers) { return ''; }; +const emojis = { + style: '💄' +}; + module.exports = { prompter (cz, commit) { let promptQuestions = questions; @@ -47,7 +51,8 @@ module.exports = { width: MAX_LINE_WIDTH }; - const head = answers.type + ': ' + answers.subject; + const emojiPrefix = emojis[answers.type] ? emojis[answers.type] + ' ' : ''; + 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 31330d0..7251ee4 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -1,3 +1,5 @@ +const types = require('../types').types; + const MAX_SUBJECT_LENGTH = 64; const MIN_SUBJECT_LENGTH = 3; const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${MIN_SUBJECT_LENGTH} characters`; @@ -5,42 +7,15 @@ const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${MIN_S 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: Markup-only changes (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: Build process or auxiliary tool changes', - value: 'chore' - }, - { - name: 'ci: CI related changes', - value: 'ci' - } + types.test, + types.feat, + types.fix, + types.chore, + types.docs, + types.refactor, + types.style, + types.ci, + types.perf ], message: 'Select the type of change that you\'re committing:', name: 'type', diff --git a/src/types.js b/src/types.js new file mode 100644 index 0000000..70985d4 --- /dev/null +++ b/src/types.js @@ -0,0 +1,39 @@ +exports.types = { + chore: { + name: 'Build process or auxiliary tool changes', + value: 'chore' + }, + ci: { + name: 'CI related changes', + value: 'ci' + }, + docs: { + name: 'Documentation only changes', + value: 'docs' + }, + feat: { + name: 'A new feature', + value: 'feat' + }, + fix: { + name: 'A bug fix', + value: 'fix' + }, + perf: { + name: 'A code change that improves performance', + value: 'perf' + }, + refactor: { + name: 'A code change that neither fixes a bug or adds a feature', + value: 'refactor' + }, + style: { + emoji: '💄', + name: 'Markup-only changes (white-space, formatting, missing semi-colons, etc)', + value: 'style' + }, + test: { + name: 'Adding missing tests', + value: 'test' + } +}; From 3e2e57b8f492073d037faf51e045334b69e72f36 Mon Sep 17 00:00:00 2001 From: Va Da Date: Wed, 23 May 2018 19:33:34 +0100 Subject: [PATCH 3/6] feat: display emoji in selection list --- package.json | 3 ++- src/prompt/questions.js | 24 +++++++++++++++--------- src/types.js | 18 +++++++++--------- 3 files changed, 26 insertions(+), 19 deletions(-) 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/prompt/questions.js b/src/prompt/questions.js index 7251ee4..fedcf1b 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -1,21 +1,27 @@ +const pad = require('pad-right'); const types = require('../types').types; const MAX_SUBJECT_LENGTH = 64; const MIN_SUBJECT_LENGTH = 3; 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: [ - types.test, - types.feat, - types.fix, - types.chore, - types.docs, - types.refactor, - types.style, - types.ci, - types.perf + typeToListItem(types.test), + typeToListItem(types.feat), + typeToListItem(types.fix), + typeToListItem(types.chore), + typeToListItem(types.docs), + typeToListItem(types.refactor), + typeToListItem(types.style), + typeToListItem(types.ci), + typeToListItem(types.perf) ], message: 'Select the type of change that you\'re committing:', name: 'type', diff --git a/src/types.js b/src/types.js index 70985d4..e551532 100644 --- a/src/types.js +++ b/src/types.js @@ -1,39 +1,39 @@ exports.types = { chore: { - name: 'Build process or auxiliary tool changes', + description: 'Build process or auxiliary tool changes', value: 'chore' }, ci: { - name: 'CI related changes', + description: 'CI related changes', value: 'ci' }, docs: { - name: 'Documentation only changes', + description: 'Documentation only changes', value: 'docs' }, feat: { - name: 'A new feature', + description: 'A new feature', value: 'feat' }, fix: { - name: 'A bug fix', + description: 'A bug fix', value: 'fix' }, perf: { - name: 'A code change that improves performance', + description: 'A code change that improves performance', value: 'perf' }, refactor: { - name: 'A code change that neither fixes a bug or adds a feature', + description: 'A code change that neither fixes a bug or adds a feature', value: 'refactor' }, style: { + description: 'Markup-only changes (white-space, formatting, missing semi-colons, etc)', emoji: '💄', - name: 'Markup-only changes (white-space, formatting, missing semi-colons, etc)', value: 'style' }, test: { - name: 'Adding missing tests', + description: 'Adding missing tests', value: 'test' } }; From 2c36297c969d21d071ce1b7b397c9de314c143b6 Mon Sep 17 00:00:00 2001 From: Va Da Date: Wed, 23 May 2018 19:43:54 +0100 Subject: [PATCH 4/6] feat: add emojis to commit message --- src/index.js | 8 +++----- src/prompt/questions.js | 2 +- src/types.js | 8 ++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index c4e0549..28670b1 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 types = require('./types').types; const { makePackagesQuestion, questions @@ -28,10 +29,6 @@ const makeAffectsLine = function (answers) { return ''; }; -const emojis = { - style: '💄' -}; - module.exports = { prompter (cz, commit) { let promptQuestions = questions; @@ -51,7 +48,8 @@ module.exports = { width: MAX_LINE_WIDTH }; - const emojiPrefix = emojis[answers.type] ? emojis[answers.type] + ' ' : ''; + const emoji = types[answers.type].ejomi; + const emojiPrefix = emoji ? emoji + ' ' : ''; const head = answers.type + ': ' + emojiPrefix + answers.subject; const affectsLine = makeAffectsLine(answers); diff --git a/src/prompt/questions.js b/src/prompt/questions.js index fedcf1b..2a86801 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -6,7 +6,7 @@ const MIN_SUBJECT_LENGTH = 3; 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, + name: (emoji || '❔') + ' ' + pad(value + ':', 12, ' ') + description, value }); diff --git a/src/types.js b/src/types.js index e551532..8751261 100644 --- a/src/types.js +++ b/src/types.js @@ -1,30 +1,37 @@ exports.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: { @@ -34,6 +41,7 @@ exports.types = { }, test: { description: 'Adding missing tests', + emoji: '💍', value: 'test' } }; From fa2496c7c21949028685c0d5ff33f81894146609 Mon Sep 17 00:00:00 2001 From: Va Da Date: Wed, 23 May 2018 19:52:55 +0100 Subject: [PATCH 5/6] =?UTF-8?q?refactor:=20=F0=9F=91=8C=20create=20default?= =?UTF-8?q?s.js=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{types.js => defaults.js} | 21 ++++++++++++++++++++- src/index.js | 4 ++-- src/prompt/questions.js | 18 ++++-------------- 3 files changed, 26 insertions(+), 17 deletions(-) rename src/{types.js => defaults.js} (81%) diff --git a/src/types.js b/src/defaults.js similarity index 81% rename from src/types.js rename to src/defaults.js index 8751261..802084c 100644 --- a/src/types.js +++ b/src/defaults.js @@ -1,4 +1,4 @@ -exports.types = { +const types = { chore: { description: 'Build process or auxiliary tool changes', emoji: '👻', @@ -45,3 +45,22 @@ exports.types = { value: 'test' } }; + +const list = [ + 'test', + 'feat', + 'fix', + 'chore', + 'docs', + 'refactor', + 'style', + 'ci', + 'perf' +]; + +module.exports = { + list, + maxMessageLength: 64, + minMessageLength: 3, + types +}; diff --git a/src/index.js b/src/index.js index 28670b1..cdb8bec 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const fs = require('fs'); const inquirer = require('inquirer'); const wrap = require('word-wrap'); const appRoot = require('app-root-path'); -const types = require('./types').types; +const defaults = require('./defaults'); const { makePackagesQuestion, questions @@ -48,7 +48,7 @@ module.exports = { width: MAX_LINE_WIDTH }; - const emoji = types[answers.type].ejomi; + const emoji = defaults.types[answers.type].emoji; const emojiPrefix = emoji ? emoji + ' ' : ''; const head = answers.type + ': ' + emojiPrefix + answers.subject; const affectsLine = makeAffectsLine(answers); diff --git a/src/prompt/questions.js b/src/prompt/questions.js index 2a86801..2b59699 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -1,8 +1,8 @@ const pad = require('pad-right'); -const types = require('../types').types; +const defaults = require('../defaults'); -const MAX_SUBJECT_LENGTH = 64; -const MIN_SUBJECT_LENGTH = 3; +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}) => ({ @@ -12,17 +12,7 @@ const typeToListItem = ({description, emoji, value}) => ({ const questions = [ { - choices: [ - typeToListItem(types.test), - typeToListItem(types.feat), - typeToListItem(types.fix), - typeToListItem(types.chore), - typeToListItem(types.docs), - typeToListItem(types.refactor), - typeToListItem(types.style), - typeToListItem(types.ci), - typeToListItem(types.perf) - ], + choices: defaults.list.map((type) => typeToListItem(defaults.types[type])), message: 'Select the type of change that you\'re committing:', name: 'type', type: 'list' From c134004f774f79ace7c3bce6ea767d4f12b5f37d Mon Sep 17 00:00:00 2001 From: Va Da Date: Wed, 23 May 2018 22:15:27 +0100 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20=F0=9F=91=BB=20decrease=20commit?= =?UTF-8?q?=20message=20length=20as=20per=20re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/defaults.js | 2 +- src/prompt/questions.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/defaults.js b/src/defaults.js index 802084c..0657744 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -60,7 +60,7 @@ const list = [ module.exports = { list, - maxMessageLength: 64, + maxMessageLength: 50, minMessageLength: 3, types }; diff --git a/src/prompt/questions.js b/src/prompt/questions.js index 2b59699..66d2512 100644 --- a/src/prompt/questions.js +++ b/src/prompt/questions.js @@ -29,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',