Yeoman生成器:复制所有文件后如何运行asynchronous命令

我正在写一个yeoman生成器。 所有文件复制后,我需要运行一些shell脚本。 发电机被称为小孩发电机,所以它应该等到脚本完成。
该脚本是通过spawn运行的一些命令文件:

 that.spawnCommand('createdb.cmd'); 

由于脚本依赖于由生成器创build的文件,因此不能在生成器的方法内运行,因为所有的复制/模板操作都是asynchronous的并且尚未执行:

 MyGenerator.prototype.serverApp = function serverApp() { if (this.useLocalDb) { this.copy('App_Data/createdb.cmd', 'App_Data/createdb.cmd'); // here I cannot run spawn with createdb.cmd as it doesn't exist } } 

所以我唯一能find的地方就是'end'事件处理器:

 var MyGenerator = module.exports = function MyGenerator (args, options, config) { this.on('end', function () { if (that.useLocalDb) { that.spawnCommand('createdb.cmd') } } } 

该脚本成功运行,但生成器比subprocess更早完成。 我需要告诉Yeoman等待我的孩子的过程。 像这样的东西:

 this.on('end', function (done) { this.spawnCommand('createdb.cmd') .on('close', function () { done(); }); }.bind(this)); 

但'end'处理程序没有“用餐”callback的参数。

这个怎么做?

更新
感谢@SimonBoudrias我得到了它的工作。
完整的工作代码如下。
顺便说一句: end方法在文档中描述

 var MyGenerator = module.exports = yeoman.generators.Base.extend({ constructor: function (args, options, config) { yeoman.generators.Base.apply(this, arguments); this.appName = this.options.appName; }, prompting : function () { // asking user }, writing : function () { // copying files }, end: function () { var that = this; if (this.useLocalDb) { var done = this.async(); process.chdir('App_Data'); this.spawnCommand('createdb.cmd').on('close', function () { that._sayGoodbay(); done(); }); process.chdir('..'); } else { this._sayGoodbay(); } }, _sayGoodbay: funciton () { // final words to user } }); 

end事件中从不触发任何操作。 这个事件将被实现者使用,而不是生成器本身。

在你的情况下:

 module.exports = generators.Base({ end: function () { var done = this.async(); this.spawnCommand('createdb.cmd').on('close', done); } });