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

I define my tasks as follows:

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

since this is a task that should not be called by the user, I would like not to show it with grunt --help . Is it possible?

I did not find any related configuration parameter in the documentation

+4
source share
1 answer

you can see in the grunt file for reference this code that traverses 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 that we have to 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 (grunt.task._tasks object). there is no check inside the loop, so now you need to see where this object is filled.

and this is done in 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 this means that there is NO for your question. you cannot register a task that will not display on --help.

but there is a problem submitted to the guntum grunt repository for your problem (private tasks). Feel free to fork the repository, do this work and give it to the community; -)

+1
source

Source: https://habr.com/ru/post/1486756/


All Articles