gulp.tree()

2020-09-30 18:07 更新

gulp.tree()介紹

獲取當(dāng)前任務(wù)依賴關(guān)系樹——在極少數(shù)情況下需要它。

通常,gulp 使用者不會使用 tree(),但它是公開的,因此 CLI 可以顯示在 gulpfile 中定義的任務(wù)的依賴關(guān)系圖。

gulp.tree()用法

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: []
                }
              ]
            }
          ]
        }
      ]
    }
  ]
} 

gulp.tree()函數(shù)原型

tree([options])

參數(shù)

參數(shù)類型描述
optionsobject詳情請見下文 選項 。

返回值

返回一個詳細(xì)描述已注冊的任務(wù)樹的對象——包含具有 'label' 和 'nodes' 屬性的嵌套對象(與 archy 兼容)。

每個對象可能有一個 type 屬性,用于確定節(jié)點(diǎn)是 task 還是 function。

每個對象可能有一個 branch 屬性,當(dāng) true 時,該屬性指示節(jié)點(diǎn)是使用 series() 還是 parallel() 創(chuàng)建的。

選項

nametypedefaultnote
deepbooleanfalse如果為 true,則返回整個樹。如果為 false,則只返回頂級任務(wù)。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號