<commit_before>'use strict';

const path = require('path');
const UglifyJS = require('uglify-js');

function init({
    processorConfig,
    processorCommonConfig,
    commonConfig,
}) {
  const config = Object.assign({}, commonConfig, processorCommonConfig, processorConfig);

  function read(basePath, { readers }) {
    const scriptPaths = readers.dir(`${basePath}`);
    const scripts = scriptPaths.map((scriptPath) => {
      return {
        id: path.basename(scriptPath),
        name: path.basename(scriptPath),
        isBundle: false,
        contents: readers.fileToString(scriptPath),
      };
    });
    const bundles = config.bundles ? config.bundles.map((bundle) => {
      return {
        id: bundle.name,
        name: bundle.name,
        isBundle: true,
        files: bundle.files,
      };
    }) : [];
    return [...scripts, ...bundles];
  }

// script has name, path
  function preprocess(scripts) {
    return scripts.map((script) => {
      const next = Object.assign({}, script);
      next.writePath = `scripts/${script.name}`;
      return next;
    });
  }

// script has name, path, writePath
  function templateVariables(scripts) {
    return scripts.map((script) => {
      const next = Object.assign({}, script);
      next.url = `/scripts/${script.name}`;
      return next;
    });
  }

// script has name, path, writePath
  function postprocess(scripts) {
    return scripts.map((script) => {
      if (script.isBundle) {
        script.contents = script.files.reduce((s, fileName) => {
          return s + scripts.object[fileName].contents;
        }, '');
      }
      if (config.productionMode) {
        config.minify = config.minify || {};
        config.minify.fromString = true;
        script.contents = UglifyJS.minify(script.contents, config.minify).code;
      }
      return script;
    });
  }

// script has name, path, writePath
  function write(scripts, { writers }) {
    scripts.forEach((script) => {
      writers.file(`${config.outputDir}/${script.writePath}`, script.contents);
    });
  }

  return {
    read,
    preprocess,<commit_msg>Implement cache busting for scripts processor<commit_after>'use strict';

const path = require('path');
const UglifyJS = require('uglify-js');

function init({
    processorConfig,
    processorCommonConfig,
    commonConfig,
}) {
  const config = Object.assign({}, commonConfig, processorCommonConfig, processorConfig);

  function read(basePath, { readers }) {
    const scriptPaths = readers.dir(`${basePath}`);
    const scripts = scriptPaths.map((scriptPath) => {
      return {
        id: path.basename(scriptPath),
        name: path.basename(scriptPath),
        isBundle: false,
        contents: readers.fileToString(scriptPath),
      };
    });
    const bundles = config.bundles ? config.bundles.map((bundle) => {
      return {
        id: bundle.name,
        name: bundle.name,
        isBundle: true,
        files: bundle.files,
      };
    }) : [];
    return [...scripts, ...bundles];
  }

// script has name, path
  function preprocess(scripts, helpers) {
    return scripts.map((script) => {
      if (script.isBundle) {
        script.contents = script.files.reduce((s, fileName) => {
          return s + scripts.object[fileName].contents;
        }, '');
      }

      const next = Object.assign({}, script);

      if (config.cacheBust) {
        const fingerprintOpts = { env: config.productionMode ? 'production' : 'dev' };
        const filename = helpers.fingerprint(script.name, script.contents, fingerprintOpts).file;
        next.writePath = `scripts/${path.basename(script.name, '.js')}-${filename}`;
      } else {
        next.writePath = `scripts/${script.name}`;
      }
      return next;
    });
  }

// script has name, path, writePath
  function templateVariables(scripts) {
    return scripts.map((script) => {
      const next = Object.assign({}, script);
      next.url = '/' + script.writePath;
      return next;
    });
  }

// script has name, path, writePath
  function postprocess(scripts) {
    return scripts.map((script) => {
      if (config.productionMode) {
        config.minify = config.minify || {};
        config.minify.fromString = true;
        script.contents = UglifyJS.minify(script.contents, config.minify).code;
      }
      return script;
    });
  }

// script has name, path, writePath
  function write(scripts, { writers }) {
    scripts.forEach((script) => {
      writers.file(`${config.outputDir}/${script.writePath}`, script.contents);
    });
  }

  return {
    read,
    preprocess,
{'fraction_non_alphanumeric': 0.14845631705714912, 'fraction_numerical': 0.0, 'mean_word_length': 2.66025641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7459326', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1348, 'n_words': 278}