下载调用函数后的Yeoman生成器

时间:2016-02-03 12:03:31

标签: javascript node.js yeoman yeoman-generator

我正在尝试创建一个Yeoman生成器。 我需要知道在bowerInstall完成下载我的包之后如何调用函数是可能的。

这是我的代码:

Generator.prototype.myFiles = function myFiles() {
    console.info('download');
    this.bowerInstall('my-package-name', { save: true });
};

Generator.prototype.moveFiles = function moveFiles() {
    console.info('move');
};

下载后我需要移动一些文件,所以我必须等到所有包都下载完毕。

但是下载开始时不会立即调用函数moveFiles,而不是下载完成时。

在下载我的软件包之后是否还要调用moveFiles?

由于

1 个答案:

答案 0 :(得分:1)

首先,您应该阅读文档以了解Yeoman发电机的工作原理。对于这个问题,您询问的是任务队列和优先级:http://yeoman.io/authoring/running-context.html

安装操作发生在install。因此,要在安装完成后执行任何操作,您需要在end优先级内添加任务。

在你的情况下,它看起来像:

Generator.prototype.install = function myFiles() {
    console.info('download');
    this.bowerInstall('my-package-name', { save: true });
};

Generator.prototype.end = function moveFiles() {
    console.info('move');
};