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

Commit

Permalink
style: 💄 improve question formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 4, 2018
1 parent 3d11bdd commit c856b9d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 23 deletions.
4 changes: 2 additions & 2 deletions lib/LimitedInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
3 changes: 2 additions & 1 deletion lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down Expand Up @@ -74,5 +74,6 @@ module.exports = {
list,
maxMessageLength: 50,
minMessageLength: 3,
scopes,
types
};
25 changes: 6 additions & 19 deletions lib/questions.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/steps/issues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.createQuestion = () => ({
message: 'Issues this commit closes:',
name: 'issues',
type: 'input'
});
17 changes: 17 additions & 0 deletions lib/steps/type.js
Original file line number Diff line number Diff line change
@@ -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;
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c856b9d

Please sign in to comment.