下载调用函数后的 Yeoman 生成器
Yeoman generator after download call function
我正在尝试创建一个 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
安装操作发生在 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');
};
我正在尝试创建一个 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
安装操作发生在 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');
};