2016-02-08 40 views

回答

0

Yeoman提供composeWith()docs),您可以使用它来调用其他(子)生成器。

'use strict'; 

var generators = require('yeoman-generator'); 

module.exports = generators.Base.extend({ 
    constructor: function() { 
    generators.Base.apply(this, arguments); 
    this.argument('theName', { 
     type: String, 
     required: true 
    }); 
    }, 

    initializing: function() { 
    this.composeWith('my-generator:mysubgen1', { args: [this.theName] }); 
    this.composeWith('my-generator:mysubgen2', { args: [this.theName] }); 
    } 
}); 

在上面的例子中我假设你生成名为my-generator,有两个子发生器(mysubgen1mysubgen2)。

上面的代码将进入第三个子生成器,例如, doall。如果您致电$ yo my-generator:doall foobar,它现在将运行两个组合的子生成器,并将foobar作为第一个参数传递。

+0

谢谢,这是惊人的发现我错过了这个文档。 –

相关问题