组合生成器未找到通过 composeWith 传递的参数
Arguments passed via composeWith not found by composed generator
约曼版本:1.4.8
NPM:2.11.3
节点:0.12.7
生成器调用其自己的子生成器时出现了额外的小问题,但这并不太疯狂,那部分工作得很好。
我的parent里有这个:
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”中看到 command-line 参数。
{ '0': [ 'test', '.' ],
'1': { env: {things...} } }
从 parent 生成器调用时,它们是“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-specific 无论如何。
更新 yeoman-generator 1.0
您需要以相同的方式传递参数和选项:
this.composeWith(require.resolve('generator-mercury/component'), {
optionName: 'my option',
argumentName: 'an argument'
});
对于yeoman-generator0.x
options
和 arguments
有区别。你想要:
this.composeWith('mercury:component', {
args: [this.props.domain + 'Content', this.props.path + '/']
})
我使用的是 yeoman-generator 版本 3.10.8
我可以将参数传递给子生成器的唯一方法如下:
this.composeWith('myGen:subGen', {
arguments: ['value-for-first-arg']
});
在选项对象中命名参数或使用名为 args 的数组对我不起作用
约曼版本:1.4.8 NPM:2.11.3 节点:0.12.7
生成器调用其自己的子生成器时出现了额外的小问题,但这并不太疯狂,那部分工作得很好。
我的parent里有这个:
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”中看到 command-line 参数。
{ '0': [ 'test', '.' ],
'1': { env: {things...} } }
从 parent 生成器调用时,它们是“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-specific 无论如何。
更新 yeoman-generator 1.0
您需要以相同的方式传递参数和选项:
this.composeWith(require.resolve('generator-mercury/component'), {
optionName: 'my option',
argumentName: 'an argument'
});
对于yeoman-generator0.x
options
和 arguments
有区别。你想要:
this.composeWith('mercury:component', {
args: [this.props.domain + 'Content', this.props.path + '/']
})
我使用的是 yeoman-generator 版本 3.10.8
我可以将参数传递给子生成器的唯一方法如下:
this.composeWith('myGen:subGen', {
arguments: ['value-for-first-arg']
});
在选项对象中命名参数或使用名为 args 的数组对我不起作用