Skip to content

Commit

Permalink
Remove support for chainning at composeWith.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 20, 2021
1 parent c2245e1 commit e9d0a15
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,7 @@ class Generator extends Base {
* Compose this generator with another one.
* @param {String|Object|Array} generator The path to the generator module or an object (see examples)
* @param {Object} [options] The options passed to the Generator
* @param {boolean} [returnNewGenerator] Returns the created generator instead of returning this.
* @return {this|Object} This generator or the composed generator when returnNewGenerator=true
* @return {Generator} The composed generator
*
* @example <caption>Using a peerDependency generator</caption>
* this.composeWith('bootstrap', { sass: true });
Expand All @@ -1063,22 +1062,15 @@ class Generator extends Base {
* @example <caption>Passing a Generator class</caption>
* this.composeWith({ Generator: MyGenerator, path: '../generator-bootstrap/app/main.js' }, { sass: true });
*/
composeWith(generator, options, returnNewGenerator = false) {
composeWith(generator, options) {
if (typeof options === 'boolean') {
returnNewGenerator = options;
options = {};
}

const returnCompose = (returnValue) =>
returnNewGenerator ? returnValue : this;

let instantiatedGenerator;

if (Array.isArray(generator)) {
const generators = generator.map((gen) =>
this.composeWith(gen, options, returnNewGenerator)
);
return returnCompose(generators);
return generator.map((gen) => this.composeWith(gen, options));
}

const instantiate = (Generator, path) => {
Expand Down Expand Up @@ -1166,7 +1158,7 @@ class Generator extends Base {
}

if (!instantiatedGenerator) {
return returnCompose(instantiatedGenerator);
return instantiatedGenerator;
}

if (this._running) {
Expand All @@ -1175,7 +1167,7 @@ class Generator extends Base {
this._composedWith.push(instantiatedGenerator);
}

return returnCompose(instantiatedGenerator);
return instantiatedGenerator;
}

/**
Expand Down

0 comments on commit e9d0a15

Please sign in to comment.