javascript - Yeoman生成器下载后调用函数

标签 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?

谢谢

最佳答案

首先,您应该阅读文档以了解 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/

相关文章:

javascript - React 期望一个赋值或函数调用,但看到一个表达式

javascript - 在 node.js 上托管具有 javascript 依赖项的 html

javascript - 数据库表中唯一的随机字符串

javascript - 如何缩小我的网络应用程序?

javascript - 尝试运行命令时处理 Yeoman 自定义生成器中的错误事件

javascript - 将多层 PHP 数组转换为 Javascript 对象表示法

javascript - 我可以将 PHP 与 Javascript 结合使用吗?

gruntjs - yeoman 构建过程

javascript - 在 ember.js 中打印数组的问题

javascript - YAML 1.2 anchor 在 js-yaml 3.10.0 中不起作用?