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

Commit

Permalink
feat: add commitizen prompter
Browse files Browse the repository at this point in the history
  • Loading branch information
brokenmass committed Oct 20, 2016
1 parent 1ba869a commit 89b4dac
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 1 deletion.
107 changes: 107 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
'use strict';

const wrap = require('word-wrap');
const inquirer = require('inquirer');
inquirer.registerPrompt('limitedInput', require('./prompt/LimitedInput'));

const MAX_SUBJECT_LENGTH = 50;
const MAX_LINE_WIDTH = 72;

module.exports = {
prompter: (cz, commit) => {
inquirer.prompt([
{
type: 'list',
name: 'type',
message: 'Select the type of change that you\'re committing:',
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'
}
]
},
{
type: 'limitedInput',
name: 'subject',
maxLength: MAX_SUBJECT_LENGTH,
leadingLabel: (answers) => `${answers.type}:`,
message: 'Write a short, imperative mood description of the change:'
},
{
type: 'input',
name: 'body',
message: 'Provide a longer description of the change:\n'
},
{
type: 'input',
name: 'breaking',
message: 'List any breaking changes:\n'
},
{
type: 'input',
name: 'footer',
message: 'Reference any task that this commit closes:\n'
}
])
.then(function (answers) {
const wrapOptions = {
trim: true,
indent: '',
width: MAX_LINE_WIDTH
};

const head = (answers.type + ': ' + answers.subject.trim());

// Wrap these lines at MAX_LINE_WIDTH characters
const body = wrap(answers.body, wrapOptions);
const breaking = wrap(answers.breaking, wrapOptions);
const footer = wrap(answers.footer, wrapOptions);

let msg = head;

if (body) {
msg += '\n\n' + body;
}

if (breaking) {
msg += '\n\n' + 'BREAKING CHANGE: ' + breaking;
}

if (footer) {
msg += '\n\n' + 'Issues: ' + footer;
}

commit(msg);
});
}
}

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
},
"license": "UNLICENSED",
"dependencies": {
"inquirer": "^1.2.2"
"inquirer": "^1.2.2",
"word-wrap": "^1.1.0"
},
"devDependencies": {
"commitizen": ">=2.8.0 <2.8.3"
},
"config": {
"commitizen": {
"path": "./index.js"
}
}
}

0 comments on commit 89b4dac

Please sign in to comment.