/* globals module */

// 'use strict'

const pkg = require('./package.json')
const Funnel = require('broccoli-funnel')

const flatiron = require('broccoli-flatiron')
const fs = require('fs')
const mergeTrees = require('broccoli-merge-trees')
const path = require('path')
const svgstore = require('broccoli-svgstore')

module.exports = {
  name: 'ember-frost-core',

  included: function (app) {
    // Addons - see: https://github.com/ember-cli/ember-cli/issues/3718
    if (typeof app.import !== 'function' && app.app) {
      this.app = app = app.app
    }

    this._super.included(app)

    if (app) {
      app.import(path.join('vendor', 'google', 'fonts', 'roboto', 'Roboto-Bold.woff2'), { destDir: 'assets/fonts' })
      app.import(path.join('vendor', 'google', 'fonts', 'roboto', 'Roboto-Light.woff2'), { destDir: 'assets/fonts' })
      app.import(path.join('vendor', 'google', 'fonts', 'roboto', 'Roboto-LightItalic.woff2'), { destDir: 'assets/fonts' })
      app.import(path.join('vendor', 'google', 'fonts', 'roboto', 'Roboto-Medium.woff2'), { destDir: 'assets/fonts' })
      app.import(path.join('vendor', 'google', 'fonts', 'roboto', 'Roboto-Regular.woff2'), { destDir: 'assets/fonts' })
      app.import(path.join('vendor', 'google', 'fonts', 'roboto', 'stylesheet.css'))
    }

    if (typeof app.import === 'function') {
      app.import(app.bowerDirectory + '/perfect-scrollbar/js/perfect-scrollbar.js')
      app.import(app.bowerDirectory + '/perfect-scrollbar/css/perfect-scrollbar.css')
    }
  },

  init: function (app) {
    this.options = this.options || {}
    this.options.babel = this.options.babel || {}
    this.options.babel.optional = this.options.babel.optional || []

    if (this.options.babel.optional.indexOf('es7.decorators') === -1) {
      this.options.babel.optional.push('es7.decorators')
    }
  },

  treeForAddon: function (tree) {
    // Flatten the svgs into js imports with inline svg using flatiron and merge the result into the addon tree
    var svgPaths = []

    var addonSvgRoot = path.join(this.root, 'public', 'svgs')
    if (fs.existsSync(addonSvgRoot)) {
      svgPaths.push(addonSvgRoot)
    }

    if (this.project.name() !== pkg.name) {
      var appSvgRoot = path.join(this.project.root, 'public', 'svgs')
      if (fs.existsSync(appSvgRoot)) {
        svgPaths.push(appSvgRoot)
      }
    }

    var dummySvgRoot = path.join(this.project.root, 'tests', 'dummy', 'public', 'svgs')
    if (fs.existsSync(dummySvgRoot)) {
      svgPaths.push(dummySvgRoot)
    }

    if (svgPaths.length > 0) {
      var svgFunnel = new Funnel(mergeTrees(svgPaths, {overwrite: true}), {
        include: [new RegExp(/\.svg$/)]
      })

      var flattenedSvgs = flatiron(svgFunnel, {
        outputFile: 'svgs.js',
        trimExtensions: true
      })

      tree = mergeTrees([tree, flattenedSvgs], {overwrite: true})
    }

    return this._super.treeForAddon.call(this, tree)
  },

  treeForPublic: function () {
    var svgRoot = path.join(this.root, 'public', 'svgs')
    return svgstore(new Funnel(svgRoot), {outputFile: '/assets/frost-core-icons.svg'})
  }
}

@@ -36,51 +36,11 @@
 t'%0A%0A
-const pkg = require('./package.json')%0Aconst
+var
  Fun
@@ -73,21 +73,19 @@
 nnel')%0A%0A
-const
+var
  flatiro
@@ -117,21 +117,19 @@
 tiron')%0A
-const
+var
  fs = re
@@ -140,21 +140,19 @@
 e('fs')%0A
-const
+var
  mergeTr
@@ -189,21 +189,19 @@
 trees')%0A
-const
+var
  path = 
@@ -220,13 +220,11 @@
 h')%0A
-const
+var
  svg
@@ -1830,115 +1830,66 @@
     
-// Flatten the svgs into js imports with inline svg using flatiron and merge the result into the addon
+var addonTree = this._super.treeForAddon.call(this,
  tree
+)%0A
 %0A   
@@ -1909,33 +1909,14 @@
  = %5B
-%5D%0A
 %0A    
-var addonSvgRoot =
+ 
  pat
@@ -1954,457 +1954,191 @@
 gs')
-%0A    if (fs.existsSync(addonSvgRoot)) %7B%0A      svgPaths.push(addonSvgRoot)%0A    %7D%0A%0A    if (this.project.name() !== pkg.name) %7B%0A      var appSvgRoot = path.join(this.project.root, 'public', 'svgs')%0A      if (fs.existsSync(appSvgRoot)) %7B%0A        svgPaths.push(appSvgRoot)%0A      %7D%0A    %7D%0A%0A    var dummySvgRoot = path.join(this.project.root, 'tests', 'dummy', 'public', 'svgs')%0A    if (fs.existsSync(dummySvgRoot)) %7B%0A      svgPaths.push(dummySvgRoot)%0A    %7D
+,%0A      path.join(this.project.root, 'public', 'svgs'),%0A      path.join(this.project.root, 'tests', 'dummy', 'public', 'svgs')%0A    %5D%0A      .filter((svgPath) =%3E fs.existsSync(svgPath))
 %0A%0A  
@@ -2163,17 +2163,19 @@
 gth 
-%3E
+===
  0) %7B%0A  
     
@@ -2166,24 +2166,52 @@
  === 0) %7B%0A  
+    return addonTree%0A    %7D%0A%0A
     var svgF
@@ -2278,18 +2278,16 @@
 %7B%0A      
- 
- 
 include:
@@ -2310,32 +2310,28 @@
 svg$/)%5D%0A    
-  
 %7D)%0A%0A
-  
     var flat
@@ -2370,18 +2370,16 @@
 %7B%0A      
-  
 outputFi
@@ -2383,16 +2383,41 @@
 tFile: '
+modules/ember-frost-core/
 svgs.js'
@@ -2418,18 +2418,16 @@
 gs.js',%0A
-  
       tr
@@ -2449,26 +2449,24 @@
 rue%0A    
-  
 %7D)%0A%0A    
   tree =
@@ -2461,16 +2461,14 @@
     
-  tree =
+return
  mer
@@ -2476,17 +2476,22 @@
 eTrees(%5B
-t
+addonT
 ree, fla
@@ -2526,68 +2526,8 @@
 e%7D)%0A
-    %7D%0A%0A    return this._super.treeForAddon.call(this, tree)%0A
   %7D,

Fix build