Skip to content

Commit 6126164

Browse files
committed
Add filter support for optional questions
Default value is now defined in metalsmith metadata when meta.js "when" property returns false. This makes the filter evaluation works for filters using data that have been skipped in the prompt workflow by using the default value of the field. Close #408
1 parent 182feab commit 6126164

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/ask.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ module.exports = function ask (prompts, data, done) {
3232
*/
3333

3434
function prompt (data, key, prompt, done) {
35-
// skip prompts whose when condition is not met
36-
if (prompt.when && !evaluate(prompt.when, data)) {
37-
return done()
38-
}
39-
4035
var promptDefault = prompt.default
4136
if (typeof prompt.default === 'function') {
4237
promptDefault = function () {
4338
return prompt.default.bind(this)(data)
4439
}
4540
}
4641

42+
// skip prompts whose when condition is not met
43+
if (prompt.when && !evaluate(prompt.when, data)) {
44+
// define default value to avoid failure on filter evaluations
45+
data[key] = promptDefault;
46+
return done()
47+
}
48+
4749
inquirer.prompt([{
4850
type: promptMapping[prompt.type] || prompt.type,
4951
name: key,

0 commit comments

Comments
 (0)