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