我正在尝试创建一个 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?
谢谢
最佳答案
首先,您应该阅读文档以了解 Yeoman 生成器的工作原理。对于这个问题,您询问的是任务队列和优先级:http://yeoman.io/authoring/running-context.html
安装操作发生在安装
中。因此,要在安装完成后执行任何操作,您需要将任务添加到 end
优先级中。
就您而言,它看起来像:
Generator.prototype.install = function myFiles() {
console.info('download');
this.bowerInstall('my-package-name', { save: true });
};
Generator.prototype.end = function moveFiles() {
console.info('move');
};
关于javascript - Yeoman生成器下载后调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35176561/