javascript - How can I perform an asynchronous operation before grunt.initConfig()? -


now have gruntfile setup perform automatic detection magic parsing sourcefiles parse php sources in roder dynamically figure out filenames , paths need know before running grunt.initconfig().

unfortunately grunt.initconfig() doesn't seem meant run asynchronously, see no way have asynchronous code executed before can call it. there trick accomplish or have rewrite detection routines synchronously? there easy way block execution before callback has arrived?

inside grunt tasks there of course this.async(), initconfig() doesn't work.

here's stripped down example:

function findsomefilesandpaths(callback) {   // async tasks detect , parse   // , 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 ideas how done?

thanks lot!

i task since grunt sync or if can make findsomefilesandpaths sync.

grunt.initconfig({   initdata: {},   watch: {     coffee: {       files: ['<%= initdata.coffeedir %>/**/*.coffee'],       tasks: ['coffee'],     },   }, });  grunt.registertask('init', function() {   var done = this.async();   findsomefilesandpaths(function(results) {     // set our initdata in our config     grunt.config(['initdata'], results);     done();   }); });  // optional if want // run init task first grunt.renametask('watch', 'actualwatch'); grunt.registertask('watch', ['init', 'actualwatch']); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -