tree()#

获取当前任务依赖树 - 在极少数需要的情况下。

¥Fetches the current task dependency tree - in the rare case that it is needed.

一般来说,tree() 不会被 gulp 使用者使用,但它被公开,以便 CLI 可以显示 gulpfile 中定义的任务的依赖图。

¥Generally, tree() won't be used by gulp consumers, but it is exposed so the CLI can show the dependency graph of the tasks defined in a gulpfile.

用法#

¥Usage

示例 gulp 文件:

¥Example gulpfile:

const { series, parallel } = require('gulp');
function one(cb) {
// body omitted
cb();
}
function two(cb) {
// body omitted
cb();
}
function three(cb) {
// body omitted
cb();
}
const four = series(one, two);
const five = series(four,
parallel(three, function(cb) {
// Body omitted
cb();
})
);
module.exports = { one, two, three, four, five };

tree() 的输出:

¥Output for tree():

{
label: 'Tasks',
nodes: [ 'one', 'two', 'three', 'four', 'five' ]
}

tree({ deep: true }) 的输出:

¥Output for tree({ deep: true }):

{
label: "Tasks",
nodes: [
{
label: "one",
type: "task",
nodes: []
},
{
label: "two",
type: "task",
nodes: []
},
{
label: "three",
type: "task",
nodes: []
},
{
label: "four",
type: "task",
nodes: [
{
label: "<series>",
type: "function",
branch: true,
nodes: [
{
label: "one",
type: "function",
nodes: []
},
{
label: "two",
type: "function",
nodes: []
}
]
}
]
},
{
label: "five",
type: "task",
nodes: [
{
label: "<series>",
type: "function",
branch: true,
nodes: [
{
label: "<series>",
type: "function",
branch: true,
nodes: [
{
label: "one",
type: "function",
nodes: []
},
{
label: "two",
type: "function",
nodes: []
}
]
},
{
label: "<parallel>",
type: "function",
branch: true,
nodes: [
{
label: "three",
type: "function",
nodes: []
},
{
label: "<anonymous>",
type: "function",
nodes: []
}
]
}
]
}
]
}
]
}

签名#

¥Signature

tree([options])

参数#

¥Parameters

参数typenote
optionsobject详细见下文 选项

返回#

¥Returns

详细说明已注册任务树的对象 - 包含具有 'label''nodes' 属性的嵌套对象(与 archy 兼容)。

¥An object detailing the tree of registered tasks - containing nested objects with 'label' and 'nodes' properties (which is archy compatible).

每个对象可能有一个 type 属性,可用于确定该节点是 task 还是 function

¥Each object may have a type property that can be used to determine if the node is a task or function.

每个对象可能有一个 branch 属性,当 true 时,表明该节点是使用 series()parallel() 创建的。

¥Each object may have a branch property that, when true, indicates the node was created using series() or parallel().

选项#

¥Options

nametypedefaultnote
deepbooleanfalse如果为 true,则将返回整棵树。如果为 false,则仅返回顶层任务。