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()
.
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?
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?
Thanks a lot!