2016-01-07 28 views
0

约曼版本:1.4.8 NPM:2.11.3 节点:0.12.7参数不是由发电机发现

有发电机调用自身的子发生器的附加打嗝,但是这不是太疯狂,那部分工作得很好。

我有这个在我的父母:

this.composeWith('mercury:component', { options: { 
    component: this.props.domain + 'Content', 
    domain: this.props.path + '/' 
}}) 

而这在我的成份指数:

constructor: function() { 
    yeoman.generators.Base.apply(this, arguments); 
    this.argument('component', {type: String, required: true}); 
    this.argument('domain', {type: String}); 
}, 

如果我叫水银:直接组件和检查arguments,我看到的命令行参数在'0'中。

{ '0': [ 'test', '.' ], 
    '1': { env: {things...} } } 

当它从父生成器调用时,它们属性为'1'。

{ '0': [], 
    '1': 
    { component: 'TestContent', 
    domain: 'src/domains/test/', 
    env: {things...} } } 

然后它有一个悲伤。

Error: Did not provide required argument component! 
at null.<anonymous> (/Users/zlandon/mercury/generator-mercury/node_modules/yeoman-generator/lib/base.js:359:33) 
at Array.forEach (native) 
at Base.checkRequiredArgs (/Users/zlandon/mercury/generator-mercury/node_modules/yeoman-generator/lib/base.js:355:19) 
at argument (/Users/zlandon/mercury/generator-mercury/node_modules/yeoman-generator/lib/base.js:321:8) 
at new module.exports.yeoman.generators.Base.extend.constructor (/Users/zlandon/mercury/generator-mercury/generators/component/index.js:11:10) 
at Environment.instantiate (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:297:10) 
at Environment.create (/usr/local/lib/node_modules/yo/node_modules/yeoman-environment/lib/environment.js:274:15) 
at composeWith (/Users/zlandon/mercury/generator-mercury/node_modules/yeoman-generator/lib/base.js:614:26) 
at module.exports.yeoman.generators.Base.extend.writing.app (/Users/zlandon/mercury/generator-mercury/generators/app/index.js:55:12) 
at /Users/zlandon/mercury/generator-mercury/node_modules/yeoman-generator/lib/base.js:421:16 

我相信我有因为外界的原因的节点的旧版本,但堆栈跟踪使其感觉哟特定的反正。

回答

1

更新自耕农发电机1.0

你需要传递两个参数和选项以同样的方式:

this.composeWith(require.resolve('generator-mercury/component'), { 
    optionName: 'my option', 
    argumentName: 'an argument' 
}); 

对于自耕农发电机0.X

之间的差异optionsarguments。你想:

this.composeWith('mercury:component', { 
    args: [this.props.domain + 'Content', this.props.path + '/'] 
}) 
+0

args必须是一个数组,而不是一个对象,但这是我需要去的方向。 – Hupfen

+0

正确,我更新了答案。 –

0

我使用的是自耕农发电机版本3.10.8

我可以传递参数给一个子发生器的唯一方法如下:

this.composeWith('myGen:subGen', { 
    arguments: ['value-for-first-arg'] 
}); 

命名论据选项对象或使用名为args的数组对我不起作用