/* global require, module */

const funnel = require('broccoli-funnel');
const concat = require('broccoli-concat');
// const staticCompiler = require('broccoli-static-compiler');
const mergeTrees = require('broccoli-merge-trees');
const babelTranspiler = require('broccoli-babel-transpiler');
const amdNameResolver = require('amd-name-resolver');
const lintedTree = require('./linted-tree');
const path = require('path');

const loaderDir = path.dirname(require.resolve('loader.js'));
const loader = funnel(loaderDir, {
  include: ['loader.js'],
  destDir: '.'
});

const shimRoot = 'shims';

const shims = babelTranspiler(mergeTrees([shimRoot, lintedTree(shimRoot)]), {
  getModuleId: function (name) {
    // Trim leading slash
    return name.slice(1);
  },
  moduleIds: true,
  modules: 'amdStrict',
  resolveModuleSource: amdNameResolver
});

const vendor = concat(mergeTrees([loader, shims]), {
  inputFiles: ['**/*.js'],
  outputFile: 'vendor.js'
});

const qunitDir = path.dirname(require.resolve('qunitjs'));
const qunit = funnel(qunitDir, {
  include: ['qunit.*'],
  destDir: 'vendor'
});

module.exports = mergeTrees([vendor, qunit]);

@@ -426,99 +426,390 @@
 nst 
-loaderDir = path.dirname(require.resolve('loader.js')
+vendorTrees = %5B%5D;%0A%0A%5B%0A  'node_modules/loader.js/loader.js',%0A  'node_modules/route-recognizer/dist/route-recognizer.js',%0A  'node_modules/fake-xml-http-request/fake_xml_http_request.js',%0A  'node_modules/pretender/pretender.js'%0A%5D.forEach(function (fullPath) %7B%0A  const dirname = path.dirname(fullPath
 );%0A
+  
 const 
-loader = funnel(loaderDir
+basename = path.basename(fullPath);%0A%0A  vendorTrees.push(funnel(dirname
 , %7B%0A
+  
   in
@@ -820,22 +820,21 @@
 e: %5B
-'loader.js'
+basename
 %5D,%0A
+  
   de
@@ -844,16 +844,23 @@
 ir: '.'%0A
+  %7D));%0A
 %7D);%0A%0Acon
@@ -887,22 +887,25 @@
 ';%0A%0A
-const shims = 
+vendorTrees.push(
 babe
@@ -1138,16 +1138,17 @@
 olver%0A%7D)
+)
 ;%0A%0Aconst
@@ -1179,23 +1179,19 @@
 ees(
-%5Bloader, shims%5D
+vendorTrees
 ), %7B

Make it easier to vendor in js