<commit_before>var path = require("path");
var fs = require("fs");
var _ = require("lodash");
var transmoglify = require("amdclean");

var fragPath = path.join(__dirname, "fragments");

// A method that is used as `onBuildStart`.
var onBuildStart = _.once(function(name, config) {
  var shimConfiguration = config.shim;
  var context = new transmoglify.Context("default", name);

  // Prime the context with the shim configuration.
  Object.keys(shimConfiguration || {}).forEach(function(key) {
    context.register(key, "window['" + shimConfiguration[key].exports + "']");
  });

  var startFrag = String(fs.readFileSync(path.join(fragPath, "start.frag")));
  var endFrag = String(fs.readFileSync(path.join(fragPath, "end.frag")));

  // Set the start and end fragments.
  config.wrap = {
    start: _.template(startFrag)({ name: name }),
    end: _.template(endFrag)({ name: name }),
  };

  // Attach the context to the shared configuration object.
  config.context = context;
});

exports.optimize = function(name, config, source) {
  // This runs once.
  onBuildStart(name, config);

  var ast = transmoglify.clean(source, config.context);
  return ast.toString();
};
<commit_msg>Added comments and new project name.<commit_after>var path = require("path");
var fs = require("fs");
var _ = require("lodash");
var transmoglify = require("transmoglify-amd");

var fragPath = path.join(__dirname, "fragments");

// A method that is used as `onBuildStart`.
var onBuildStart = _.once(function(name, config) {
  var shimConfiguration = config.shim;
  var context = new transmoglify.Context("default", name);

  // Prime the context with the shim configuration.
  Object.keys(shimConfiguration || {}).forEach(function(key) {
    context.register(key, "window['" + shimConfiguration[key].exports + "']");
  });

  var startFrag = String(fs.readFileSync(path.join(fragPath, "start.frag")));
  var endFrag = String(fs.readFileSync(path.join(fragPath, "end.frag")));

  // Set the start and end fragments.
  config.wrap = {
    start: _.template(startFrag)({ name: name }),
    end: _.template(endFrag)({ name: name }),
  };

  // Attach the context to the shared configuration object.
  config.context = context;
});

exports.optimize = function(name, config, source) {
  // This runs once.
  onBuildStart(name, config);

  // Build out the AST from the source.  Reuse the existing context each time
  // to remain consistent.
  var ast = transmoglify.clean(source, config.context);

  // Return the string contents of the modified source file.
  return ast.toString();
};

{'fraction_non_alphanumeric': 0.14914330218068536, 'fraction_numerical': 0.0, 'mean_word_length': 4.275154004106776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3149444', 'n_tokens_mistral': 798, 'n_tokens_neox': 790, 'n_words': 218}