[TOC]
  • tree()用法函数原型参数返回值选项

tree()

获取当前任务依赖关系树——在极少数情况下需要它。

通常,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 详情请见下文 选项 。

返回值

返回一个详细描述已注册的任务树的对象——包含具有 ‘label’ 和 ‘nodes’ 属性的嵌套对象(与 archy 兼容)。

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

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

选项

name type default note
deep boolean false 如果为 true,则返回整个树。如果为 false,则只返回顶级任务。