plop icon indicating copy to clipboard operation
plop copied to clipboard

when prompt object has when property later prompts just ignored

Open bung87 opened this issue 4 years ago • 4 comments
trafficstars

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'
        }
      },

bung87 avatar Jan 02 '21 18:01 bung87

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

a-axton avatar Jan 03 '21 02:01 a-axton

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.

bung87 avatar Jan 03 '21 05:01 bung87

@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

crutchcorn avatar Apr 26 '22 00:04 crutchcorn

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.

amwmedia avatar Apr 26 '22 19:04 amwmedia