yeoman/generator — pull request #324 by mrichard (2013-07-26 01:13:13+00:00)
Title: clone options for _hooks array in runHooks function

Looks like using multiple hookFor calls, causes conflicts with their respective arguments and options. Cloning the options in runHooks, before the hooks are invoked seems to do the trick. Example code that cause the problem is below. In this example the marionette:model generator ends up being called with the mocha-amd:unitTest arguments, despite the _hooks array in base containing the correct data. The pull request fixes this problem.

function Generator() {
generator.NamedBase.apply(this, arguments);
var dirPath = '../templates/javascript';
this.sourceRoot(path.join(__dirname, dirPath));

this.argument('model', { type: String, required: false });
this.argument('inherit', { type: String, required: false });

this.option('create-all', { desc: 'Create a new model for this collection' });

if (this.model && this.options['create-all']) {
// invoke marionette:model gen
this.hookFor('marionette', { as: 'model', args: [this.model, this.inherit], options: this.options });
}

// invoke mocha-amd:unitTest gen
this.hookFor('mocha-amd', {
as: 'unitTest',
args: [this.name, 'collection', 'collections']
});
}