yeoman / environment

Yeoman runtime environment
BSD 2-Clause "Simplified" License
127 stars 71 forks source link

add callback function support for generator scheduling #521

Closed dwarakaprasad closed 6 months ago

dwarakaprasad commented 6 months ago

depends on yeoman/yeoman-api#6 required by jhipster/generator-jhipster#25445

This PR allows a callback function as an option for ComposeOptions.schedule

The function receives the generator instance as the parameter and must return a boolean that will decide the scheduling. A true return value schedules the generator to be run under environment:run loop and a false queues the generator tasks immediately.

usage:

env.composeWith('hello:world', { schedule: (generator) => {
    // some code to decide the scheduling option
   return generator.immediate;
}});
mshima commented 6 months ago

Please add test for function returning false since a function is truthy.

current tests are in: https://github.com/yeoman/environment/blob/0218d49783ff7b5cb7bf5e21ec9d4a67b5f996a3/test/environment.js#L263-L270