为什么 _directory 函数在 yeoman.generators.Base 子类中被调用四次?

Why the _directory function is called four times in a yeoman.generators.Base subclass?

下面是我如何扩展 yeoman 生成器 Base class

module.exports = yeoman.generators.Base.extend({
  prompting: function () {
    var done = this.async();

    // Have Yeoman greet the user.
    this.log(yosay(
      'Welcome to the cool ' + chalk.red('generator-zeetings') + ' generator!'
    ));

    var prompts = [{
      ...  
    }];

    this.prompt(prompts, function (props) {
      this.props = props;
      // ...
      done();
    }.bind(this));
  },

  _directory: function (source, destination) {
      // Simplified for this question
      var src = path.join(source, 'index.html');
      var dest = path.join(destination, 'final.html');
      console.log('Copy from ' + src + ' to ' + dest);
      this.fs.copyTpl(
        this.templatePath(src),
        this.destinationPath(dest),
        this.props
      );

  },

  prepareApp: function () {
    this._directory(this.templatePath(), this.destinationRoot('app'));
  },

  prepareData: function () {
    this._directory(this.templatePath(), this.destinationRoot('data'));
  },

  writing: function () {
    this.prepareApp();
    this.prepareData();
  },
});

我发现由于某种原因辅助函数 _directory 被调用了 4 次。

我预计该函数仅被调用两次,一次用于 app,另一次用于文件夹 data,由 writing 函数调用。

事实证明,如果我将 _ 添加到 appendAppappendData 之前,生成器将按照我的预期运行。

我想了解的是:

1) 我似乎没有在 yeoman 网站上找到这种行为的记录。这种行为 ('calling every public method in the subclass') 是预期的吗?

2) 如果这是预期的行为,我如何控制调用这些 public 方法的顺序?

参考文档:http://yeoman.io/authoring/running-context.html

yeoman-generator 中的每个函数都是一个任务。任务都是 运行 自动的,并根据它们的优先级排序(优先级由 function/object 名称定义)。

以下划线开头的函数名称被认为是私有的,不会被 运行ned。