Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add default values to options (#69)
For my own workflow, I made an adapter to allow passing default values in gleaned from the branch name, but needed to somehow get those values into this adapter, and I thought this was a good way to achieve this goal.

With these changes, my custom adapter can be like this:
```
process.env.CZ_TYPE = "fix"
module.exports = require("cz-conventional-changelog")
```

Instead of having to copy everything.
  • Loading branch information
smccollum-blurb authored and jimthedev committed Sep 18, 2018
1 parent f2ca755 commit 65d6a9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 11 additions & 6 deletions engine.js
Expand Up @@ -53,19 +53,23 @@ module.exports = function (options) {
type: 'list',
name: 'type',
message: 'Select the type of change that you\'re committing:',
choices: choices
choices: choices,
default: options.defaultType
}, {
type: 'input',
name: 'scope',
message: 'What is the scope of this change (e.g. component or file name)? (press enter to skip)\n'
message: 'What is the scope of this change (e.g. component or file name)? (press enter to skip)\n',
default: options.defaultScope
}, {
type: 'input',
name: 'subject',
message: 'Write a short, imperative tense description of the change:\n'
message: 'Write a short, imperative tense description of the change:\n',
default: options.defaultSubject
}, {
type: 'input',
name: 'body',
message: 'Provide a longer description of the change: (press enter to skip)\n'
message: 'Provide a longer description of the change: (press enter to skip)\n',
default: options.defaultBody
}, {
type: 'confirm',
name: 'isBreaking',
Expand All @@ -82,14 +86,15 @@ module.exports = function (options) {
type: 'confirm',
name: 'isIssueAffected',
message: 'Does this change affect any open issues?',
default: false
default: options.defaultIssues ? true : false
}, {
type: 'input',
name: 'issues',
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
when: function(answers) {
return answers.isIssueAffected;
}
},
default: options.defaultIssues ? options.defaultIssues : undefined
}
]).then(function(answers) {

Expand Down
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -4,5 +4,10 @@ var engine = require('./engine');
var conventionalCommitTypes = require('conventional-commit-types');

module.exports = engine({
types: conventionalCommitTypes.types
types: conventionalCommitTypes.types,
defaultType: process.env.CZ_TYPE,
defaultScope: process.env.CZ_SCOPE,
defaultSubject: process.env.CZ_SUBJECT,
defaultBody: process.env.CZ_BODY,
defaultIssues: process.env.CZ_ISSUES
});

0 comments on commit 65d6a9f

Please sign in to comment.