Skip to content

Dynamic choices and CLI #224

@ekv88

Description

@ekv88

So this is somewhere in the middle between bug and improvement.
I have kind of specific situation, but I think lot of users can try to do the same.

So I'm using Lerna for monorepo ReactJS project and plop is configured to 1st fetch list od directories inside ./packages folder as there can be multiple projects inside there and some developer can create new project so I wanted to make it dynamic as possible. I'm achieving using fs from node js and something like:

{
 type: 'list',
 name: 'package',
 message: 'Choose project from ./packages dir',
 choices: () => fs.readdirSync('./packages/')
  .filter(item => !/.ts|.tsx|.ejs|.js|.jsx/.test(item))
  .map(file => ({ name: file, value: file })),
}

But then if I try to use plopthro CLI like this: plop styleguide i get:

[ERROR] The "package" prompt did not recognize "styleguide" as a valid list value (ERROR: Cannot read property 'call' of undefined)

Standard option with providing array of objects works, but then i lose dynamic capabilities and have to force developers to change generator every time they make new project (it's not offeten but it could be)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions