source: Dev/trunk/grunt-tasks/heroku.js @ 517

Last change on this file since 517 was 517, checked in by hendrikvanantwerpen, 11 years ago

Deployment and database management now done through Grunt. Look mom, no shell\!

File size: 2.3 KB
Line 
1var _ = require('underscore')
2  , path = require('path');
3
4module.exports = function(grunt) {
5   
6    grunt.registerTask(
7        'heroku-config',
8        "Get config values from heroku app and put them in grunt.config.",
9        function(){
10            var done = this.async();
11            var options = this.options({
12                keys: [],
13                output: 'herokuConfig'
14            });
15            if ( !options.app ) {
16                done(new Error(("Must specify the app name.")));
17            } else {
18                if ( options.keys.length === 0 ) {
19                    grunt.log.warn("Did not specify any config keys.");
20                }
21                var tasks = _.map(options.keys, function(key){
22                    return _.partial(getConfigValue,options.app,key);
23                });
24                grunt.util.async.series(tasks,function(error,results){
25                    if ( error ) {
26                        done(error);
27                    } else {
28                        var herokuConfig = {};
29                        _.each(results,function(result){
30                            _.extend(herokuConfig,result);
31                        });
32                        grunt.config.set(options.output,herokuConfig);
33                        done();
34                    }
35                });
36            }
37        });
38
39    function getConfigValue(app,key,callback) {
40        grunt.util.spawn({
41            cmd: 'heroku',
42            args: ['config:get',key,'--app',app]
43        }, function(error,result){
44            if ( error ) {
45                callback(error);
46            } else {
47                var value = grunt.util.normalizelf(result.stdout)
48                            .split(grunt.util.linefeed)[0];
49                result = {};
50                result[key] = value;
51                callback(null,result);
52            }
53        });
54    }
55
56    grunt.registerMultiTask(
57        'foreman',
58        "Run a foreman command in a directory.",
59        function(){
60            var options = this.options({
61                cmd: 'start',
62                cwd: '.'
63            });
64            var done = this.async();
65            grunt.util.spawn({
66                cmd: 'foreman',
67                args: [options.cmd],
68                opts: {
69                    cwd: options.cwd,
70                    stdio: 'inherit'
71                }
72            }, done);
73        });
74
75};
Note: See TracBrowser for help on using the repository browser.