var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');
var streamify = require('gulp-streamify');
var _ = require('lodash');

var config = {
  main: 'js/main.js',
  out: 'bundle.js',
  dest: 'js/dist'
};

// for files that need to be run through browserify and reactify
// Mostly copied from:
// http://tylermcginnis.com/reactjs-tutorial-pt-2-building-react-applications-with-gulp-and-browserify/
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md
gulp.task('js', function() {
  var bfy_opts = {
    entries: [config.main],
    transform: [reactify],
    debug: true
  };
  _.assign(bfy_opts, watchify.args);
  var watcher = watchify(browserify(bfy_opts));

  function bundle() {
    watcher.bundle()
      .on('error', gutil.log.bind(gutil, 'Browserify Error'))
      .pipe(source(config.out))
      .pipe(gulp.dest(config.dest))
  }

  watcher.on('update', bundle);
  watcher.on('log', gutil.log);

  return bundle();
});

gulp.task('default', ['js']);

@@ -666,16 +666,22 @@
 task('js
+-watch
 ', funct
@@ -1136,16 +1136,304 @@
 );%0A%7D);%0A%0A
+gulp.task('js-build', function () %7B%0A  var bfy_opts = %7B%0A    entries: %5Bconfig.main%5D,%0A    transform: %5Breactify%5D%0A  %7D;%0A  return browserify(bfy_opts)%0A    .bundle()%0A    .on('error', gutil.log.bind(gutil, 'Browserify Error'))%0A    .pipe(source(config.out))%0A    .pipe(gulp.dest(config.dest));%0A%7D);%0A%0A
 gulp.tas
@@ -1449,13 +1449,19 @@
 t', %5B'js
+-watch
 '%5D);%0A

add command for building js bundle