How to disable a task in Grunt?

When used grunt.loadNpmTasks, the command line task is automatically available to the command line. This may be useful, but sometimes I would like this task to be confidential, so it can be used in the Grunt file, but not accessible to the command line.

Here is a contrived example. If I do this:

module.exports = function(grunt) {

    grunt.initConfig({  
        clean: {
            test: ['test'],
            release: ['release']
        },  
    });

    grunt.loadNpmTasks('grunt-contrib-clean');

    grunt.registerTask('build', 'Build the project.', function() {
        console.log("building project");
    });
    grunt.registerTask('release', ['clean:release', 'build']);

};

... I can use the following command:

$ grunt release

However, this option is also available, and both clean:release, and will be executed clean:test:

$ grunt clean

I do not want it. I want to control what can be called from the command line, since I could not foresee some undesirable effects if the user directly calls some tasks or subtasks.

clean, , , , clean ( ), , clean:

grunt.registerTask('clean', ['clean:release']);p >

+4
1

grunt.task.renameTask

var ticks = +new Date();
var clean = 'clean-' + ticks;

grunt.task.renameTask('clean', clean);
grunt.registerTask('release', [clean + ':release', 'build']);
grunt.config.set(clean, grunt.config.get('clean'));

, target

+2

All Articles