import { defineCustomElement } from './dist/esm/es5/corporate-ui.core'
import * as CUI from './dist/esm/es5/corporate-ui.components'
const CUI_COMPONENTS = CUI.COMPONENTS
var collections = require('./dist/collection/collection-manifest.json')
var subComponents = {}

let collection = collections.components
collection.forEach(obj => {
  if (obj.dependencies.length > 0) {
    subComponents[obj.tag] = obj.dependencies
  }
})

function defineCustomElements(components) {
  if(components==='all') {
    defineCustomElement(window, CUI_COMPONENTS);
  } else {
    components.forEach(project_comp => {
      defineCustomElement(window, [findComponent(project_comp)])
      for (let tag in subComponents) {
        if (project_comp === tag) {
          subComponents[tag].forEach(tagDep => {
            defineCustomElement(window, [findComponent(tagDep)])
          })
        }
      }
    })
  }
}

function findComponent(name) {
  var val
  CUI_COMPONENTS.forEach(comp => {
    if (comp[0] === name) val = comp
  })
  return val
}

export { defineCustomElements }

@@ -132,50 +132,14 @@
 s'%0D%0A
-const CUI_COMPONENTS = CUI.COMPONENTS%0D%0Avar
+import
  col
@@ -151,18 +151,13 @@
 ons 
-= require(
+from 
 './d
@@ -200,33 +200,96 @@
 son'
-)
 %0D%0A
-var subComponents = %7B%7D
+%0D%0Aconst CUI_COMPONENTS = CUI.COMPONENTS%0D%0Alet subComponents = %7B%7D,%0D%0A    components = %5B%5D;
 %0D%0A%0D%0A
@@ -484,24 +484,22 @@
 lements(
-componen
+reques
 ts) %7B%0D%0A 
@@ -502,24 +502,22 @@
 %7B%0D%0A  if(
-componen
+reques
 ts==='al
@@ -531,36 +531,25 @@
     
-defineCustomElement(window, 
+components = %5B...
 CUI_
@@ -562,10 +562,9 @@
 ENTS
-);
+%5D
 %0D%0A  
@@ -577,24 +577,22 @@
  %7B%0D%0A    
-componen
+reques
 ts.forEa
@@ -623,37 +623,24 @@
     
-defineCustomElement(window, %5B
+components.push(
 find
@@ -662,17 +662,16 @@
 ct_comp)
-%5D
 )%0D%0A     
@@ -808,37 +808,24 @@
     
-defineCustomElement(window, %5B
+components.push(
 find
@@ -841,17 +841,16 @@
 (tagDep)
-%5D
 )%0D%0A     
@@ -891,16 +891,59 @@
 )%0D%0A  %7D%0D%0A
+  defineCustomElement(window, components)%0D%0A
 %7D%0D%0A%0D%0Afun

Fix import helpers