Search code examples
yeomanyeoman-generator

Pass variables to and from Yeoman subgenerators


Is this possible, if yes, how would I go about it?

I have some subgenerators, which install express, wordpress or drupal. You can also name the install folder and name the assets folders (css/js/images). I'd like to pass those folder names to the parent generator for templating.


Solution

  • Variables can be pass through options/arguments when using composition. This only flows from the parent to the children.

    There's no way for the children to pass back values to the parent generator. This is by design.

    Better way is to rely on configuration files like package.json or infer settings from the content of files in the destination folder. This is better because that mean your generator is loosely couple to match the architecture of any existing project or any other generators your end user might want to compose with.