gpt4 book ai didi

javascript - 如何在不将其列在 "grunt --help"中的情况下定义(内部)任务

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:34:33 25 4
gpt4 key购买 nike

我这样定义我的任务:

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

因为这是一个不应该被用户调用的任务,我想避免用 grunt --help 显示它。这可能吗?

我没有在 documentation 中找到任何相关的配置参数

最佳答案

您可以在帮助任务的 grunt 代码中看到这段代码 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.task._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};

现在这意味着对您的问题明确表示“否”。您不能注册不会显示在 --help 上的任务。

但是有一个issue filed on the grunt github repository正是针对您的问题(私有(private)任务)。随时 fork 存储库,让它工作并将其回馈社区 ;-)

关于javascript - 如何在不将其列在 "grunt --help"中的情况下定义(内部)任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17162743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com