Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a (internal) task without having it listed it in "grunt --help"

I am defining my tasks like this:

grunt.registerTask('tmp', 'An internal task', [
    'clean:tmp',
    'jshint',
    'ember_templates',
    'neuter',
    'copy:tmp',
    'replace:tmp',
]);

since this is a task which is not supposed to be called by the user, I would like to avoid showing it with grunt --help. Is this possible?

I have not found any related config parameter in the documentation

like image 998
blueFast Avatar asked Nov 12 '22 03:11

blueFast


1 Answers

you can see in the grunt-code for the help task this code which loops over an array of all tasks - currently starts at line 106

exports.tasks = function() {
  grunt.log.header('Available tasks');
  if (exports._tasks.length === 0) {
    grunt.log.writeln('(no tasks found)');
  } else {
     exports.table(exports._tasks.map(function(task) {
       var info = task.info;
       if (task.multi) { info += ' *'; }
       return [task.name, info];
     }));
  ...

this means we should take a look where this array is filled - (currently starts at line 94):

exports.initTasks = function() {
  // Initialize task system so that the tasks can be listed.
  grunt.task.init([], {help: true});

  // Build object of tasks by info (where they were loaded from).
  exports._tasks = [];
  Object.keys(grunt.task._tasks).forEach(function(name) {
    exports.initCol1(name);
    var task = grunt.task._tasks[name];
    exports._tasks.push(task);
  });
};

here you can see, that there is a loop over all registered tasks (the object grunt.task._tasks). inside the loop there is no check, so now must see where this object is filled.

and this is done in the registerTask-prototype-method (currently line 78):

// Register a new task.
Task.prototype.registerTask = function(name, info, fn) {

    ... some other code

    // Add task into cache.
    this._tasks[name] = {name: name, info: info, fn: fn};

now that means a clear NO for your question. you can not register a task which will not be shown on --help.

but there is an issue filed on the grunt github repository for exactly your problem (private tasks). feel free to fork the repository, make that work and give it back to the community ;-)

like image 79
hereandnow78 Avatar answered Nov 14 '22 22:11

hereandnow78