plop
plop copied to clipboard
when prompt object has when property later prompts just ignored
and that prompt has when doesn't show too here's the prompt in the middle of list.
//...
{
type: "input",
name: "name",
message: "Project name(private)",
validate: (e) => Boolean(validatePackageName(e.name)),
when: (e) =>{
console.log(e)
return e.sourceType === 'private'
}
},
I've been wanting to use when also, I looked at the code of node-plop and they are filtering out any prompts with when so it must be intentional, not sure why though. https://github.com/plopjs/node-plop/blob/a187e28a5ddc4c6b8e6d9495d95151daf1a2f4c2/src/prompt-bypass.js#L120
Thanks point out that, that's weird behaviour , it haven't been documented , the document says it's a plain prompt object, and it doesn't show any message as the code.
@amwmedia are you able to explain a bit more why this code was written? I'm admittedly not clear what it's doing here, either
If it is intentional, let's go ahead and document it
the prompt bypass functionality... where you can tack on the answers to prompts as part of the initial command, basically pre-answers prompts and removes them from the chain. Whatever prompts are left are passed to inquirer for resolution. Once the code hits a "branch" in the prompt chain, we can't know ahead of time how the rest of the prompt data corresponds to question objects. Due to this unknown, I added logic to "bail out" when the potential issue occurs.