2016-01-07 32 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的數組對我不起作用