const resolve = require('resolve');
const path = require('path');
const pluginUtils = require('./plugins/utils');

const Funnel = require('broccoli-funnel');
const Sass = require('broccoli-sass');
const MergeTrees = require('broccoli-merge-trees');
const BrowserSync = require('broccoli-browser-sync');

const Context = require('./plugins/context');
const CollectionsPlugin = require('./plugins/collections');
const NunjucksRender = require('./plugins/nunjucks-render');

const Paths = {
  IMAGES: 'src/images',
  BULMA: path.dirname(resolve.sync('bulma')),
  FONT_AWESOME: path.dirname(resolve.sync('font-awesome/css/font-awesome.css')),
  SASS: 'src/sass',
  SITE: 'src/site',
  LAYOUTS: 'src/layouts',
};

// Copy images to output as-is
const imageFiles = new Funnel(Paths.IMAGES, {
  destDir: 'images'
});

// Compile SASS to CSS
const cssFiles = new Sass([ Paths.SASS, Paths.BULMA, Paths.FONT_AWESOME ], 'bundle.scss', 'css/bundle.css');

// Pages are all markdown and nunjucks files under the site node
const pageFiles = new Funnel(Paths.SITE, { include: [ '**/*.md', '**/*.nj' ] });

// Generate context for each page file to be used when rendering
const contextFiles = new Context(pageFiles, Paths.SITE);

// Use context to generate collections and create (possibly) new context for the pages that need it
const contextWithCollections = new CollectionsPlugin(Paths.SITE, contextFiles);

// Render all page files using context to produce pages
const pages = new NunjucksRender(pageFiles, Paths.LAYOUTS, contextWithCollections, {
  defaultLayout: 'base.nj',
  layouts: [
    { pattern: 'docs/**/*.md', layout: 'docs.nj' }
  ]
});

let output = [ imageFiles, cssFiles, pages ];

// Watch for changes if running serve
if (process.argv.indexOf('serve') > 0) {
  output.push(new BrowserSync(output.slice(0)));
}

// Merge output
module.exports = new MergeTrees(output); 

@@ -611,28 +611,20 @@
 ome/
-css/font-awesome.css
+package.json
 ')),
@@ -872,16 +872,26 @@
 .BULMA, 
+path.join(
 Paths.FO
@@ -900,16 +900,24 @@
 _AWESOME
+, 'css')
  %5D, 'bun
@@ -947,16 +947,125 @@
 css');%0A%0A
+// Copy fonts%0Aconst fontFiles = new Funnel(path.join(Paths.FONT_AWESOME, 'fonts'), %7B%0A  destDir: 'fonts'%0A%7D);%0A%0A
 // Pages
@@ -1785,16 +1785,27 @@
 ssFiles,
+ fontFiles,
  pages %5D

Add fonts to output