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

Commit

Permalink
refactor: move commit types into a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed May 23, 2018
1 parent 909bae6 commit bb1967d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 38 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/
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const makeAffectsLine = function (answers) {
return '';
};

const emojis = {
style: '💄'
};

module.exports = {
prompter (cz, commit) {
let promptQuestions = questions;
Expand All @@ -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
Expand Down
47 changes: 11 additions & 36 deletions src/prompt/questions.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,21 @@
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 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',
Expand Down
39 changes: 39 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
@@ -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'
}
};

0 comments on commit bb1967d

Please sign in to comment.