Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic choices and CLI #224

Closed
ekv88 opened this issue Jun 17, 2020 · 2 comments · May be fixed by #372
Closed

Dynamic choices and CLI #224

ekv88 opened this issue Jun 17, 2020 · 2 comments · May be fixed by #372

Comments

@ekv88
Copy link

ekv88 commented Jun 17, 2020

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)

@amwmedia
Copy link
Member

Try changing the value to be an array of choices instead of a function that returns an array of choices. I think the bypass logic doesn't support the latter interface.

so...

{
 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 })),
}

@crutchcorn
Copy link
Member

Closing, since @amwmedia provided an alternative API that doesn't seem to have a comment indicating its failure. Please feel free to let us know if that solution didn't work for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants