Yeoman版本: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});
},
如果我直接调用mercury:component并检查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
我认为由于外部原因,我有一个较旧版本的节点,但是堆栈跟踪使得它感觉特定于Yo特定。
答案 0 :(得分:3)
更新yeoman-generator 1.0
您需要以相同的方式传递参数和选项:
this.composeWith(require.resolve('generator-mercury/component'), {
optionName: 'my option',
argumentName: 'an argument'
});
对于yeoman-generator 0.x
options
和arguments
之间存在差异。你想要:
this.composeWith('mercury:component', {
args: [this.props.domain + 'Content', this.props.path + '/']
})
答案 1 :(得分:0)
我正在使用yeoman-generator版本3.10.8
我可以将参数传递给子生成器的唯一方法如下:
this.composeWith('myGen:subGen', {
arguments: ['value-for-first-arg']
});
在options对象中命名参数或使用名为args的数组对我不起作用