<commit_before>'use strict';

var exec = require('child_process').exec;
var utils = require('./utils');

function installGlobalDependencies() {
  return new Promise((resolve) => {
    exec('which tsc', (error, stdout, stderr) => {
      if (stdout) {
        return resolve();
      }

      if (stderr) {
        console.error(stderr);
        return resolve();
      }

      console.log('Installing typescript');
      exec('npm install -g typings typescript', (error) => {
        if (error) {
          console.error(error);
        }

        return resolve();
      })
    });
  });
}

module.exports = function(callback) {
  installGlobalDependencies().then(() => utils.installNodeModules.call(this))
    .then(callback)
    .catch((error) => {
      console.error(error);

      callback();
    });
};<commit_msg>#82: Adjust post-root-fetch hook to install typings and tsc globally<commit_after>'use strict';

var exec = require('child_process').exec;
var utils = require('./utils');

function installGlobalDependencies(globalDeps) {
  var promises = [];

  for (let depKey in globalDeps) {
    if (!globalDeps.hasOwnProperty(depKey)) {
      continue;
    }

    let dep = globalDeps[depKey];

    let promise = new Promise((resolve) => {
      exec(`which ${depKey}`, (error, stdout, stderr) => {
        if (stdout) {
          return resolve();
        }

        if (stderr) {
          console.error(`Error checking for ${dep} dependency globally. ${stderr}`);
          return resolve();
        }

        console.log(`Installing ${dep} globally.`);

        exec(`npm install -g ${dep}`, (error) => {
          if (error) {
            console.error(`Error installing ${dep} dependency globally. ${error}`);
          }

          return resolve();
        })
      });
    });

    promises.push(promise);
  }

  return Promise.all(promises);
}

module.exports = function(callback) {
  var deps = {
    'tsc': 'typescript',
    'typings': 'typings'
  };

  installGlobalDependencies(deps).then(() => utils.installNodeModules.call(this))
    .then(callback)
    .catch((error) => {
      console.error(error);

      callback();
    });
};
{'fraction_non_alphanumeric': 0.16087158089939732, 'fraction_numerical': 0.0009272137227630969, 'mean_word_length': 2.526143790849673, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1207501', 'n_tokens_mistral': 651, 'n_tokens_neox': 632, 'n_words': 139}