<commit_before>import { logError } from '../lib/log';
import fs from 'fs';
import es from 'event-stream';
import config from '../lib/config';
import gulp from 'gulp';
import pump from 'pump';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import browserSync from 'browser-sync';

import sourcemaps from 'gulp-sourcemaps';
import browserify from 'browserify';
import babelify from 'babelify';
import watchify from 'watchify';

/**
 * Javascript bundle with Browserify and Babel transpiler
 */
const bundle = (args) => {
  return pump([
    args.instance.bundle()
      .on('error', err => logError(err)),
    source(args.bundle),
    buffer(),
    sourcemaps.init({ loadMaps: true }),
    sourcemaps.write('./'),
    gulp.dest(config.get('tasks.javascript.dist')),
  ]);
};

const getBrowserifyInstance = (args) => {
  const options = { entries: config.get('tasks.javascript.main') };
  const instance = args && args.watch ? watchify(browserify(options)) : browserify(options);
  return instance.transform(babelify, args.config);
};

gulp.task('javascript:build', () => {
  const entries = config.get('tasks.javascript.bundles');
  return es.merge(entries.map(entry => {
    return bundle({
      instance: getBrowserifyInstance({ config: entry.babel }),
      bundle: entry.bundle,
    });
  }));
});

gulp.task('javascript:watch', () => {
  const entries = config.get('tasks.javascript.bundles').filter(entry => entry.watch);
  return es.merge(entries.map(entry => {
    return bundle({
      instance: getBrowserifyInstance({
        config: entry.babel,
        watch: true,
      }),
      bundle: entry.bundle,
    });
  })).on('end', () => {
    browserSync.reload();
    gulp.start('eslint');<commit_msg>Fixed javascript task error handling<commit_after>import { logError } from '../lib/log';
import fs from 'fs';
import es from 'event-stream';
import config from '../lib/config';
import gulp from 'gulp';
import pump from 'pump';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import browserSync from 'browser-sync';

import sourcemaps from 'gulp-sourcemaps';
import browserify from 'browserify';
import babelify from 'babelify';
import watchify from 'watchify';

/**
 * Javascript bundle with Browserify and Babel transpiler
 */
const bundle = (args, done) => {
  return args.instance.bundle()
    .on('error', err => {
      logError(err);
      done();
    })
    .pipe(source(args.bundle))
    .pipe(buffer())
    .pipe(sourcemaps.init({ loadMaps: true }))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest(config.get('tasks.javascript.dist')));
};

const getBrowserifyInstance = (args) => {
  const options = { entries: config.get('tasks.javascript.main') };
  const instance = args && args.watch ? watchify(browserify(options)) : browserify(options);
  return instance.transform(babelify, args.config);
};

gulp.task('javascript:build', (done) => {
  const task = this;
  const entries = config.get('tasks.javascript.bundles');
  return es.merge(entries.map(entry => {
    return bundle({
      task: task,
      instance: getBrowserifyInstance({ config: entry.babel }),
      bundle: entry.bundle,
    }, error => process.exit(1));
  }));
});

gulp.task('javascript:watch', (done) => {
  const task = this;
  const entries = config.get('tasks.javascript.bundles').filter(entry => entry.watch);
  return es.merge(entries.map(entry => {
    return bundle({
      task: task,
      instance: getBrowserifyInstance({
        config: entry.babel,
        watch: true,
      }),
      bundle: entry.bundle,
    }, error => done());
  })).on('end', () => {
    browserSync.reload();
    gulp.start('eslint');
{'fraction_non_alphanumeric': 0.1654891304347826, 'fraction_numerical': 0.0002717391304347826, 'mean_word_length': 3.8370565045992118, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6469488', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1106, 'n_words': 270}