var gulp = require('gulp');
var gutil = require('gulp-util');
var path = require('path');
var spawnSync = require('child_process').spawnSync;
var url = require('url');
var webpack = require('webpack');

var ENVIRONMENT = process.env.NODE_ENV || 'development';
var PRODUCTION = ENVIRONMENT === 'production';

var CHROME_BUILD_PATH = 'chrome/build';
var CHROME_ASSETS_SOURCE_PATH = 'chrome/src/{html/*,img/*,manifest.json}';

var WEBPACK_CONFIG = {
  devtool: PRODUCTION ? null : 'source-map',
  entry: {
    'js/index': './chrome/src/js/index'
  },
  output: {
    path: CHROME_BUILD_PATH,
    filename: '[name].js'
  },
  module: {
    loaders: [{
      loader: 'babel',
      test: /.jsx?$/,
      exclude: /node_modules/,
      query: {
        presets: ['es2015', 'react'],
        plugins: ['transform-object-rest-spread']
      }
    }]
  },
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(ENVIRONMENT)
      }
    }),
    PRODUCTION && new webpack.optimize.DedupePlugin(),
    PRODUCTION && new webpack.optimize.UglifyJsPlugin()
  ].filter(Boolean)
}

gulp.task('scripts', function(done) {
  webpack(WEBPACK_CONFIG, function(error, stats) {
    if (error) throw new gutil.PluginError('webpack:build', error);

    gutil.log('[webpack:build]', '\n' + stats.toString({ chunks: false, colors: true }));

    done();
  });
});

gulp.task('watch:scripts', function(done) { //eslint-disable-line no-unused-vars
  var config = Object.assign({}, WEBPACK_CONFIG, { watch: true });
  var compiler = webpack(config);

  compiler.watch({}, function(error, stats) {
    if (error) throw new gutil.PluginError('webpack:build', error);

    gutil.log('[webpack:build]', stats.toString({ colors: true }));
    gutil.log('[webpack:build]', 'Built scripts');
  });
});

gulp.task('styles', function() {
  var isDevelopment = config.environment !== 'production';
  var src = path.join(config.less.src, '**/[^_]*.less');

  return gulp.src(src)
    .pipe(gulpIf(isDevelopment, sourcemaps.init()))
    .pipe(less({
      paths: config.less.paths
    }).on('error', function(error) {
      gutil.log('[less:build]', '[ERROR]', error.message);

      this.emit('end', new gutil.PluginError('styles', error, {
        showStack: true
      }));
    }))
    .pipe(autoprefixer())
    .pipe(gulpIf(!isDevelopment, cssnano({ zindex: false })))
    .pipe(gulpIf(isDevelopment, sourcemaps.write('.')))
    .pipe(gulp.dest(config.less.dest));
});

gulp.task('assets', function() {
  return gulp.src(CHROME_ASSETS_SOURCE_PATH)
    .pipe(gulp.dest(CHROME_BUILD_PATH));
});

gulp.task('watch:assets', function() {
  gulp.watch(CHROME_ASSETS_SOURCE_PATH, ['assets']);
});

gulp.task('watch:styles', function() {
  gulp.watch(path.join(__dirname, '../../**/*.less'), ['styles']);
});

gulp.task('clean', function() {
  spawnSync('rm', ['-rf', CHROME_BUILD_PATH]);
});

gulp.task('watch', ['watch:scripts', 'watch:styles', 'watch:assets']);
gulp.task('build', ['scripts', 'styles', 'assets']);

@@ -1807,674 +1807,8 @@
 );%0A%0A
-gulp.task('styles', function() %7B%0A  var isDevelopment = config.environment !== 'production';%0A  var src = path.join(config.less.src, '**/%5B%5E_%5D*.less');%0A%0A  return gulp.src(src)%0A    .pipe(gulpIf(isDevelopment, sourcemaps.init()))%0A    .pipe(less(%7B%0A      paths: config.less.paths%0A    %7D).on('error', function(error) %7B%0A      gutil.log('%5Bless:build%5D', '%5BERROR%5D', error.message);%0A%0A      this.emit('end', new gutil.PluginError('styles', error, %7B%0A        showStack: true%0A      %7D));%0A    %7D))%0A    .pipe(autoprefixer())%0A    .pipe(gulpIf(!isDevelopment, cssnano(%7B zindex: false %7D)))%0A    .pipe(gulpIf(isDevelopment, sourcemaps.write('.')))%0A    .pipe(gulp.dest(config.less.dest));%0A%7D);%0A%0A
 gulp
@@ -2028,119 +2028,8 @@
 );%0A%0A
-gulp.task('watch:styles', function() %7B%0A  gulp.watch(path.join(__dirname, '../../**/*.less'), %5B'styles'%5D);%0A%7D);%0A%0A
 gulp
@@ -2139,30 +2139,13 @@
 tch:
-scripts', 'watch:style
+asset
 s', 
@@ -2151,20 +2151,21 @@
  'watch:
-asse
+scrip
 ts'%5D);%0Ag
@@ -2197,18 +2197,8 @@
 ts',
- 'styles',
  'as

Remove styles tasks from gulpfile