yeoman / generator

Rails-inspired generator system that provides scaffolding for your apps
http://yeoman.io
BSD 2-Clause "Simplified" License
1.22k stars 299 forks source link

How to pass options to subgenerator in Yeoman 1.0? #995

Closed ngawor closed 7 years ago

ngawor commented 7 years ago

I had code that worked in .23 of yeoman-generator that I am now attempting to port to 1.0. The generator calls:

this.composeWith('@console/xxx:yyy', { options: testsOptions });

where testsOptions is an object containing uiFramework, among other things: {"uiFramework":"React"}

Previously, this value was then available within the subgenerator at this.options.uiFramework. However it is now undefined. I tried adding this.option("uiFramework") to the subgenerator constructor but it didn't make a difference. If I look at the this.options object available in the subgenerator with JSON.stringify, it has the following form:

{"skip-install":false,"skip-cache":false,"options":{"composedFrom":"@console/xxx:zzz","uiFramework":"React"}} (with a lot removed).

That is, it looks like I'd need to call this.options.options.uiFramework? Is that correct or have I done something wrong?

SBoudrias commented 7 years ago

The change is with composeWith

// BEFORE
this.composeWith('@console/xxx:yyy', { options: testsOptions });

// NOW
this.composeWith('@console/xxx:yyy', testsOptions);

There's no more need to options as the options key.

ngawor commented 7 years ago

Thank you!