<commit_before>//  Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met:
//  1. Redistributions of source code must retain the above copyright notice, this
//  list of conditions and the following disclaimer.
//  2. Redistributions in binary form must reproduce the above copyright notice,
//  this list of conditions and the following disclaimer in the documentation and/or
//  other materials provided with the distribution.
//  3. Neither the name of the organization nor the names of its contributors may be
//  used to endorse or promote products derived from this software without specific
//  prior written permission.

(
function(thiz){

    console.log("========>");
    console.log("========> RJS bootstrap ...");
    console.log("========>");

    //console.log(thiz);
    console.log(process.cwd());
    //console.log(process.env);




    var args = process.argv.slice(3);
    console.log(args);

    // relative to process.cwd(), folder that contains this config file
    var configDir = args[0];
    var i = configDir.lastIndexOf("/");
    configDir = configDir.substr(0, i);
    console.log(configDir);
    process._RJS_Path_RelCwd__ConfigDir = configDir;

    process._RJS_Path_RelCwd__ConfigDir_nSlashes
        = process._RJS_Path_RelCwd__ConfigDir.split('/').length - 1;


    var configCustomTarget = undefined;
    process._RJS_isSingleBundle = false;

    for (var k = 1; k < args.length; k++) {
        var parameter = args[k];

        var token = "--rjs_bundle=";
        if (parameter.indexOf(token) == 0) {

             // single or multiple bundle target
            var configBundleType = parameter;
            configBundleType = configBundleType.substr(token.length);
            console.log(configBundleType);
            process._RJS_isSingleBundle = (configBundleType === "single" ? true : false);
        }

        token = "--rjs_configCustomTarget=";
        if (parameter.indexOf(token) == 0) {

            configCustomTarget = parameter;
            configCustomTarget = configCustomTarget.substr(token.length);
            console.log(configCustomTarget);
        }

        // token = "--<PASSWORD>=";
        // if (parameter.indexOf(token) == 0) {

            // // relative to this config file, array of mainConfigFile(s)
            // mainConfigFile = parameter;
            // mainConfigFile = mainConfigFile.substr(token.length);
            // mainConfigFile = mainConfigFile.split(',');
            // console.log(mainConfigFile);
            // process._RJS_mainConfigFile = mainConfigFile;
        // }

        // token = "--<PASSWORD>=";
        // if (parameter.indexOf(token) == 0) {

            // // relative to process.cwd(), array of source folders
            // sources = parameter;
            // sources = sources.substr(token.length);
            // sources = sources.split(',');
            // console.log(sources);
        // }
    }

    // if (!process._RJS_isSingleBundle)
    // {
    //     // relative to process.cwd()
    //     var copiedSourcesDir = "/build-output/_SOURCES";
    //
    //     var fs = nodeRequire("fs");
    //
    //     var req = requirejs({
    //         context: 'build'
    //     });
    //     var nodeFile = req('node/file');
    //
    //     var regExpFilter= /\w/;
    //     var onlyCopyNew = false;
    //
    //     var destDir = process.cwd() + copiedSourcesDir;
    //     console.log("===> Destination source folder: " + destDir);
    // }

    var mainConfigFile = [];


    var N = process._RJS_Path_RelCwd__ConfigDir_nSlashes + 1;
    for (var i = 0; i < N; i++) {
        var pathPrefix = "";

        for (var j = 0; j < i; j++) {
            pathPrefix = pathPrefix + "../";
        }
        pathPrefix = pathPrefix + "../build-config/";

        if (i == N-1 && !process._RJS_isSingleBundle)
        {
            mainConfigFile.push(pathPrefix + "RequireJS_config_multiple-bundles_external-libs.js");
        }

        mainConfigFile.push(pathPrefix + "RequireJS_config_" + (process._RJS_isSingleBundle ? "single-bundle" : "multiple-bundles") + ((i == N-1) && configCustomTarget ? configCustomTarget : "") + ".js");

        mainConfigFile.push(pathPrefix + "RequireJS_config_common.js");

        // if (!process._RJS_isSingleBundle)
        // {
        //     var sourcesJsonPath = process.cwd() + "/" + process._RJS_Path_RelCwd__ConfigDir + "/" + pathPrefix + "RequireJS_sources.json";
        //     console.log(sourcesJsonPath);
        //
        //     var sourcesJson = fs.readFileSync(
        //         sourcesJsonPath,
        //         {encoding: 'utf-8'});
        //     var sources = JSON.parse(sourcesJson).sourceDirsToCopy;
        //     for (var k = 0; k < sources.length; k++) {
        //         var srcDir = sources[k];
        //         srcDir = process.cwd() + "/" + process._RJS_Path_RelCwd__ConfigDir + "/" + pathPrefix + srcDir;
        //         console.log("... Copying directory contents: " + srcDir);
        //<commit_msg>RequireJS config override suitable for Chrome extension / app Almond-driven worker single-bundle ("epub library writer")<commit_after>//  Copyright (c) 2014 Readium Foundation and/or its licensees. All rights reserved.
//
//  Redistribution and use in source and binary forms, with or without modification,
//  are permitted provided that the following conditions are met:
//  1. Redistributions of source code must retain the above copyright notice, this
//  list of conditions and the following disclaimer.
//  2. Redistributions in binary form must reproduce the above copyright notice,
//  this list of conditions and the following disclaimer in the documentation and/or
//  other materials provided with the distribution.
//  3. Neither the name of the organization nor the names of its contributors may be
//  used to endorse or promote products derived from this software without specific
//  prior written permission.

(
function(thiz){

    console.log("========>");
    console.log("========> RJS bootstrap ...");
    console.log("========>");

    //console.log(thiz);
    console.log(process.cwd());
    //console.log(process.env);




    var args = process.argv.slice(3);
    console.log(args);

    // relative to process.cwd(), folder that contains this config file
    var configDir = args[0];
    var i = configDir.lastIndexOf("/");
    configDir = configDir.substr(0, i);
    console.log(configDir);
    process._RJS_Path_RelCwd__ConfigDir = configDir;

    process._RJS_Path_RelCwd__ConfigDir_nSlashes
        = process._RJS_Path_RelCwd__ConfigDir.split('/').length - 1;


    var configCustomTarget = undefined;
    var configOverrideTarget = undefined;
    process._RJS_isSingleBundle = false;

    for (var k = 1; k < args.length; k++) {
        var parameter = args[k];

        var token = "--rjs_bundle=";
        if (parameter.indexOf(token) == 0) {

             // single or multiple bundle target
            var configBundleType = parameter;
            configBundleType = configBundleType.substr(token.length);
            console.log(configBundleType);
            process._RJS_isSingleBundle = (configBundleType === "single" ? true : false);
        }

        token = "--rjs_configCustomTarget=";
        if (parameter.indexOf(token) == 0) {

            configCustomTarget = parameter;
            configCustomTarget = configCustomTarget.substr(token.length);
            console.log(configCustomTarget);
        }

        token = "--rjs_configOverrideTarget=";
        if (parameter.indexOf(token) == 0) {

            configOverrideTarget = parameter;
            configOverrideTarget = configOverrideTarget.substr(token.length);
            console.log(configOverrideTarget);
        }

        // token = "--rjs_mainConfigFile=";
        // if (parameter.indexOf(token) == 0) {

            // // relative to this config file, array of mainConfigFile(s)
            // mainConfigFile = parameter;
            // mainConfigFile = mainConfigFile.substr(token.length);
            // mainConfigFile = mainConfigFile.split(',');
            // console.log(mainConfigFile);
            // process._RJS_mainConfigFile = mainConfigFile;
        // }

        // token = "--rjs_sources=";
        // if (parameter.indexOf(token) == 0) {

            // // relative to process.cwd(), array of source folders
            // sources = parameter;
            // sources = sources.substr(token.length);
            // sources = sources.split(',');
            // console.log(sources);
        // }
    }

    // if (!process._RJS_isSingleBundle)
    // {
    //     // relative to process.cwd()
    //     var copiedSourcesDir = "/build-output/_SOURCES";
    //
    //     var fs = nodeRequire("fs");
    //
    //     var req = requirejs({
    //         context: 'build'
    //     });
    //     var nodeFile = req('node/file');
    //
    //     var regExpFilter= /\w/;
    //     var onlyCopyNew = false;
    //
    //     var destDir = process.cwd() + copiedSourcesDir;
    //     console.log("===> Destination source folder: " + destDir);
    // }

    var mainConfigFile = [];


    var N = process._RJS_Path_RelCwd__ConfigDir_nSlashes + 1;
    for (var i = 0; i < N; i++) {
        var pathPrefix = "";

        for (var j = 0; j < i; j++) {
            pathPrefix = pathPrefix + "../";
        }
        pathPrefix = pathPrefix + "../build-config/";

        if (i == N-1 && !process._RJS_isSingleBundle)
        {
            mainConfigFile.push(pathPrefix + "RequireJS_config_multiple-bundles_external-libs.js");
        }

        if (!configOverrideTarget)
        {
            mainConfigFile.push(pathPrefix + "RequireJS_config_" + (process._RJS_isSingleBundle ? "single-bundle" : "multiple-bundles") + ((i == N-1) && configCustomTarget ? configCustomTarget : "") + ".js");
        }
        else if (i == N-1)
        {
            mainConfigFile.push(pathPrefix + "RequireJS_config_" + (process._RJS_isSingleBundle ? "single-bundle" : "multiple-bundles") + configOverrideTarget + ".js");
        }

        mainConfigFile.push(pathPrefix + "RequireJS_config_common.js");

        // if (!process._RJS_isSingleBundle)
        // {
        //     var sourcesJsonPath = process.cwd() + "/" + process._RJS_Path_RelCwd__ConfigDir + "/" + pathPrefix + "RequireJS_sources.json";
        //     console.log(sourcesJsonPath);
        //
        //     var sourcesJson = fs.readFileSync(
        //         sourcesJsonPath,
        //         {encoding: 'utf-8'});
        //     var sources = JSON.parse(sourcesJson).sourceDirsToCopy;
        //     for (var k = 0; k < sources.length; k++) {
        //         var srcDir = sources[k];
        //         srcDir = process.cwd() + "/" + process._RJS_Path_RelCwd__ConfigDir + "/" + pathPrefix + srcDir;
        //         console.log("... Copying directory contents: " + srcDir);
        //
{'fraction_non_alphanumeric': 0.13591090184715682, 'fraction_numerical': 0.004346251358203549, 'mean_word_length': 2.1521118721461185, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2875115', 'n_tokens_mistral': 3174, 'n_tokens_neox': 3071, 'n_words': 745}