<commit_before>'use strict';

// This script takes 2 arguments:
//
// * config: a RequireJS configuration file (passed to require.config
//   at run time),
//
// * build: a r.js build file (the file passed r.js to build an
//   optimization).
//
// It produces a configuration file designed to use an optimized
// bundle (what is produced by r.js). This configuration has:
//
// * baseURL set to the value of build.dir
//
// * paths containing, for each "define(" in each module created by
//   the build:
//
//       defined module: module created by build
//
// For instance if the build create foo.js which contains defines for
// A, B, C, and bar.js which contains a define for D. Then the
// following mappings will be created:
//
//     "A": "foo.js",
//     "B": "foo.js",
//     "C": "foo.js",
//     "D": "bar.js"
//
var path = require("path");
var util = require("./util");
var captureConfigObject = util.captureConfigObject;
var fileAsString = util.fileAsString;

var config_file_path = process.argv[2];
var build_file_path = process.argv[3];
var config_file_text = fileAsString(config_file_path);
var build_file_text = fileAsString(build_file_path);

var config = captureConfigObject(config_file_text);

/* jshint evil: true */
var build = eval(build_file_text);

var path_config = config.paths;
if (build.modules) {
    build.modules.forEach(function (module) {
        //
        // Scan each module for:
        //
        // define("...",
        var module_path = path.join(build.dir, module.name) + ".js";
        var text = fileAsString(module_path);
        text.match(/define\(["'](.*?)["']/g).forEach(function (match) {
            var name = match.slice(8, -1);
            path_config[name] = module.name;
        });
    });
}
config.paths = path_config;
console.log("require.config(" +
            JSON.stringify(config, null, 4) +
           ");");
<commit_msg>Add the possibility to skip modules.<commit_after>'use strict';

// This script takes 2 arguments:
//
// * config: a RequireJS configuration file (passed to require.config
//   at run time),
//
// * build: a r.js build file (the file passed r.js to build an
//   optimization).
//
// It produces a configuration file designed to use an optimized
// bundle (what is produced by r.js). This configuration has:
//
// * baseURL set to the value of build.dir
//
// * paths containing, for each "define(" in each module created by
//   the build:
//
//       defined module: module created by build
//
// For instance if the build create foo.js which contains defines for
// A, B, C, and bar.js which contains a define for D. Then the
// following mappings will be created:
//
//     "A": "foo.js",
//     "B": "foo.js",
//     "C": "foo.js",
//     "D": "bar.js"
//
var path = require("path");
var util = require("./util");
var ArgumentParser = require("argparse").ArgumentParser;

var captureConfigObject = util.captureConfigObject;
var fileAsString = util.fileAsString;

var parser = new ArgumentParser({
    version: "0.0.1",
    addHelp: true,
    description: 'Creates an optimized configuration from a base' +
        ' configuration and the optimizer\'s build file.'});

parser.addArgument(["-k", "--skip"],
                   { help: "Skip a module from processing.",
                     action: "append",
                     dest: "skip"});

parser.addArgument(["config"]);
parser.addArgument(["build"]);

var args = parser.parseArgs();

var config_file_path = args.config;
var build_file_path = args.build;
var config_file_text = fileAsString(config_file_path);
var build_file_text = fileAsString(build_file_path);

var config = captureConfigObject(config_file_text);

/* jshint evil: true */
var build = eval(build_file_text);

var path_config = config.paths;
if (build.modules) {
    build.modules.forEach(function (module) {
        if (args.skip.indexOf(module))
            return;
        //
        // Scan each module for:
        //
        // define("...",
        var module_path = path.join(build.dir, module.name) + ".js";
        var text = fileAsString(module_path);
        text.match(/define\(["'](.*?)["']/g).forEach(function (match) {
            var name = match.slice(8, -1);
            path_config[name] = module.name;
        });
    });
}
config.paths = path_config;
console.log("require.config(" +
            JSON.stringify(config, null, 4) +
           ");");

{'fraction_non_alphanumeric': 0.1487565594341775, 'fraction_numerical': 0.00296600501939311, 'mean_word_length': 2.705832628909552, 'pattern_counts': {'":': 8, '<': 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': '6488680', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1315, 'n_words': 408}