yeoman / generator

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

Value from option defined in a composed generator is only available on generator triggered #1456

Closed adautomendes closed 1 year ago

adautomendes commented 1 year ago

Hi :)

I have a scenario here with 3 subgeneratos following the structure below:

└───generator-dummy-adauto
    │   package-lock.json
    │   package.json
    └───generators
        ├───app
        │       index.js
        ├───sub-gen1
        │       index.js
        └───sub-gen2
                index.js

The app subgenerator is composed by sub-gen1 and sub-gen2. Each one define its own options inside its constructor:

//app
constructor(args, opts) {
    super(args, opts);
    this.option('str1', { type: String });
    this.option('bool1', { type: Boolean });
}
//sub-gen1
constructor(args, opts) {
    super(args, opts);
    this.option('str2', { type: String });
    this.option('bool2', { type: Boolean });
}
//sub-gen2
constructor(args, opts) {
    super(args, opts);
    this.option('str3', { type: String });
    this.option('bool3', { type: Boolean });
}

Then when I run from app I expected that each subgenerator will have access to the value of its options, e.g., in sub-gen1 I may be able to read str2. But, the behavior I'm having here is that app subgenerator have all options values (even the ones defined in the other two subgenerators) and sub-gen1 and sub-gen2 are not able to read the value of its own options, like the output below:

> yo dummy-adauto --str1=val1 --str2=val2 --str3=val3 --bool1 --bool2 --bool3

*** APP ***
str1 => val1
str2 => val2
str3 => val3
bool1 => true
bool2 => true
bool3 => true

** SUB-GEN1 ***
str1 => undefined
str2 => undefined
str3 => undefined
bool1 => undefined
bool2 => undefined
bool3 => undefined

*** SUB-GEN2 ***
str1 => undefined
str2 => undefined
str3 => undefined
bool1 => undefined
bool2 => undefined
bool3 => undefined

Is this the expected behavior under the composability of generators? How can I propagate these values from app to the others subgenerators correctly?

If needed, I have a dummy generator created to demonstrate this behavior: https://github.com/adautomendes/generator-dummy-adauto

github-actions[bot] commented 1 year ago

This issue is stale because it has been open with no activity. Remove stale label or comment or this will be closed

mshima commented 1 year ago

Generator v6 adds an option for that https://github.com/yeoman/generator/blob/454b3ec276aece401c1898ca421bce48b4397f5e/src/types.d.ts#L174