獲取當(dāng)前任務(wù)依賴關(guān)系樹(shù)——在極少數(shù)情況下需要它。
通常,gulp 使用者不會(huì)使用 tree(),但它是公開(kāi)的,因此 CLI 可以顯示在 gulpfile 中定義的任務(wù)的依賴關(guān)系圖。
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])
參數(shù) | 類型 | 描述 |
---|---|---|
options | object | 詳情請(qǐng)見(jiàn)下文 選項(xiàng) 。 |
返回一個(gè)詳細(xì)描述已注冊(cè)的任務(wù)樹(shù)的對(duì)象——包含具有 'label' 和 'nodes' 屬性的嵌套對(duì)象(與 archy 兼容)。
每個(gè)對(duì)象可能有一個(gè) type 屬性,用于確定節(jié)點(diǎn)是 task 還是 function。
每個(gè)對(duì)象可能有一個(gè) branch 屬性,當(dāng) true 時(shí),該屬性指示節(jié)點(diǎn)是使用 series() 還是 parallel() 創(chuàng)建的。
name | type | default | note |
---|---|---|---|
deep | boolean | false | 如果為 true,則返回整個(gè)樹(shù)。如果為 false,則只返回頂級(jí)任務(wù)。 |
更多建議: