Skip to content

Commit

Permalink
Single way of passing both arguments and options to composed generator
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Dec 2, 2016
1 parent a852f62 commit 1885dec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
18 changes: 8 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ Base.prototype.run = function run(cb) {
* @return {this}
*
* @example <caption>Using a peerDependency generator</caption>
* this.composeWith('bootstrap', { options: { sass: true } });
* this.composeWith('bootstrap', { sass: true });
*
* @example <caption>Using a direct dependency generator</caption>
* this.composeWith('bootstrap', { options: { sass: true } }, {
* this.composeWith('bootstrap', { sass: true }, {
* local: require.resolve('generator-bootstrap/app/main.js')
* });
*/
Expand All @@ -503,21 +503,19 @@ Base.prototype.composeWith = function composeWith(namespace, options, settings)

// Pass down the default options so they're correclty mirrored down the chain.
options = _.extend({
options: _.extend({
skipInstall: this.options.skipInstall,
'skip-install': this.options.skipInstall,
skipCache: this.options.skipCache,
'skip-cache': this.options.skipCache
}, options.options)
skipInstall: this.options.skipInstall,
'skip-install': this.options.skipInstall,
skipCache: this.options.skipCache,
'skip-cache': this.options.skipCache
}, options);

if (settings.local) {
var Generator = require(settings.local);
Generator.resolved = require.resolve(settings.local);
Generator.namespace = namespace;
generator = this.env.instantiate(Generator, options);
generator = this.env.instantiate(Generator, {options: options});
} else {
generator = this.env.create(namespace, options);
generator = this.env.create(namespace, {options: options});
}

if (this._running) {
Expand Down
15 changes: 7 additions & 8 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,12 @@ describe('Base', function () {

it('pass options and arguments to the composed generators', function (done) {
this.dummy.composeWith('composed:gen', {
options: { foo: 'bar', 'skip-install': true },
arguments: ['foo']
foo: 'bar',
'skip-install': true
});

this.dummy.run(function () {
assert.equal(this.spy.firstCall.thisValue.options.foo, 'bar');
assert.deepEqual(this.spy.firstCall.thisValue.args, ['foo']);
done();
}.bind(this));
});
Expand All @@ -807,14 +806,14 @@ describe('Base', function () {
});

it('pass options and arguments to the composed generators', function (done) {
this.dummy.composeWith('dumb', {
options: { foo: 'bar', 'skip-install': true },
arguments: ['foo']
}, { local: this.stubPath });
this.dummy.composeWith(
'dumb',
{ foo: 'bar', 'skip-install': true },
{ local: this.stubPath }
);

this.dummy.run(function () {
assert.equal(this.spy.firstCall.thisValue.options.foo, 'bar');
assert.deepEqual(this.spy.firstCall.thisValue.args, ['foo']);
done();
}.bind(this));
});
Expand Down

0 comments on commit 1885dec

Please sign in to comment.