From c856b9debda5dbbe272892819aea0890828c865b Mon Sep 17 00:00:00 2001 From: Va Da Date: Mon, 4 Jun 2018 22:18:28 +0100 Subject: [PATCH] =?UTF-8?q?style:=20=F0=9F=92=84=20improve=20question=20fo?= =?UTF-8?q?rmatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/LimitedInput.js | 4 ++-- lib/defaults.js | 3 ++- lib/questions.js | 25 ++++++------------------- lib/steps/issues.js | 5 +++++ lib/steps/type.js | 17 +++++++++++++++++ package.json | 3 ++- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/LimitedInput.js b/lib/LimitedInput.js index 026ebefc..ef3f8089 100644 --- a/lib/LimitedInput.js +++ b/lib/LimitedInput.js @@ -28,8 +28,8 @@ util.inherits(LimitedInput, inquirer.prompt.prompts.input); LimitedInput.prototype.updateMessage = function () { this.opt.message = `${this.originalMessage} -[${this.spacer}] ${this.remainingChar()} remaining chars -${this.leadingLabel}`; + [${this.spacer}] ${this.remainingChar()} remaining chars + ${this.leadingLabel}`; }; LimitedInput.prototype.remainingChar = function () { diff --git a/lib/defaults.js b/lib/defaults.js index 090fa0fa..78383bf6 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -35,7 +35,7 @@ const types = { value: 'refactor' }, style: { - description: 'Markup-only changes (white-space, formatting, missing semi-colons, etc)', + description: 'Markup, white-space, formatting, missing semi-colons...', emoji: '💄', value: 'style' }, @@ -74,5 +74,6 @@ module.exports = { list, maxMessageLength: 50, minMessageLength: 3, + scopes, types }; diff --git a/lib/questions.js b/lib/questions.js index 290d8a15..569c46f6 100644 --- a/lib/questions.js +++ b/lib/questions.js @@ -1,19 +1,10 @@ -const pad = require('pad-right'); - -const typeToListItem = ({description, emoji, value}) => ({ - name: (emoji || '❔') + ' ' + pad(value + ':', 12, ' ') + description, - value -}); +/* eslint-disable global-require */ +const chalk = require('chalk'); const createQuestions = (config) => { const MIN_SUBJECT_LENGTH_ERROR_MESSAGE = `The subject must have at least ${config.minMessageLength} characters`; const questions = [ - { - choices: config.list.map((type) => typeToListItem(config.types[type])), - message: 'Select the type of change that you\'re committing:', - name: 'type', - type: 'list' - }, + require('./steps/type').createQuestion({}, config), { filter: (input) => { let subject; @@ -35,20 +26,16 @@ const createQuestions = (config) => { validate: (input) => input.length >= config.minMessageLength || MIN_SUBJECT_LENGTH_ERROR_MESSAGE }, { - message: 'Provide a longer description of the change:\n', + message: 'Provide a longer description of the change:\n ', name: 'body', type: 'input' }, { - message: 'List any breaking changes:\n BREAKING CHANGE:', + message: `List any breaking changes:\n ${chalk.red('BREAKING CHANGE')}:`, name: 'breaking', type: 'input' }, - { - message: 'Reference any task that this commit closes:\n Issues:', - name: 'footer', - type: 'input' - } + require('./steps/issues').createQuestion() ]; return questions; diff --git a/lib/steps/issues.js b/lib/steps/issues.js index e69de29b..fede33af 100644 --- a/lib/steps/issues.js +++ b/lib/steps/issues.js @@ -0,0 +1,5 @@ +exports.createQuestion = () => ({ + message: 'Issues this commit closes:', + name: 'issues', + type: 'input' +}); diff --git a/lib/steps/type.js b/lib/steps/type.js index e69de29b..bf064534 100644 --- a/lib/steps/type.js +++ b/lib/steps/type.js @@ -0,0 +1,17 @@ +const pad = require('pad-right'); + +const typeToListItem = ({description, emoji, value}) => ({ + name: (emoji || '❔') + ' ' + pad(value + ':', 12, ' ') + description, + value +}); + +exports.createQuestion = (state, config) => { + const question = { + choices: config.list.map((type) => typeToListItem(config.types[type])), + message: 'Select the type of change that you\'re committing:\n', + name: 'type', + type: 'list' + }; + + return question; +}; diff --git a/package.json b/package.json index c8602504..5317bf58 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "word-wrap": "^1.2.3", "pad-right": "^0.2.2", "signale": "^1.1.0", - "minimist": "^1.2.0" + "minimist": "^1.2.0", + "chalk": "^2.4.1" }, "devDependencies": { "commitizen": "^2.9.6",