任何相關配置參數,可以在繁重的代碼看到的幫助任務這個代碼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];
}));
...
這意味着我們應該看一看那裏這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);
});
};
在這裏你可以看到,有一個循環遍歷所有已註冊的任務(目標grunt.t ask._tasks)。在循環內沒有檢查,所以現在必須看到這個對象被填充的位置。
,這是在做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};
現在,這意味着你的問題一個明確的NO。你不能註冊一個不會顯示在--help上的任務。
但是有一個issue filed on the grunt github repository正是你的問題(私人任務)。隨時分叉存儲庫,使這項工作,並將其送回社區;-)
謝謝。我會考慮這樣做(我的JavaScript是有限的) – dangonfast
拉請求在這裏:https://github.com/gruntjs/grunt/pull/821 – dangonfast