diff --git a/README.md b/README.md index a294925..68e5ce5 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ This module can: * validate a given message if it fits the above simple format * guide the user with questions in order to form well formatted message -This was copied from [validate-commit-msg](https://www.npmjs.com/package/validate-commit-msg) -and cleaned up slightly to be both a wizard and a validator. +The validation was copied from [validate-commit-msg](https://www.npmjs.com/package/validate-commit-msg), +and the wizard is used from [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog). ## Install and use diff --git a/package.json b/package.json index 1e73674..4913577 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ }, "dependencies": { "check-more-types": "2.3.0", + "cz-conventional-changelog": "1.1.5", "lazy-ass": "1.3.0", "word-wrap": "1.1.0" } diff --git a/src/index.js b/src/index.js index f9b2a7a..3ad233d 100644 --- a/src/index.js +++ b/src/index.js @@ -8,5 +8,5 @@ module.exports = { // and from https://github.com/commitizen/cz-conventional-changelog parse: require('./valid-message').parse, validate: require('./valid-message').validate, - prompter: require('./message-wizard').prompter + prompter: require('cz-conventional-changelog').prompter } diff --git a/src/message-wizard.js b/src/message-wizard.js deleted file mode 100644 index f27afe3..0000000 --- a/src/message-wizard.js +++ /dev/null @@ -1,95 +0,0 @@ -'use strict' - -// copied from cz-conventional-changelog -const wrap = require('word-wrap') - -// This can be any kind of SystemJS compatible module. -// We use Commonjs here, but ES6 or AMD would do just -// fine. -module.exports = { - - // When a user runs `git cz`, prompter will - // be executed. We pass you cz, which currently - // is just an instance of inquirer.js. Using - // this you can ask questions and get answers. - // - // The callback should be executed when - // you're ready to send back a commit template - // to git. - // - // By default, we'll de-indent your commit - // template and will keep empty lines. - prompter: function prompter (cz, cb) { - console.log('\nLine 1 will be cropped at 100 characters.\n' + - 'All other lines will be wrapped after 100 characters.\n') - - // Let's ask some questions of the user - // so that we can populate our commit - // template. - // - // See inquirer.js docs for specifics. - // You can also opt to use another input - // collection library if you prefer. - cz.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: 'chore: Changes to the build process or auxiliary tools\n' + - ' and libraries such as documentation generation', - value: 'chore' - } - ] - }, { - type: 'input', - name: 'scope', - message: 'Denote the scope of this change (db, api, cli, etc.):\n' - }, { - type: 'input', - name: 'subject', - message: 'Write a short, imperative tense description of the change:\n' - }, { - type: 'input', - name: 'body', - message: 'Provide a longer description of the change:\n' - }, { - type: 'input', - name: 'issues', - message: 'List issues this commit resolves (fixes #2, closes #14):\n' - }, { - type: 'confirm', - name: 'breaking', - message: 'Is this a major breaking change:\n', - default: false - } - ], function (answers) { - var maxLineWidth = 100 - - var wrapOptions = { - trim: true, - newline: '\n', - indent: '', - width: maxLineWidth - } - - var breakingChange = answers.breaking ? 'BREAKING CHANGE: ' : '' - // Hard limit this line - var head = (answers.type + '(' + answers.scope.trim() + '): ' + - breakingChange + answers.subject.trim()).slice(0, maxLineWidth) - - // Wrap these lines at 100 characters - var body = wrap(breakingChange + answers.body, wrapOptions) - var issues = wrap(answers.issues, wrapOptions) - - cb(head + '\n\n' + body + '\n\n' + issues) - }) - } -}