我怎样才能grunt.initConfig之前执行异步操作()? [英] How can I perform an asynchronous operation before grunt.initConfig()?

查看:289
本文介绍了我怎样才能grunt.initConfig之前执行异步操作()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有我的Gruntfile的设置,来执行解析来源档案解析在瑞德尔一些PHP源动态地计算出文件名和路径我需要在运行之前知道一些自动侦测魔法 grunt.initConfig()

Now I have my Gruntfile setup to perform some automatic detection magic like parsing sourcefiles to parse some PHP sources in roder to dynamically figure out filenames and paths I need to know before running grunt.initConfig().

不幸的是 grunt.initConfig()似乎并不能意味着要异步运行的,所以我看不出有什么办法让我的异步code我之前执行可以调用它。有没有窍门做到这一点还是我不得不重新编写同步我的检测例程?有没有简单的方法我的回调到达之前阻止执行?

Unfortunately grunt.initConfig() doesn't seem to be meant to be run asynchronously, so I see no way to have my asynchronous code executed before I can call it. Is there a trick to accomplish this or do I have to rewrite my detection routines synchronously? Is there any easy way to block execution before my callback has arrived?

里面咕噜任务,当然还有 this.async(),但 initConfig()那并不是'将不起作用。

Inside grunt tasks there is of course this.async(), but for initConfig() that doesn't work.

下面是一个精简的例子:

Here's a stripped down example:

function findSomeFilesAndPaths(callback) {
  // async tasks that detect and parse
  // and execute callback(results) when done
}

module.exports = function (grunt) {
  var config = {
    pkg: grunt.file.readJSON('package.json'),
  }

  findSomeFilesAndPaths(function (results) {
    config.watch = {
      coffee: {
        files: results.coffeeDir + "**/*.coffee",
        tasks: ["coffee"]
         // ...
      }
    };

    grunt.initConfig(config);

    grunt.loadNpmTasks "grunt-contrib-coffee"
    // grunt.loadNpmTasks(...);
  });
};

任何好的想法如何完成这件事?

Any good ideas how to get this done?

非常感谢!

推荐答案

通过改写,同步解决的风格。 ShellJS 派上了用场,特别是对执行同步shell命令。

Solved by rewriting, synchronous style. ShellJS came in handy, especially for synchronously executing shell commands.

这篇关于我怎样才能grunt.initConfig之前执行异步操作()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆