<commit_before>var fs = require('fs')
    , path = require('path')
    , crypto = require('crypto')
    , CircularJSON = require('circular-json')
    , fse = require('fs-extra');



/** Function: storeScreenShot
 * Stores base64 encoded PNG data to the file at the given path.
 *
 * Parameters:
 *     (String) data - PNG data, encoded in base64
 *     (String) file - Target file path
 */
function storeScreenShot(data, file) {
    try {
        fse.outputFileSync(file, data, {encoding: 'base64'})
    } catch(e) {
        console.error(e);
        console.error('Could not save image: ', file);
    }
}

/**
 * Writes a new _report.html file from the jsonData.
 * @param jsonData combined.json
 * @param baseName
 * @param options
 */
function addHTMLReport(jsonData, baseName, options){
    var basePath = path.dirname(baseName),
        // Output files
        htmlFile = path.join(basePath, options.docName),
        jsFile = path.join(basePath, 'app.js'),
        // Input files
        htmlInFile = path.join(__dirname, 'lib', 'index.html'),
        jsTemplate = path.join(__dirname, 'lib', 'app.js'),
        streamJs,
        streamHtml,
        cssLink = 'bootstrap.css';

    try {
        if (options.cssOverrideFile) {
            cssLink = options.cssOverrideFile;
        }

        var libs = [
            'bootstrap.css',
            'jquery.min.js',
            'angular.min.js',
            'bootstrap.min.js'
        ];
        for (var i = 0; i < libs.length; i++) {
            fs.createReadStream(path.join(__dirname, 'lib', 'assets', libs[i]))
                .pipe(fs.createWriteStream(path.join(basePath, libs[i])));
        }

        // Construct index.html
        streamHtml = fs.createWriteStream(htmlFile);

        streamHtml.write(
            fs.readFileSync(htmlInFile)
                .toString()
                .replace('<!-- Here will be CSS placed -->', '<link rel="stylesheet" href="'+cssLink+'" crossorigin="anonymous">')
                .replace('<!-- Here goes title -->', options.docTitle)
        );

        streamHtml.end();

        // Construct app.js
        streamJs = fs.createWriteStream(jsFile);

        streamJs.write(
            fs.readFileSync(jsTemplate)
                .toString()
                .replace('\'<Results Replacement>\'', JSON.stringify(jsonData, null, 4))
                .replace('\'<Sort Function Replacement>\'', options.sortFunction.toString())
        );

        streamJs.end();
    } catch(e) {
        console.error(e);
        console.error('Could not save combined.js for data: ' + jsonData);<commit_msg>Bugfix for stylesheet not loading in the report<commit_after>var fs = require('fs')
    , path = require('path')
    , crypto = require('crypto')
    , CircularJSON = require('circular-json')
    , fse = require('fs-extra');



/** Function: storeScreenShot
 * Stores base64 encoded PNG data to the file at the given path.
 *
 * Parameters:
 *     (String) data - PNG data, encoded in base64
 *     (String) file - Target file path
 */
function storeScreenShot(data, file) {
    try {
        fse.outputFileSync(file, data, {encoding: 'base64'})
    } catch(e) {
        console.error(e);
        console.error('Could not save image: ', file);
    }
}

/**
 * Writes a new _report.html file from the jsonData.
 * @param jsonData combined.json
 * @param baseName
 * @param options
 */
function addHTMLReport(jsonData, baseName, options){
    var basePath = path.dirname(baseName),
        // Output files
        htmlFile = path.join(basePath, options.docName),
        jsFile = path.join(basePath, 'app.js'),
        // Input files
        htmlInFile = path.join(__dirname, 'lib', 'index.html'),
        jsTemplate = path.join(__dirname, 'lib', 'app.js'),
        streamJs,
        streamHtml,
        cssLink = 'bootstrap.css';

    try {
        if (options.cssOverrideFile) {
            cssLink = options.cssOverrideFile;
        }

        var libs = [
            'bootstrap.css',
            'jquery.min.js',
            'angular.min.js',
            'bootstrap.min.js'
        ];
        for (var i = 0; i < libs.length; i++) {
            fs.createReadStream(path.join(__dirname, 'lib', 'assets', libs[i]))
                .pipe(fs.createWriteStream(path.join(basePath, libs[i])));
        }

        // Construct index.html
        streamHtml = fs.createWriteStream(htmlFile);

        streamHtml.write(
            fs.readFileSync(htmlInFile)
                .toString()
                .replace('<!-- Here will be CSS placed -->', '<link rel="stylesheet" href="'+cssLink+'">')
                .replace('<!-- Here goes title -->', options.docTitle)
        );

        streamHtml.end();

        // Construct app.js
        streamJs = fs.createWriteStream(jsFile);

        streamJs.write(
            fs.readFileSync(jsTemplate)
                .toString()
                .replace('\'<Results Replacement>\'', JSON.stringify(jsonData, null, 4))
                .replace('\'<Sort Function Replacement>\'', options.sortFunction.toString())
        );

        streamJs.end();
    } catch(e) {
        console.error(e);
        console.error('Could not save combined.js for data: ' + jsonData);
{'fraction_non_alphanumeric': 0.14255482878030012, 'fraction_numerical': 0.0030781069642170067, 'mean_word_length': 2.107591153616258, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3565373', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1491, 'n_words': 345}