【问题标题】:YEOMAN run multiple sub generators in one functionYEOMAN 在一个函数中运行多个子生成器
【发布时间】:2016-02-08 13:34:29
【问题描述】:

我有一个基于角度的生成器,其中包含三个用于控制器指令和服务的子生成器。我想运行一个函数,它接受 NAME 变量/输入并同时运行所有这三个函数,而不必分别运行每个函数。

【问题讨论】:

    标签: yeoman yeoman-generator


    【解决方案1】:

    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 作为第一个参数传递。

    【讨论】:

    • 谢谢你,我很惊讶我在文档中错过了这个。
    猜你喜欢
    • 2018-07-18
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2015-06-26
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    相关资源
    最近更新 更多