<commit_before>// Tasks related to compilation of scripts
module.exports = function(CONFIG, gulp) {
  var taskId = 'scripts';

  // Required modules
  var browsersync = require('browser-sync');
  var concat = require('gulp-concat');
  var es = require('event-stream');
  var filter = require('gulp-filter');
  var path = require('path');
  var rename = require('gulp-rename');
  var size = require('gulp-size');
  var sourcemaps = require('gulp-sourcemaps');
  var uglify = require('gulp-uglify');

  // Paths
  var src = path.join(CONFIG.PATHS.SRC, CONFIG.PATHS.SCRIPTS, '**/*.js');
  var dist = path.join(CONFIG.PATHS.DIST, CONFIG.PATHS.SCRIPTS);

  // Lint scripts
  gulp.task('lint-' + taskId, function(cb) {
    cb();
  });

  // Build all script bundles
  gulp.task(CONFIG.PREFIX_BUILD + taskId, function() {
    // Create a stream for each script bundle
    var streams = CONFIG.SCRIPT_BUNDLES.map(function(bundle) {
      // Update files with SRC path
      var files = bundle.files.map(function(file) {
        return path.join(CONFIG.PATHS.SRC, CONFIG.PATHS.SCRIPTS, file);
      });

      // Start stream
      return gulp.src(files)
        .pipe(sourcemaps.init())
        .pipe(concat(bundle.dest))
        .pipe(uglify(CONFIG.UGLIFY_OPTIONS))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(dist))
    });

    // Merge streams in to one
    return es.merge(streams)
      .pipe(size({ showFiles: true }))
      .pipe(filter('**/*.js'))
      .pipe(browsersync.reload({ stream: true }))
  });

  // Watch for script changes
  gulp.task(CONFIG.PREFIX_WATCH + taskId, function(cb) {
    gulp.watch(src, gulp.series(CONFIG.PREFIX_BUILD + taskId));
    cb();
  });
};<commit_msg>When a script file is updated only the bundles that contain it are built and reloaded.<commit_after>// Tasks related to compilation of scripts
module.exports = function(CONFIG, gulp) {
  var taskId = 'scripts';

  // Required modules
  var browsersync = require('browser-sync');
  var concat = require('gulp-concat');
  var es = require('event-stream');
  var filter = require('gulp-filter');
  var path = require('path');
  var rename = require('gulp-rename');
  var size = require('gulp-size');
  var sourcemaps = require('gulp-sourcemaps');
  var uglify = require('gulp-uglify');

  // Paths
  var src = path.join(CONFIG.PATHS.SRC, CONFIG.PATHS.SCRIPTS, '**/*.js');
  var dist = path.join(CONFIG.PATHS.DIST, CONFIG.PATHS.SCRIPTS);

  // Find bundles that contain a file
  function find(file) {
    return CONFIG.SCRIPT_BUNDLES.filter(function(bundle) {
      // Bundle contains the file
      if(bundle.files.indexOf(file) >= 0) {
        return true;
      }

      // Bundle does not contain the file
      return false;
    });
  }

  // Build the provided script bundle
  function buildBundles(bundles) {
    // Create a stream for each script bundle being built
    var streams = bundles.map(function(bundle) {
      // Appen path to scripts folder
      var files = bundle.files.map(function(file) {
        return path.join(CONFIG.PATHS.SRC, CONFIG.PATHS.SCRIPTS, file);
      });

      // Create strem for this bundle
      return gulp.src(files)
        .pipe(sourcemaps.init())
        .pipe(concat(bundle.dest))
        .pipe(uglify(CONFIG.UGLIFY_OPTIONS))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest(dist))
    });

    // Merge all bundle streams in to one
    return es.merge(streams)
      .pipe(size({ showFiles: true }))
      .pipe(filter('**/*.js'))
      .pipe(browsersync.reload({ stream: true }))
  }

  // Build all script bundles
  gulp.task(CONFIG.PREFIX_BUILD + taskId, function() {
    return buildBundles(CONFIG.SCRIPT_BUNDLES);
  });

  // Watch for script changes
  gulp.task(CONFIG.PREFIX_WATCH + taskId, function(cb) {
    gulp.watch(src).on('change', function(filePath) {
      // Make the path relative to scripts folder
      var scriptFolderPath = path.join(CONFIG.PATHS.SRC, CONFIG.PATHS.SCRIPTS, '/');
      var file = filePath.replace(scriptFolderPath, '');

      // Build all bundles that contain the changed file
      return buildBundles(find(file));
    });
    cb();
  });
};
{'fraction_non_alphanumeric': 0.14620024125452352, 'fraction_numerical': 0.00024125452352231604, 'mean_word_length': 2.9827089337175794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '57851', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1326, 'n_words': 316}