text: import config from "../../base/config"
  import { isDev } from "../utils"
  
  /**
   * Генерируется дерево страниц с используемыми нодами
   * @param task
   */
  export default function (task)
  {
      const { store } = task
      const mainBundle = config.build.mainBundle
      const symbol = (store.symbol = [])
      const assets = (store.assets = [])
      const pages = store.pages || {}
      const tree = (store.tree = {})
  
      const allPages = {}
  
      if (pages[mainBundle])
          delete pages[mainBundle]
  
      Object.keys(pages).forEach(page => {
          if (!page)
              return
  
          Object.keys(pages[page].nodes).forEach(node => {
              if (!allPages[node])
                  allPages[node] = {
                      mod: []
                  }
  
              pages[page].nodes[node].mod.forEach(mod => {
                  if (allPages[node].mod.indexOf(mod) === -1)
                      allPages[node].mod.push(mod)
              })
          })
  
          pages[page].symbol.forEach(icon => {
              if (symbol.indexOf(icon) === -1) symbol.push(icon)
          })
  
          pages[page].assets.forEach( asset => {
              if (assets.indexOf(asset) === -1) assets.push(asset)
          })
      })
  
      if ((!isDev && config.build.bundles.length > 0) && pages[mainBundle])
          throw new Error(`\n\n\x1b[41mFAIL\x1b[0m: A page "\x1b[36m${mainBundle}\x1b[0m" have the same name as main bundle, please rename the page or change bundle name in config!`)
  
      pages[mainBundle] = {
          nodes: allPages
      }
  
      const parse = (key, page) => {
          if (pages[page].nodes[key].already)
              return
  
          pages[page].nodes[key].already = true
  
          if (!tree[page])
              tree[page] = {}
  
          return tree[page][key] = pages[page].nodes[key].mod
      }
  
      // generate tree
      Object.keys(pages).forEach(page => {
          Object.keys(pages[page].nodes).forEach(key => parse(key, page))
      })
  }