Last Updated: February 25, 2016
·
4.057K
· gasparotto

Conditional grunt task

Hi!

Are you need run a conditional grunt task? Maybe this tip can help you.

In this case, this script expect a grunt option named gui-version.

Ex: grunt publish --gui-version=VERSION

grunt.registerTask('publish', function() {
        if(!grunt.option('gui-version')) {
            grunt.fatal('ERROR: please, this task need that you send a param --gui-version=YOUR_VERSION');
        } else {
            grunt.task.run([
                'handlebars'
                , 'concat
                , 'copy:components'
                , 'uglify'
            ]);
        }
    });

You can use the same approach with params, and run:

grunt publish:myParam

grunt.registerTask('publish', function(myParam) {
        if(!myParam) {
            grunt.fatal('ERROR: i need a param');
        } else {
            grunt.task.run([
                'handlebars'
                , 'concat
                , 'copy:components'
                , 'uglify'
            ]);
        }
    });

This is it.