Skip to content

Commit 65d6a9f

Browse files
smccollum-blurbjimthedev
authored andcommittedSep 18, 2018
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.
1 parent f2ca755 commit 65d6a9f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed
 

Diff for: ‎engine.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,23 @@ module.exports = function (options) {
5353
type: 'list',
5454
name: 'type',
5555
message: 'Select the type of change that you\'re committing:',
56-
choices: choices
56+
choices: choices,
57+
default: options.defaultType
5758
}, {
5859
type: 'input',
5960
name: 'scope',
60-
message: 'What is the scope of this change (e.g. component or file name)? (press enter to skip)\n'
61+
message: 'What is the scope of this change (e.g. component or file name)? (press enter to skip)\n',
62+
default: options.defaultScope
6163
}, {
6264
type: 'input',
6365
name: 'subject',
64-
message: 'Write a short, imperative tense description of the change:\n'
66+
message: 'Write a short, imperative tense description of the change:\n',
67+
default: options.defaultSubject
6568
}, {
6669
type: 'input',
6770
name: 'body',
68-
message: 'Provide a longer description of the change: (press enter to skip)\n'
71+
message: 'Provide a longer description of the change: (press enter to skip)\n',
72+
default: options.defaultBody
6973
}, {
7074
type: 'confirm',
7175
name: 'isBreaking',
@@ -82,14 +86,15 @@ module.exports = function (options) {
8286
type: 'confirm',
8387
name: 'isIssueAffected',
8488
message: 'Does this change affect any open issues?',
85-
default: false
89+
default: options.defaultIssues ? true : false
8690
}, {
8791
type: 'input',
8892
name: 'issues',
8993
message: 'Add issue references (e.g. "fix #123", "re #123".):\n',
9094
when: function(answers) {
9195
return answers.isIssueAffected;
92-
}
96+
},
97+
default: options.defaultIssues ? options.defaultIssues : undefined
9398
}
9499
]).then(function(answers) {
95100

Diff for: ‎index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@ var engine = require('./engine');
44
var conventionalCommitTypes = require('conventional-commit-types');
55

66
module.exports = engine({
7-
types: conventionalCommitTypes.types
7+
types: conventionalCommitTypes.types,
8+
defaultType: process.env.CZ_TYPE,
9+
defaultScope: process.env.CZ_SCOPE,
10+
defaultSubject: process.env.CZ_SUBJECT,
11+
defaultBody: process.env.CZ_BODY,
12+
defaultIssues: process.env.CZ_ISSUES
813
});

0 commit comments

Comments
 (0)
Please sign in to comment.