为什么 Yeoman 不能在 exec 方法后执行异步回调?

Why Yeoman can't perform async callback after exec method?

我正在尝试执行一个 async callback in my action after the bowerInstall 方法已完成(问题与使用 exec 命令的其他方法相同)。我需要这个,因为没有它,下一个动作将在方法完成之前被触发。

     _-----_
    |       |    .--------------------------.
    |--(o)--|    |   Yeoman is frustrated   |
   `---------´   |     Help him please!     |
    ( _´U`_ )    '--------------------------'
    /___A___\
     |  ~  |
   __'.___.'__
 ´   `  |° ´ Y `

问题是 Yeoman 不支持方法回调中的异步回调。

default: {
  installPackage: function () {
    done = this.async();
    this.bowerInstall(this.packageName, function () {
      done();
    });
  },
  nextAction: function () {
    // Do stuff after installPackage is completed.
  }
}

在这种情况下,永远不会触发 bowerInstall 方法并且 运行 循环中断。

[编辑] 解决方案

正如 Simon Boudrias 所说,我不能在安装上下文中使用异步回调。我必须在安装后将我想要的任务 运行 放在最后的上下文中。

install: {
  installPackage: function () {
    this.bowerInstall(this.packageName);
  }
},
end: {
  nextAction: function () {
    // Do stuff after installPackage is completed.
  }
}

Yeoman 安装方法在 install 任务循环期间自动安排。

在此处使用 this.async() 会使进程陷入僵局。

此更改记录在 the v0.18.0 release. Might be worth it to detail that behavior more explicitly on the install methods documentation -> https://github.com/yeoman/yeoman.io/blob/master/app/authoring/dependencies.md