const gulp = require('gulp');
const path = require('path');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const eslint = require('gulp-eslint');
const manifest = require('./package.json');

const mainFile = manifest.main;
const packageName = manifest.name;
const destinationDirectory = path.dirname(mainFile);
const exportFileName = path.basename(mainFile, path.extname(mainFile));


function build() {
  return gulp.src('./src/formwood.js')
    .pipe(webpackStream({
      externals: {
        "react": "react"
      },
      output: {
        filename: `${exportFileName}.js`,
        library: packageName,
        libraryTarget: 'umd'
      },
      module: {
        loaders: [{
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
        }]
      }
    }))
    .pipe(gulp.dest(destinationDirectory));
}

function test() {
  require('babel-register');

  gulp.src('src/**/*.js')
    .pipe(babel())
    .pipe(istanbul())
    .pipe(istanbul.hookRequire())
    .on('finish', function() {
      return gulp.src('test/unit/**/*.js', {read: false})
        .pipe(mocha({
           reporter: 'dot',
           ignoreLeaks: false
        }))
        .pipe(istanbul.writeReports());
    });
}

function lint() {
  return gulp.src('src/**/*')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

gulp.task('build', build);
gulp.task('test', test);
gulp.task('lint', lint);
gulp.task('default', ['build']);

const gulp = require('gulp');
const path = require('path');
const webpackStream = require('webpack-stream');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');
const eslint = require('gulp-eslint');
const manifest = require('./package.json');

const mainFile = manifest.main;
const packageName = manifest.name;
const destinationDirectory = path.dirname(mainFile);
const exportFileName = path.basename(mainFile, path.extname(mainFile));


function build() {
  return gulp.src('./src/formwood.js')
    .pipe(webpackStream({
      externals: {
        "react": "react"
      },
      output: {
        filename: `${exportFileName}.js`,
        library: packageName,
        libraryTarget: 'umd'
      },
      module: {
        loaders: [{
          test: /\.js$/,
          exclude: /node_modules/,
          loader: 'babel-loader'
        }]
      }
    }))
    .pipe(gulp.dest(destinationDirectory));
}

function test() {
  require('babel-core/register');

  gulp.src('src/**/*.js')
    .pipe(babel())
    .pipe(istanbul())
    .pipe(istanbul.hookRequire())
    .on('finish', function() {
      return gulp.src('test/unit/**/*.js', {read: false})
        .pipe(mocha({
           reporter: 'dot',
           ignoreLeaks: false
        }))
        .pipe(istanbul.writeReports());
    });
}

function lint() {
  return gulp.src('src/**/*')
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failAfterError());
}

gulp.task('build', build);
gulp.task('test', test);
gulp.task('lint', lint);
gulp.task('default', ['build']);

Use babel-core/register