var _ = require('underscore') , path = require('path'); module.exports = function(grunt) { grunt.registerTask( 'heroku-config', "Get config values from heroku app and put them in grunt.config.", function(){ var done = this.async(); var options = this.options({ keys: [], output: 'herokuConfig' }); if ( !options.app ) { done(new Error(("Must specify the app name."))); } else { if ( options.keys.length === 0 ) { grunt.log.warn("Did not specify any config keys."); } var tasks = _.map(options.keys, function(key){ return _.partial(getConfigValue,options.app,key); }); grunt.util.async.series(tasks,function(error,results){ if ( error ) { done(error); } else { var herokuConfig = {}; _.each(results,function(result){ _.extend(herokuConfig,result); }); grunt.config.set(options.output,herokuConfig); done(); } }); } }); function getConfigValue(app,key,callback) { grunt.util.spawn({ cmd: 'heroku', args: ['config:get',key,'--app',app] }, function(error,result){ if ( error ) { callback(error); } else { var value = grunt.util.normalizelf(result.stdout) .split(grunt.util.linefeed)[0]; result = {}; result[key] = value; callback(null,result); } }); } grunt.registerMultiTask( 'foreman', "Run a foreman command in a directory.", function(){ var options = this.options({ cmd: 'start', cwd: '.' }); var done = this.async(); grunt.util.spawn({ cmd: 'foreman', args: [options.cmd], opts: { cwd: options.cwd, stdio: 'inherit' } }, done); }); };