Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Grunt config variable through command line

I have two different paths where I want to compile the mobile vs desktop code. I would like to alternate by passing a grunt parameter in the command line.

/**
 * @module Build
 * @class Build.Config
 * @static
 */

module.exports = function(grunt) {

var config = {};

    var NewPath;

    var env = grunt.option('target') || "Mobile";


    if (env == "Desktop") {  // MAKE THIS DYNAMIC WITH COMMAND LINE ARGUMENT
        newPath = "source/desktop/";
    }
    else {
       newPath = "source/mobile/";
    }

config.root = newPath;
config.stylesheets = config.root + '/stylesheets';
config.javascripts = config.root + '/javascripts';
config.images = config.root + '/images';
config.jsbin = config.javascripts + '/generated';
config.cssbin = config.stylesheets + '/generated';
config.docsbin = 'docs';



// Project configuration.
grunt.initConfig({

    'beautifier': {
        'options': {
            'indentSize': 1,
            'indentChar': '\t',
            'spaceAfterAnonFunction': true
        }
    },

    'beautify': {
        'files': [ config.javascripts + '/app/**/*.js' ]
    },

    'requirejs': require('./build/config/requirejs.js')(config),

    'watch': require('./build/config/watch.js')(config),
    'stylus':require('./build/config/stylus.js')(config)

});


// Default task.
grunt.registerTask('default', ['stylus:compile','requirejs']);      
grunt.registerTask('dev', ['stylus:dev']);

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-contrib-stylus');
};
like image 425
im_benton Avatar asked Jul 14 '26 20:07

im_benton


1 Answers

Turns out I was doing it right I just needed to pass in the variable for env correctly:

$ grunt --target="Desktop"

like image 128
im_benton Avatar answered Jul 21 '26 14:07

im_benton