Open blimmer opened 3 years ago
i think maybe the right way for you to do that is to switch to "script mode" where actually you build your own workflow:
I see what you mean, but I'm not quite sure that meets my exact use-case. I basically have two generators and I want to guide the user through a series of prompts to choose the proper hygen generator to run. I could always just write a separate enquirer prompt to do this, probably. I was originally thinking it would be nice to keep everything in the same framework, though.
To add to this, lets say you have the following:
Here, a package is the base output type, so :
Components
are Packages
, but they go in design-system/packages
not packages
.Cli Tools
are also Packages
, but they go in tools/*
not packages
.So I want all the generated workspace package types to have all the files and attributes of the package
generator output, but i then want to do extra stuff.
---
sh: >-
yarn generate new package
title:<%= title %>
code:<%= code %>
package_name:<%= package_name %>
package_path:<%= package_path %>
main_export:<%= main_export %>
---
---
sh: mv packages/<%= code %> tools/
---
but it hangs on tools/generators/new/cli/1-create-package.ejs.t
So i figured this out by :
modifying my custom prompter to run the hygen prompter or not based on an interactive
flag
using nconf to turn envvars, argv, default file contents into pre-seeded answers.
My Custom Prompter
https://github.com/airtonix/crypto-app/blob/d46a04b11ce8a1514b282646e838f21f0c1d65a9/packages/hygen-prompts/src/gatherer.js
Creating a PackageJson prompt preset
https://github.com/airtonix/crypto-app/blob/d46a04b11ce8a1514b282646e838f21f0c1d65a9/packages/hygen-prompts/src/package-json.js
Using the PackageJson prompts
https://github.com/airtonix/crypto-app/blob/d46a04b11ce8a1514b282646e838f21f0c1d65a9/packages/generators/new/package/index.js
yarn generate new cli --title my awesome thinger
# ...asks a bunch of questions providing a mutated version of `title` as an initial value to each
Now because interactive
is true by default you get asked all the questions.
if you instead provide --no-interactive
then it will only succeed if you provide all the expected parameters (fails otherwise)
You won't find a use of this topic in that repo, but I'll paste it here from another repo:
tools/generators/new/cli/01_generate_package.ejs.t
---
sh: >-
yarn generate new package
--no-interactive
--title <%= title %>
--code <%= code %>
--package_name <%= package_name %>
--package_path <%= package_path %>
---
This ends up creating what I expect and then any other parts of my new/cli
generator take effect.
@airtonix you could check it it’s in the args and then use the skip methode
I have three generators:
handler
- this generator basically just delegates between the other two generators based on a promptbatch-handler
- handles batchessequential-handler
- handles one-at-a-time message processingWhen you run
hygen handler new
, it prompts asking which kind of handler you want (batch or sequential):Based on your answer, it triggers the proper generator using this
sh
command:Then, those handlers should prompt again, but it appears to just "hang":
I'm assuming this is because
stdin
isn't being passed through to thesh
command.If I run the sub-generator separately, it does prompt properly:
I have an example of this issue in a sample repo: https://github.com/blimmer/hygen-issue