/**
 * Simple node script to be used via npm run.
 * 
 * Will transpile ES2015 client code to ES5
 * using the babelify transform, and then
 * use browserify/watchify to read all of the
 * require/import statements and put everything 
 * together into a single bundle file.
 * 
 */

const fs = require('fs');
const browserify = require('browserify');
const watchify = require('watchify');
const errorify = require('errorify');

function runBundler() {
  b.transform("babelify", {
      presets: ["es2015", "react"]
    })
    .bundle()
    .pipe(fs.createWriteStream("./public/js/app.js"));
}

const b = browserify({
  entries: ["./src/client/main.js"],
  cache: {},
  packageCache: {},
  plugin: [watchify, errorify]
});

b.on('update', function(ids) {
  console.log("Files changed: " + ids);
});
b.on('update', runBundler);

b.on('log', function(msg) {
  console.log("Watchify: new bundle created: " + msg);
});

runBundler();
@@ -452,79 +452,8 @@
 %0A  b
-.transform(%22babelify%22, %7B%0A      presets: %5B%22es2015%22, %22react%22%5D%0A    %7D)%0A    
 .bun
@@ -461,13 +461,8 @@
 le()
-%0A    
 .pip
@@ -635,16 +635,74 @@
 rorify%5D%0A
+%7D).transform(%22babelify%22, %7B%0A  presets: %5B%22es2015%22, %22react%22%5D%0A
 %7D);%0A%0Ab.o

fix bad watchify configuration that was causing long builds