<commit_before>const {dependencies} = require('./package.json'),
      gulp = require('gulp'),
      multipipe = require('multipipe'),
      path = require('path'),
      browserify = require('browserify'),
      browserSync = require('browser-sync'),
      reload = browserSync.reload,
      source = require('vinyl-source-stream'),
      _ = require('lodash'),
      {
        autoprefixer,
        cached,
        clean,
        concat,
        imagemin,
        jshint,
        less,
        lessReporter,
        minifyCss,
        minifyHtml,
        pipe,
        print,
        remember,
        revAll,
        sequence,
        sourcemaps,
        tasks,
        uglify,
        util
      } = require('gulp-load-plugins')();

const result = tasks(gulp, require);
if (typeof result === 'string') console.log(result);

let p = name => print(file => console.log(name, file));

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

gulp.task('build', sequence(['clean-rev', 'clean-dist'],
                            ['js-vendor', 'js-app', 'less:debug', 'html', 'images', 'fonts'],
                            ['minify-css', 'minify-html', 'minify-js', 'minify-images'],
                            'rev'));

gulp.task('dev', cb => {
  const {src} = paths;

  sequence('clean-dev', ['js-vendor', 'js-app', 'less:debug', 'html', 'images'], 'browser-sync')(cb);

  gulp.watch(src.html, ['html']);
  gulp.watch(src.scripts, ['js-app']);
  gulp.watch(src.templates, ['js-app']);
  gulp.watch(src.vendor, ['js-vendor']);
  gulp.watch(src.less, ['less:debug'])
      .on('change', event => {
        if (event.type === 'deleted') {
          delete cached.caches['less'][event.path];
          remember.forget('less', event.path);
        }
      });
});

gulp.task('browser-sync',
  () => browserSync({
    server: paths.dev.$,
    ghostMode: false
  }));

gulp.task('js-vendor',
  () => pipe([
    browserify()
      .require(_.keys(dependencies))
      .bundle()
    ,source('vendor.js')
    ,p('js-vendor')
    ,gulp.dest(paths.dev.$)
    ,reload({stream: true})
  ]));

gulp.task('js-app', ['jshint'],
  () => pipe([
    browserify({
      entries: [paths.src.app],
      debug: true
    })
      .external(_.keys(dependencies))
      .bundle()
    ,source('app.js')
    ,p('js-app')
    ,gulp.dest(paths.dev.$)
    ,reload({stream: true})
  ]));

gulp.task('jshint',
  () => pipe([
    gulp.src(paths.src.scripts)
    ,cached('jshint')
    ,p('jshint')
    ,jshint()
    ,jshint.reporter('jshint-stylish')
    ,jshint.reporter('fail')<commit_msg>Don't let `js-app` task hard fail gulp on error<commit_after>const {dependencies} = require('./package.json'),
      gulp = require('gulp'),
      multipipe = require('multipipe'),
      path = require('path'),
      browserify = require('browserify'),
      browserSync = require('browser-sync'),
      reload = browserSync.reload,
      source = require('vinyl-source-stream'),
      _ = require('lodash'),
      {
        autoprefixer,
        cached,
        clean,
        concat,
        imagemin,
        jshint,
        less,
        lessReporter,
        minifyCss,
        minifyHtml,
        pipe,
        print,
        remember,
        revAll,
        sequence,
        sourcemaps,
        tasks,
        uglify,
        util
      } = require('gulp-load-plugins')();

const result = tasks(gulp, require);
if (typeof result === 'string') console.log(result);

let p = name => print(file => console.log(name, file));

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

gulp.task('build', sequence(['clean-rev', 'clean-dist'],
                            ['js-vendor', 'js-app', 'less:debug', 'html', 'images', 'fonts'],
                            ['minify-css', 'minify-html', 'minify-js', 'minify-images'],
                            'rev'));

gulp.task('dev', cb => {
  const {src} = paths;

  sequence('clean-dev', ['js-vendor', 'js-app', 'less:debug', 'html', 'images'], 'browser-sync')(cb);

  gulp.watch(src.html, ['html']);
  gulp.watch(src.scripts, ['js-app']);
  gulp.watch(src.templates, ['js-app']);
  gulp.watch(src.vendor, ['js-vendor']);
  gulp.watch(src.less, ['less:debug'])
      .on('change', event => {
        if (event.type === 'deleted') {
          delete cached.caches['less'][event.path];
          remember.forget('less', event.path);
        }
      });
});

gulp.task('browser-sync',
  () => browserSync({
    server: paths.dev.$,
    ghostMode: false
  }));

gulp.task('js-vendor',
  () => pipe([
    browserify()
      .require(_.keys(dependencies))
      .bundle()
    ,source('vendor.js')
    ,p('js-vendor')
    ,gulp.dest(paths.dev.$)
    ,reload({stream: true})
  ]));

gulp.task('js-app', ['jshint'],
  () => pipe([
    browserify({
      entries: [paths.src.app],
      debug: true
    })
      .external(_.keys(dependencies))
      .bundle()
      .on('error', function(err) {
        console.log('js-app', err.stack);
        this.emit('end');
      })
    ,source('app.js')
    ,p('js-app')
    ,gulp.dest(paths.dev.$)
    ,reload({stream: true})
  ]));

gulp.task('jshint',
  () => pipe([
    gulp.src(paths.src.scripts)
    ,cached('jshint')
    ,p('jshint')
    ,jshint()
    ,jshint.reporter('jshint-stylish')
    ,jshint.reporter('fail')
{'fraction_non_alphanumeric': 0.2023398542385884, 'fraction_numerical': 0.0, 'mean_word_length': 2.360180412371134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '1834889', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1751, 'n_words': 290}