<commit_before>#!/usr/bin/env node
'use strict';
var child = require('child_process');
var fs = require('fs');
var path = require('path');

var cwd = process.cwd();
var pkgjsonpth = path.join(cwd, 'package.json');
var files = fs.readdirSync(cwd);
if(files.indexOf('package.json') === -1) {
  fail('No `package.json` found.');
}

var json;
try {
  json = require(pkgjsonpth);
} catch(err) {
  fail('Failed to read your `package.json`');
}

if(!json.scripts) json.scripts = {};

if(json.scripts.test && json.scripts.test.indexOf('mocha-spec-cov-alt') === -1) {
  json.scripts.test += ' &&  mocha --require blanket -R mocha-spec-cov-alt';
} else {
  json.scripts.test = 'mocha --require blanket -R mocha-spec-cov-alt';
}

if(!json.config) json.config = {};
json.config.blanket = extend({
  'data-cover-never': [
    'node_modules'
  ],
  'pattern': [
    'lib', 'YOUR', 'MODULE', 'DIRECTORIES', 'HERE'
  ],
  'spec-cov': {
    'threshold': 80,
    'localThreshold': 80,
  }
}, json.config.blanket || {});

process.stdout.write('Adding mocha-spec-cov-alt to your package.json...');
fs.writeFileSync(pkgjsonpth, JSON.stringify(json, null, 2));
process.stdout.write(' OK\n');
console.log('Adding `mocha`, `mocha-spec-cov-alt` and `blanket` through npm:');
var npm = child.spawn('npm', [
  'install', '--save-dev', 'mocha-spec-cov-alt', 'mocha@2.1', 'blanket',
]);
npm.stdout.pipe(process.stdout);

/**
 * Merges two objects together, overwriting the second's properties onto the
 * first.
 *
 * @param {Object} target
 * @param {Object} source
 * @return {Object} result The modified `target` parameter
 */

function extend(target, source) {
  var keys = Object.keys(source);
  for(var i = 0, len = keys.length; i < len; i++) {
    var key = keys[i];<commit_msg>Set-up the html-cov reporter script automatically<commit_after>#!/usr/bin/env node
'use strict';
var child = require('child_process');
var fs = require('fs');
var path = require('path');

var cwd = process.cwd();
var pkgjsonpth = path.join(cwd, 'package.json');
var files = fs.readdirSync(cwd);
if(files.indexOf('package.json') === -1) {
  fail('No `package.json` found.');
}

var json;
try {
  json = require(pkgjsonpth);
} catch(err) {
  fail('Failed to read your `package.json`');
}

if(!json.scripts) json.scripts = {};

if(json.scripts.test && json.scripts.test.indexOf('mocha-spec-cov-alt') === -1) {
  json.scripts.test += ' &&  mocha --require blanket -R mocha-spec-cov-alt';
} else {
  json.scripts.test = 'mocha --require blanket -R mocha-spec-cov-alt';
}

function usesHtmlCov(script) {
  return script.indexOf('html-cov') !== -1;
}

if(!any(json.scripts, usesHtmlCov)) {
  json.scripts['test-html-cov'] = 'mocha --require blanket -R html-cov > coverage.html';
}

if(!json.config) json.config = {};
json.config.blanket = extend({
  'data-cover-never': [
    'node_modules'
  ],
  'pattern': [
    'lib', 'YOUR', 'MODULE', 'DIRECTORIES', 'HERE'
  ],
  'spec-cov': {
    'threshold': 80,
    'localThreshold': 80,
  }
}, json.config.blanket || {});

process.stdout.write('Adding mocha-spec-cov-alt to your package.json...');
fs.writeFileSync(pkgjsonpth, JSON.stringify(json, null, 2));
process.stdout.write(' OK\n');
console.log('Adding `mocha`, `mocha-spec-cov-alt` and `blanket` through npm:');
var npm = child.spawn('npm', [
  'install', '--save-dev', 'mocha-spec-cov-alt', 'mocha@2.1', 'blanket',
]);
npm.stdout.pipe(process.stdout);

/**
 * Applies a predicate to collection and returns true if any of the items match
 * it
 */

function any(target, fn) {
  var keys = Object.keys(target);
  for(var i = 0, len = keys.length; i < len; i++) {
    var key = keys[i];
    var value = target[key];
    if(fn(value, key)) return true;
  }
  return false;
}

/**
 * Merges two objects together, overwriting the second's properties onto the
 * first.
 *
 * @param {Object} target
 * @param {Object} source
 * @return {Object} result The modified `target` parameter
 */

function extend(target, source) {
  var keys = Object.keys(source);
  for(var i = 0, len = keys.length; i < len; i++) {
    var key = keys[i];
{'fraction_non_alphanumeric': 0.19631901840490798, 'fraction_numerical': 0.005398773006134969, 'mean_word_length': 3.964677222898904, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, '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': '7095393', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1455, 'n_words': 345}