javascript - 如何在 Yeoman 中等到复制操作完成

标签 javascript node.js yeoman

我正在编写一个 Yeoman 生成器,我想复制一个目录。您可以在下面找到代码。它工作正常,但是,在复制完成后,我想执行进一步的操作,如“npm install”。 由于复制是异步完成的,因此在复制所有文件之前执行“npm install”。我如何才能等到所有复制操作完成?

this.expandFiles('**', {
    cwd: this.sourceRoot(),
    dot: true
}).forEach(function (el) {

    this.copy(el, el);

}, this);

最佳答案

使用 .on 调用链 this.copy 并在 'end' 事件上运行您的函数。

this.copy(el, el)
  .on('end', function() {
     console.log("Copy is complete");
   });

关于javascript - 如何在 Yeoman 中等到复制操作完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24550663/

相关文章:

javascript - AngularJS 1.5 组件 ng-repeat 显示为表格

javascript - jquery .submit() 和变量的问题

javascript - 保护纯客户端主干应用程序

javascript - 在javascript中获取getter的调用参数

javascript - grunt-contrib-watch 静默退出

node.js - karma 开始引发用户代理错误

javascript - 我们可以获得 jQuery Chosen 插件的最后一个未选择的值吗?

javascript - 使用 Node.js 和 MySQL 查询函数回调的范围

javascript - 我们是否需要使用 `for..of`/`for..in` 循环声明变量

google-chrome - Grunt 服务器和 scss 源映射 : not serving the scss files (404)