<commit_before>const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const file = require('gulp-file');
const filter = require('gulp-filter');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const path = require('path');
const isparta = require('isparta');
const Promise = require('bluebird');
const _ = require('underscore');
const eslint = require('gulp-eslint');
const plumber = require('gulp-plumber');
const notify = require('gulp-notify');
const rollup = require('rollup').rollup;
const multiEntry = require('rollup-plugin-multi-entry');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const json = require('rollup-plugin-json');
const preset = require('babel-preset-es2015-rollup');

const manifest = require('./package.json');
const config = manifest.babelBoilerplateOptions;
const mochaGlobals = require('./test/.globals.json').globals;
const mainFile = manifest.main;
const destinationFolder = path.dirname(mainFile);
const exportFileName = path.basename(mainFile, path.extname(mainFile));

// Remove the built files
gulp.task('clean', function(cb) {
  del([destinationFolder], cb);
});

// Remove our temporary files
gulp.task('clean-tmp', function(cb) {
  del(['tmp'], cb);
});

const onError = notify.onError('Error: <%= error.message %>');

function lint(files) {
  return gulp.src(files)
    .pipe(plumber(onError))
    .pipe(eslint())
    .pipe(eslint.format())
    .pipe(eslint.failOnError());
}

// Lint our source code
gulp.task('lint-src', function() {
  return lint(['src/**/*.js']);
});

// Lint our test code
gulp.task('lint-test', function() {
  return lint(['test/**/*.js']);
});

function getBanner() {
  const banner = ['/**',
    ` * ${ manifest.name } - ${ manifest.description }`,
    ` * @version v${ manifest.version }`,
    ` * @link ${ manifest.homepage }`,
    ` * @license ${ manifest.license }`,
    ' */',
    ''].join('\n');

  return banner;
}

function _generate(bundle) {
  const intro = getBanner();

  return bundle.generate({
    format: 'umd',
    moduleName: config.exportVarName,
    sourceMap: true,
    banner: intro,
    globals: {
      'backbone': 'Backbone',
      'underscore': '_',
      'backbone.marionette': 'Marionette'
    }
  });
}

function bundleCode(entryFileName) {
  return rollup({
    entry: `src/${ entryFileName }.js`,
    external: ['underscore', 'backbone', 'backbone.marionette'],
    plugins: [
      babel({
        sourceMaps: true,
        presets: [preset],
        babelrc: false
      })
    ]
  }).then(function(bundle) {
    return _generate(bundle);
  }).then(gen => {
    gen.code += `\n//# sourceMappingURL=${ gen.map.toUrl() }`;
    return gen;
  });
}

function _buildLib(entryFileName, destFolder, expFileName, expVarName, isPackage) {
  return bundleCode(entryFileName).then(gen => {
    if(isPackage) gen.code.replace('./state-class', 'marionette.toolkit.state-class');

    return file(`${ expFileName }.js`, gen.code, { src: true })
      .on('error', function(err) {
        console.log(err);
        this.emit('end');
      })
      .pipe(plumber())
      .pipe($.sourcemaps.init({ loadMaps: true }))
      .pipe($.sourcemaps.write('./'))
      .pipe(gulp.dest(destFolder))
      .pipe(filter(['*', '!**/*.js.map']))
      .pipe(rename(`${ expFileName }.min.js`))
      .pipe($.sourcemaps.init({ loadMaps: true }))
      .pipe(uglify({
        preserveComments: 'license'
      }))
      .pipe($.sourcemaps.write('./'))
      .pipe(gulp.dest(destFolder));
  });
}

// Build two versions of the library
gulp.task('build-lib', ['lint-src', 'clean'], function() {
  return _buildLib(config.entryFileName, destinationFolder, exportFileName, config.exportVarName);
});<commit_msg>Remove unneeded requires in favor of gulp-load-plugins<commit_after>const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const path = require('path');
const isparta = require('isparta');
const Promise = require('bluebird');
const _ = require('underscore');
const rollup = require('rollup').rollup;
const multiEntry = require('rollup-plugin-multi-entry');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const babel = require('rollup-plugin-babel');
const json = require('rollup-plugin-json');
const preset = require('babel-preset-es2015-rollup');

const manifest = require('./package.json');
const config = manifest.babelBoilerplateOptions;
const mochaGlobals = require('./test/.globals.json').globals;
const mainFile = manifest.main;
const destinationFolder = path.dirname(mainFile);
const exportFileName = path.basename(mainFile, path.extname(mainFile));

// Remove the built files
gulp.task('clean', function(cb) {
  del([destinationFolder], cb);
});

// Remove our temporary files
gulp.task('clean-tmp', function(cb) {
  del(['tmp'], cb);
});

const onError = $.notify.onError('Error: <%= error.message %>');

function lint(files) {
  return gulp.src(files)
    .pipe($.plumber(onError))
    .pipe($.eslint())
    .pipe($.eslint.format())
    .pipe($.eslint.failOnError());
}

// Lint our source code
gulp.task('lint-src', function() {
  return lint(['src/**/*.js']);
});

// Lint our test code
gulp.task('lint-test', function() {
  return lint(['test/**/*.js']);
});

function getBanner() {
  const banner = ['/**',
    ` * ${ manifest.name } - ${ manifest.description }`,
    ` * @version v${ manifest.version }`,
    ` * @link ${ manifest.homepage }`,
    ` * @license ${ manifest.license }`,
    ' */',
    ''].join('\n');

  return banner;
}

function _generate(bundle) {
  const intro = getBanner();

  return bundle.generate({
    format: 'umd',
    moduleName: config.exportVarName,
    sourceMap: true,
    banner: intro,
    globals: {
      'backbone': 'Backbone',
      'underscore': '_',
      'backbone.marionette': 'Marionette'
    }
  });
}

function bundleCode(entryFileName) {
  return rollup({
    entry: `src/${ entryFileName }.js`,
    external: ['underscore', 'backbone', 'backbone.marionette'],
    plugins: [
      babel({
        sourceMaps: true,
        presets: [preset],
        babelrc: false
      })
    ]
  }).then(function(bundle) {
    return _generate(bundle);
  }).then(gen => {
    gen.code += `\n//# sourceMappingURL=${ gen.map.toUrl() }`;
    return gen;
  });
}

function _buildLib(entryFileName, destFolder, expFileName, expVarName, isPackage) {
  return bundleCode(entryFileName).then(gen => {
    if(isPackage) gen.code.replace('./state-class', 'marionette.toolkit.state-class');

    return $.file(`${ expFileName }.js`, gen.code, { src: true })
      .on('error', function(err) {
        console.log(err);
        this.emit('end');
      })
      .pipe($.plumber())
      .pipe($.sourcemaps.init({ loadMaps: true }))
      .pipe($.sourcemaps.write('./'))
      .pipe(gulp.dest(destFolder))
      .pipe($.filter(['*', '!**/*.js.map']))
      .pipe($.rename(`${ expFileName }.min.js`))
      .pipe($.sourcemaps.init({ loadMaps: true }))
      .pipe($.uglify({
        preserveComments: 'license'
      }))
      .pipe($.sourcemaps.write('./'))
      .pipe(gulp.dest(destFolder));
  });
}

// Build two versions of the library
gulp.task('build-lib', ['lint-src', 'clean'], function() {
  return _buildLib(config.entryFileName, destinationFolder, exportFileName, config.exportVarName);
});
{'fraction_non_alphanumeric': 0.19346666666666668, 'fraction_numerical': 0.0010666666666666667, 'mean_word_length': 3.753485424588086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1112220', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2422, 'n_words': 479}