<commit_before>'use strict';
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var path = require('path');
var http = require('http');
var fs = require('fs'); // Will be overwritten by fs-extra-promise
var objectAssign = require('object-assign');
var Promise = null; // Wil be set below

var pouchDBNodePackageName = 'pouchdb';
var expressPouchDBPackageName = 'express-pouchdb';

function getPackageJsonVersion(packageName) {
  // If you can't trust your own file, who can you trust?
  var packageJSON =
    JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json')));
  if (!packageJSON.dependencies || !packageJSON.dependencies[packageName]) {
    throw new Error('No such packageName - ' + packageName);
  }
  return packageJSON.dependencies[packageName];
}

function installPackage(packageName, version, callback) {
  var packageVersion = packageName + '@' + version;
  exec('jx install ' + packageVersion, function (error, stdout, stderr) {
    if (error) {
      console.log('jx install of ' + packageVersion + ' failed with error ' +
        error + ', stdout: ' + stdout + ', stderr: ' + stderr);
      return callback(error);
    }
    callback();
  });
}


// This is stolen from install.js, I copy it here to simplify the work of
// making this file function since as it is, it is run before we run
// 'npm install'.
function childProcessExecPromise(commandString, currentWorkingDirectory, env) {
  return new Promise(function (resolve, reject) {
    var commandSplit = commandString.split(' ');
    var command = commandSplit.shift();
    env = objectAssign({}, process.env, env);
    var theProcess = spawn(command, commandSplit,
      { cwd: currentWorkingDirectory, env: env });
    theProcess.stdout.on('data', function (data) {
      console.log('' + data);
    });
    theProcess.stderr.on('data', function (data) {
      console.log('' + data);
    });
    theProcess.on('close', function (code) {
      if (code !== 0) {
        return reject(code);
      }
      return resolve();
    });
  });
}

/**
 * Runs an array of commands on the command line one by one.
 *
 * @param {string[][]} arrayOfCommandDirs An array of arrays. The child arrays
 * each must contain exactly two values, the first is the command to execute
 * and the second is the directory to run the command in.
 *<commit_msg>Fix "module not found" error during build<commit_after>'use strict';
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var path = require('path');
var http = require('http');
var fs = require('fs'); // Will be overwritten by fs-extra-promise
var Promise = null; // Wil be set below

var pouchDBNodePackageName = 'pouchdb';
var expressPouchDBPackageName = 'express-pouchdb';

function getPackageJsonVersion(packageName) {
  // If you can't trust your own file, who can you trust?
  var packageJSON =
    JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json')));
  if (!packageJSON.dependencies || !packageJSON.dependencies[packageName]) {
    throw new Error('No such packageName - ' + packageName);
  }
  return packageJSON.dependencies[packageName];
}

function installPackage(packageName, version, callback) {
  var packageVersion = packageName + '@' + version;
  exec('jx install ' + packageVersion, function (error, stdout, stderr) {
    if (error) {
      console.log('jx install of ' + packageVersion + ' failed with error ' +
        error + ', stdout: ' + stdout + ', stderr: ' + stderr);
      return callback(error);
    }
    callback();
  });
}


// This is stolen from install.js, I copy it here to simplify the work of
// making this file function since as it is, it is run before we run
// 'npm install'.
function childProcessExecPromise(commandString, currentWorkingDirectory, env) {
  return new Promise(function (resolve, reject) {
    var commandSplit = commandString.split(' ');
    var command = commandSplit.shift();
    env = Object.assign({}, process.env, env);
    var theProcess = spawn(command, commandSplit,
      { cwd: currentWorkingDirectory, env: env });
    theProcess.stdout.on('data', function (data) {
      console.log('' + data);
    });
    theProcess.stderr.on('data', function (data) {
      console.log('' + data);
    });
    theProcess.on('close', function (code) {
      if (code !== 0) {
        return reject(code);
      }
      return resolve();
    });
  });
}

/**
 * Runs an array of commands on the command line one by one.
 *
 * @param {string[][]} arrayOfCommandDirs An array of arrays. The child arrays
 * each must contain exactly two values, the first is the command to execute
 * and the second is the directory to run the command in.
 *
{'fraction_non_alphanumeric': 0.13026819923371646, 'fraction_numerical': 0.0004257130693912303, 'mean_word_length': 3.7037037037037037, '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': '3298989', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1340, 'n_words': 445}