<commit_before>'use strict';

module.exports = function HandleUsingProcess(grunt, options, commands, callback) {

    var fs = require('fs');
    var version = grunt.file.readJSON('./package.json').version;
    var projectPkg = grunt.file.readJSON('package.json');
    var spawn = require('child_process').spawn;
    var _ = require('underscore');
    var commondir = require('commondir');

    var WIN32_BIN_PATH,
		UNIX_BIN_PATH;

	if (options.executeParallel) {
		UNIX_BIN_PATH = 'node_modules/parallel-cucumber/bin/parallel-cucumber-js';
		WIN32_BIN_PATH = 'node_modules\\parallel-cucumber\\bin\\parallel-cucumber-js';
	} else {
		WIN32_BIN_PATH = 'node_modules\\.bin\\cucumber-js.cmd';
		UNIX_BIN_PATH = 'node_modules/cucumber/bin/cucumber.js';
	}

    var buffer = [];
    var cucumber;
    var binPath = '';

    if (process.platform === 'win32') {
        binPath = WIN32_BIN_PATH;
    } else {
        binPath = UNIX_BIN_PATH;
    }

    if (!grunt.file.exists(binPath)) {
		if(options.executeParallel) {
			grunt.log.error('parallel-cucumber-js binary not found at path ' + binPath + '\n NOTE: You cannot install grunt-cucumberjs without bin links on windows');
		} else {
			grunt.log.error('cucumberjs binary not found at path ' + binPath + '\n NOTE: You cannot install grunt-cucumberjs without bin links on windows');
		}
        return callback(false);
    }

    cucumber = spawn(binPath, commands);

    cucumber.stdout.on('data', function(data) {
        if (options.format === 'html') {
            if (options.debug) {
                process.stdout.write(data);
            }
            buffer.push(data);
        } else {
            grunt.log.write(data);
        }
    });

    cucumber.stderr.on('data', function(data) {
        if (options.debug) {
            process.stdout.write(data);
        }
        var stderr = new Buffer(data);
        grunt.log.error(stderr.toString());
    });

    cucumber.on('close', function(code) {
        if (options.format === 'html') {

			var featureJsonOutput,
				featureOutput;

			if (options.executeParallel) {
				featureOutput = JSON.stringify(require('jsonfile').readFileSync(options.output + '.json'));
			} else {
				var output = Buffer.concat(buffer).toString();

				var featureStartIndex = output.search(/\[\s*{\s*\"id\"/g);

				var logOutput = output.substring(0, featureStartIndex - 1);

				featureOutput = output.substring(featureStartIndex);
			}

            try {
				featureJsonOutput = JSON.parse(featureOutput);
            } catch (e) {
                grunt.log.error('Unable to parse cucumberjs output into json.');

                return callback(false);
            }

            generateReport(featureJsonOutput, logOutput);
        }
<commit_msg>process html on if asked for<commit_after>'use strict';

module.exports = function HandleUsingProcess(grunt, options, commands, callback) {

    var fs = require('fs');
	var jsonFile = require('jsonfile');
    var version = grunt.file.readJSON('./package.json').version;
    var projectPkg = grunt.file.readJSON('package.json');
    var spawn = require('child_process').spawn;
    var _ = require('underscore');
    var commondir = require('commondir');

    var WIN32_BIN_PATH,
		UNIX_BIN_PATH;

	if (options.executeParallel) {
		UNIX_BIN_PATH = 'node_modules/parallel-cucumber/bin/parallel-cucumber-js';
		WIN32_BIN_PATH = 'node_modules\\parallel-cucumber\\bin\\parallel-cucumber-js';
	} else {
		WIN32_BIN_PATH = 'node_modules\\.bin\\cucumber-js.cmd';
		UNIX_BIN_PATH = 'node_modules/cucumber/bin/cucumber.js';
	}

    var buffer = [];
    var cucumber;
    var binPath = '';

    if (process.platform === 'win32') {
        binPath = WIN32_BIN_PATH;
    } else {
        binPath = UNIX_BIN_PATH;
    }

    if (!grunt.file.exists(binPath)) {
		if(options.executeParallel) {
			grunt.log.error('parallel-cucumber-js binary not found at path ' + binPath + '\n NOTE: You cannot install grunt-cucumberjs without bin links on windows');
		} else {
			grunt.log.error('cucumberjs binary not found at path ' + binPath + '\n NOTE: You cannot install grunt-cucumberjs without bin links on windows');
		}
        return callback(false);
    }

    cucumber = spawn(binPath, commands);

    cucumber.stdout.on('data', function(data) {
        if (options.isHtml) {
            if (options.debug) {
                process.stdout.write(data);
            }
            buffer.push(data);
        } else {
            grunt.log.write(data);
        }
    });

    cucumber.stderr.on('data', function(data) {
        if (options.debug) {
            process.stdout.write(data);
        }
        var stderr = new Buffer(data);
        grunt.log.error(stderr.toString());
    });

    cucumber.on('close', function(code) {
        if (options.isHtml) {

			var featureJsonOutput,
				featureOutput;

			if (options.executeParallel) {
				featureOutput = JSON.stringify(jsonFile.readFileSync(options.output + '.json'));
			} else {
				var jsonOutputFilePath = options.output + '.json';
				var jsonOutput;

				if (fs.existsSync(options.output + '.json')) {
					jsonOutput= JSON.stringify(jsonFile.readFileSync(jsonOutputFilePath));
				} else {
					jsonOutput = Buffer.concat(buffer).toString();
				}

				var featureStartIndex = jsonOutput.search(/\[\s*{\s*\"id\"/g);

				var logOutput = jsonOutput.substring(0, featureStartIndex - 1);

				featureOutput = jsonOutput.substring(featureStartIndex);
			}

            try {
				featureJsonOutput = JSON.parse(featureOutput);
            } catch (e) {
                grunt.log.error('Unable to parse cucumberjs output into json.');

                return callback(false);
            }

            generateReport(featureJsonOutput, logOutput);
        }

{'fraction_non_alphanumeric': 0.13440111420612813, 'fraction_numerical': 0.004178272980501393, 'mean_word_length': 2.6850545221295703, 'pattern_counts': {'":': 0, '<': 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': '4586887', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1766, 'n_words': 345}