tree()
优质
小牛编辑
134浏览
2023-12-01
获取当前任务依赖关系树——在极少数情况下需要它。
通常,gulp 使用者不会使用 tree()
,但它是公开的,因此 CLI 可以显示在 gulpfile 中定义的任务的依赖关系图。
用法
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()
的输出:
{
label: 'Tasks',
nodes: [ 'one', 'two', 'three', 'four', 'five' ]
}
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: []
}
]
}
]
}
]
}
]
}
函数原型
tree([options])
参数
参数 | 类型 | 描述 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
options | object | 详情请见下文 返回值 返回一个详细描述已注册的任务树的对象——包含具有 每个对象可能有一个 每个对象可能有一个 选项
|