'use strict';

const babel = require('babel-core'),
  fs = require('fs');

// es5 build
babel.transformFile('./src/index.js', (err, result) => {
  if (err) throw err;

  let filename = './lib/index.js';
  fs.writeFile(filename, result.code, onWriteCompleted(filename));
});

// jsnext build

let jsnextOpts = {
  presets: [ [ 'es2015', { modules: false } ] ],
  babelrc: false
};

babel.transformFile('./src/index.js', jsnextOpts, (err, result) => {
  if (err) throw err;

  let filename = './lib/index.jsnext.js';
  fs.writeFile(filename, result.code, onWriteCompleted(filename));
});

function onWriteCompleted(filename) {
  return err => {
    if (err) throw err;
    console.log(`${filename} written`);
  }
}

@@ -12,13 +12,11 @@
 ';%0A%0A
-const
+var
  bab
@@ -117,16 +117,24 @@
 ex.js', 
+function
 (err, re
@@ -130,35 +130,32 @@
 ion(err, result)
- =%3E
  %7B%0A  if (err) th
@@ -158,35 +158,35 @@
 ) throw err;%0A%0A  
-let
+var
  filename = './l
@@ -288,19 +288,19 @@
  build%0A%0A
-let
+var
  jsnextO
@@ -427,16 +427,24 @@
 xtOpts, 
+function
 (err, re
@@ -448,19 +448,16 @@
  result)
- =%3E
  %7B%0A  if 
@@ -476,19 +476,19 @@
 err;%0A%0A  
-let
+var
  filenam
@@ -639,14 +639,21 @@
 urn 
-err =%3E
+function(err)
  %7B%0A 
@@ -695,19 +695,16 @@
 log(
-%60$%7B
 filename
 %7D wr
@@ -703,17 +703,20 @@
 name
-%7D
+ + '
  written
 %60);%0A
@@ -715,9 +715,9 @@
 tten
-%60
+'
 );%0A 

Make build file compatible with node 0.10.0