<commit_before>var fs = require("fs"),
    zlib = require("zlib"),
    UglifyJS = require("uglify-js"),
    MagicString = require("magic-string");

function getFiles() {
    return [
        "src/subgroup.js"
    ];
}

function bundleFiles(files, copyright) {
    var bundle = new MagicString.Bundle(),
        umdTemplate = require(__dirname + "/umd.template.js"),
        i = 0;

    for (; i < files.length; i += 1) {
        bundle.addSource({
            filename: files[i],
            content: new MagicString( fs.readFileSync(files[i], "utf8") + "\n\n" )
        });
    }

    bundle.prepend(
        copyright + umdTemplate.before
    ).append(umdTemplate.after);

    return bundle;
}

function getSizeDelta(newContent, oldContent, fixCRLF) {
    if (!oldContent) {
        return " (new)";
    }
    if (newContent === oldContent) {
        return " (unchanged)";
    }
    if (fixCRLF) {
        newContent = newContent.replace(/\r\n?/g, '\n');
        oldContent = oldContent.replace(/\r\n?/g, '\n');
    }
    var delta = newContent.length - oldContent.length;

    return delta === 0 ? "" : " (" + (delta > 0 ? "+" : "") + delta + " bytes)";
}

function loadSilently(path) {
    try {
        return fs.readFileSync(path, "utf8");
    } catch (e) {
        return null;
    }
}

function bytesToKB(bytes) {
    return (bytes / 1024).toFixed(2) + " kB";
}

function fillContentWithMetaData(content, metaData) {
    return content.
        replace("{VERSION}", metaData.version).
        replace("{YEAR}", metaData["_year"]).
        replace("{AUTHOR}", metaData.author).
        replace("{LICENSE}", metaData.license).
        replace("{NAME}", metaData["_name"]).
        replace("{DESCRIPTION}", metaData.description);
}

exports.build = function (callback, metaData, compsBase32, buildName) {

    var files = getFiles(compsBase32);

    console.log("Bundling and minifying " + files.length + " file(s)...");

    var copyrightSrc = fillContentWithMetaData(fs.readFileSync("build/copyright-src.js", "utf8"), metaData),
        copyrightMin = fillContentWithMetaData(fs.readFileSync("build/copyright.js", "utf8"), metaData),

        filenamePart = "leaflet.featuregroup.subgroup" + (buildName ? "-" + buildName : ""),
        pathPart = "dist/",
        srcFilename = filenamePart + "-src.js",
        mapFilename = filenamePart + "-src.map",
        srcPath = pathPart + srcFilename,
        mapPath = pathPart + mapFilename,

        bundle = bundleFiles(files, copyrightSrc),
        newSrc = bundle.toString() + "\n//# sourceMappingURL=" + mapFilename,

        oldSrc = loadSilently(srcPath),
        srcDelta = getSizeDelta(newSrc, oldSrc, true);

    // Make sure the dist/ folder exists.
    try {
        fs.accessSync(pathPart, fs.F_OK);
    } catch (err) {
        fs.mkdirSync(pathPart);
    }

    pathPart += filenamePart;

    console.log("\tNon-minified: " + bytesToKB(newSrc.length) + srcDelta);
<commit_msg>Chore(sourcemap): renamed with -src.js.map extension<commit_after>var fs = require("fs"),
    zlib = require("zlib"),
    UglifyJS = require("uglify-js"),
    MagicString = require("magic-string");

function getFiles() {
    return [
        "src/subgroup.js"
    ];
}

function bundleFiles(files, copyright) {
    var bundle = new MagicString.Bundle(),
        umdTemplate = require(__dirname + "/umd.template.js"),
        i = 0;

    for (; i < files.length; i += 1) {
        bundle.addSource({
            filename: files[i],
            content: new MagicString( fs.readFileSync(files[i], "utf8") + "\n\n" )
        });
    }

    bundle.prepend(
        copyright + umdTemplate.before
    ).append(umdTemplate.after);

    return bundle;
}

function getSizeDelta(newContent, oldContent, fixCRLF) {
    if (!oldContent) {
        return " (new)";
    }
    if (newContent === oldContent) {
        return " (unchanged)";
    }
    if (fixCRLF) {
        newContent = newContent.replace(/\r\n?/g, '\n');
        oldContent = oldContent.replace(/\r\n?/g, '\n');
    }
    var delta = newContent.length - oldContent.length;

    return delta === 0 ? "" : " (" + (delta > 0 ? "+" : "") + delta + " bytes)";
}

function loadSilently(path) {
    try {
        return fs.readFileSync(path, "utf8");
    } catch (e) {
        return null;
    }
}

function bytesToKB(bytes) {
    return (bytes / 1024).toFixed(2) + " kB";
}

function fillContentWithMetaData(content, metaData) {
    return content.
        replace("{VERSION}", metaData.version).
        replace("{YEAR}", metaData["_year"]).
        replace("{AUTHOR}", metaData.author).
        replace("{LICENSE}", metaData.license).
        replace("{NAME}", metaData["_name"]).
        replace("{DESCRIPTION}", metaData.description);
}

exports.build = function (callback, metaData, compsBase32, buildName) {

    var files = getFiles(compsBase32);

    console.log("Bundling and minifying " + files.length + " file(s)...");

    var copyrightSrc = fillContentWithMetaData(fs.readFileSync("build/copyright-src.js", "utf8"), metaData),
        copyrightMin = fillContentWithMetaData(fs.readFileSync("build/copyright.js", "utf8"), metaData),

        filenamePart = "leaflet.featuregroup.subgroup" + (buildName ? "-" + buildName : ""),
        pathPart = "dist/",
        srcFilename = filenamePart + "-src.js",
        mapFilename = filenamePart + "-src.js.map",
        srcPath = pathPart + srcFilename,
        mapPath = pathPart + mapFilename,

        bundle = bundleFiles(files, copyrightSrc),
        newSrc = bundle.toString() + "\n//# sourceMappingURL=" + mapFilename,

        oldSrc = loadSilently(srcPath),
        srcDelta = getSizeDelta(newSrc, oldSrc, true);

    // Make sure the dist/ folder exists.
    try {
        fs.accessSync(pathPart, fs.F_OK);
    } catch (err) {
        fs.mkdirSync(pathPart);
    }

    pathPart += filenamePart;

    console.log("\tNon-minified: " + bytesToKB(newSrc.length) + srcDelta);

{'fraction_non_alphanumeric': 0.1584008097165992, 'fraction_numerical': 0.005735492577597841, 'mean_word_length': 2.717241379310345, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2075253', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1852, 'n_words': 368}