<commit_before>var fs          = require('fs-extra'),
    sh          = require('shelljs'),
    program     = require('commander'),
    jsonPretty  = require('json-pretty');

program
.version('0.0.1')
.option('-u, --url [URL]', 'Input URL')
.option('-d, --destination [path]', 'Input Path to Store The Output')
.parse(process.argv);

var url     = program.url;
var dest;

var outputYSlow = 'tempYSlow.json';

// ---------------------- run the phantom command ----------------------
if ( sh.exec('phantomjs yslow.js --info grade ' + url + ' > ' + outputYSlow).code !== 0 ) {
    console.log('cannot generate YSlow result!');
    process.exit(1);
}

// ----------------------------- initialize -----------------------------
var resultYSlow = {
    name    : 'YSlow',
    url     : url,
    checking: []
};

var checkingName = [
    "Minimize HTTP Requests" ,
    "Use a Content Delivery Network" ,
    "Avoid empty src or href" ,
    "Add an Expires or a Cache-Control Header" ,
    "Gzip Components" ,
    "Put StyleSheets at the Top" ,
    "Put Scripts at the Bottom" ,
    "Avoid CSS Expressions" ,
    "Make JavaScript and CSS External" ,
    "Reduce DNS Lookups" ,
    "Minify JavaScript and CSS" ,
    "Avoid Redirects" ,
    "Remove Duplicate Scripts" ,
    "Configure ETags" ,
    "Make AJAX Cacheable" ,
    "Use GET for AJAX Requests" ,
    "Reduce the Number of DOM Elements" ,
    "No 404s" ,
    "Reduce Cookie Size" ,
    "Use Cookie-Free Domains for Components" ,
    "Avoid Filters" ,
    "Do Not Scale Images in HTML" ,
    "Make favicon.ico Small and Cacheable"
];

var i = 0;

fs.exists(program.destination, function (exists) {
    if ( !exists ) {
        fs.mkdirsSync( program.destination );
    }
    dest = './' + program.destination;

    // -------------------------- read yslow file output --------------------------
    fs.readFile('./' + outputYSlow,'utf-8' , function (err, data) {
        if (err) throw err;

        var jsonYSlow           = JSON.parse( data ),
            jsonYSlowChecking   = jsonYSlow.g;

        resultYSlow.overallScore = jsonYSlow.o;

        for ( var key in jsonYSlowChecking ) {
            if ( jsonYSlowChecking[key].score < 100 ) {
                resultYSlow.checking.push({
                    error   : "Error",
                    name    : checkingName[i] + " (" + key + ")",
                    score   : jsonYSlowChecking[key].score,
                    desc    : jsonYSlowChecking[key].message,
                    code    : jsonYSlowChecking[key].components
                });
            }
            i++;
        }

        var toJson = jsonPretty(resultYSlow);

        saveReport(dest, toJson);
        deleteTempFile(outputYSlow);
    });


});

function saveReport(path, content) {
    fs.writeFile(dest + 'resultYSlow.json', content, function (err) {
        if (err) throw err;
        console.log("resultYSlow.json has saved!");
    }); 
}

function deleteTempFile(url) {
    fs.remove( url , function (err) {
        if (err) return console.error(err);
        console.log("Temporary file has been deleted.");
    });
}
    <commit_msg>fix path bug<commit_after>var fs          = require('fs-extra'),
    sh          = require('shelljs'),
    program     = require('commander'),
    jsonPretty  = require('json-pretty');

program
.version('0.0.1')
.option('-u, --url [URL]', 'Input URL')
.option('-d, --destination [path]', 'Input Path to Store The Output')
.parse(process.argv);

var url     = program.url;
var dest;

var outputYSlow = 'tempYSlow.json';

// ---------------------- run the phantom command ----------------------
if ( sh.exec('phantomjs yslow.js --info grade ' + url + ' > ' + outputYSlow).code !== 0 ) {
    console.log('cannot generate YSlow result!');
    process.exit(1);
}

// ----------------------------- initialize -----------------------------
var resultYSlow = {
    name    : 'YSlow',
    url     : url,
    checking: []
};

var checkingName = [
    "Minimize HTTP Requests" ,
    "Use a Content Delivery Network" ,
    "Avoid empty src or href" ,
    "Add an Expires or a Cache-Control Header" ,
    "Gzip Components" ,
    "Put StyleSheets at the Top" ,
    "Put Scripts at the Bottom" ,
    "Avoid CSS Expressions" ,
    "Make JavaScript and CSS External" ,
    "Reduce DNS Lookups" ,
    "Minify JavaScript and CSS" ,
    "Avoid Redirects" ,
    "Remove Duplicate Scripts" ,
    "Configure ETags" ,
    "Make AJAX Cacheable" ,
    "Use GET for AJAX Requests" ,
    "Reduce the Number of DOM Elements" ,
    "No 404s" ,
    "Reduce Cookie Size" ,
    "Use Cookie-Free Domains for Components" ,
    "Avoid Filters" ,
    "Do Not Scale Images in HTML" ,
    "Make favicon.ico Small and Cacheable"
];

var i = 0;

fs.exists(program.destination, function (exists) {
    if ( !exists ) {
        fs.mkdirsSync( program.destination );
    }
    dest = './' + program.destination;

    // -------------------------- read yslow file output --------------------------
    fs.readFile('./' + outputYSlow,'utf-8' , function (err, data) {
        if (err) throw err;

        var jsonYSlow           = JSON.parse( data ),
            jsonYSlowChecking   = jsonYSlow.g;

        resultYSlow.overallScore = jsonYSlow.o;

        for ( var key in jsonYSlowChecking ) {
            if ( jsonYSlowChecking[key].score < 100 ) {
                resultYSlow.checking.push({
                    error   : "Error",
                    name    : checkingName[i] + " (" + key + ")",
                    score   : jsonYSlowChecking[key].score,
                    desc    : jsonYSlowChecking[key].message,
                    code    : jsonYSlowChecking[key].components
                });
            }
            i++;
        }

        var toJson = jsonPretty(resultYSlow);

        saveReport(dest, toJson);
        deleteTempFile(outputYSlow);
    });


});

function saveReport(path, content) {
    fs.writeFile(path + 'resultYSlow.json', content, function (err) {
        if (err) throw err;
        console.log("resultYSlow.json has saved!");
    }); 
}

function deleteTempFile(url) {
    fs.remove( url , function (err) {
        if (err) return console.error(err);
        console.log("Temporary file has been deleted.");
    });
}
    
{'fraction_non_alphanumeric': 0.17417802726543705, 'fraction_numerical': 0.004170008019246191, 'mean_word_length': 1.8384160218479746, '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': '898112', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1840, 'n_words': 486}