<commit_before>var path = require('path');
var fs = require('fs');
var _ = require('underscore');
var spawn = require('child_process').spawn;
var GitRepo = require('./gitrepo').GitRepo;
var rm_rf = require('rimraf');

Installer = function() {
  this._parseDeps();
  this._parseConfig();
  this._prepareFS();
};

Installer.prototype.run = function(fn) {
  var self = this;
  
  var preparedCount = 0;
  var _prepared = function() {
    preparedCount++;
    if (preparedCount >= _.keys(self.deps).length)
      fn();
  };

  var preparePackages = function() {
    _.each(self.deps, function(repoConfig, packageName) {
      var gitRepo = new GitRepo({
        config: repoConfig,
        name: packageName,
        rootDest: self.meteoriteDir
      });

      gitRepo.prepare(function() {
        var packagePath = path.join(gitRepo.path, 'src', packageName);
        self._linkPackage(packageName, packagePath, _prepared);
      });
    });
  };
  
  this._findMeteor(function() {
    preparePackages();
  });
};

Installer.prototype._linkPackage = function(name, linkPath, fn) {
  var packageDir = path.join(path.dirname(this.meteorPath), 'packages', name);
  var realPath;
  try {
    realPath = fs.readlinkSync(packageDir)
  } catch(e) {}
  
  if (realPath)
    rm_rf(packageDir, function() {
      fs.symlinkSync(linkPath, packageDir);
      fn();
    });

};

Installer.prototype._parseDeps = function() {
  var projectPath = process.cwd();
  var configPath = path.join(projectPath, 'depend.json');
  try {
    var rawConfig = fs.readFileSync(configPath).toString();
    this.deps = JSON.parse(rawConfig);
  } catch(e) {}
};

Installer.prototype._findMeteor = function(fn) {
  var self = this;
  var meteorPath;
  var whichMeteor = spawn('which', ['meteor']);

  whichMeteor.stdout.on('data', function (data) {
    self.meteorPath = data.toString().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    fn();
  });
};

Installer.prototype._parseConfig = function() {
  var homeDir = process.env.HOME;
  this.meteoriteDir = path.join(homeDir, '.meteorite');
};

Installer.prototype._prepareFS = function() {
  if (!path.existsSync(this.meteoriteDir))
    fs.mkdir(this.meteoriteDir);
};

module.exports = Installer;<commit_msg>rename method<commit_after>var path = require('path');
var fs = require('fs');
var _ = require('underscore');
var spawn = require('child_process').spawn;
var GitRepo = require('./gitrepo').GitRepo;
var rm_rf = require('rimraf');

Installer = function() {
  this._parseDeps();
  this._findMeteoriteDir();
  this._prepareFS();
};

Installer.prototype.run = function(fn) {
  var self = this;
  
  var preparedCount = 0;
  var _prepared = function() {
    preparedCount++;
    if (preparedCount >= _.keys(self.deps).length)
      fn();
  };

  var preparePackages = function() {
    _.each(self.deps, function(repoConfig, packageName) {
      var gitRepo = new GitRepo({
        config: repoConfig,
        name: packageName,
        rootDest: self.meteoriteDir
      });

      gitRepo.prepare(function() {
        var packagePath = path.join(gitRepo.path, 'src', packageName);
        self._linkPackage(packageName, packagePath, _prepared);
      });
    });
  };
  
  this._findMeteor(function() {
    preparePackages();
  });
};

Installer.prototype._linkPackage = function(name, linkPath, fn) {
  var packageDir = path.join(path.dirname(this.meteorPath), 'packages', name);
  var realPath;
  try {
    realPath = fs.readlinkSync(packageDir)
  } catch(e) {}
  
  if (realPath)
    rm_rf(packageDir, function() {
      fs.symlinkSync(linkPath, packageDir);
      fn();
    });

};

Installer.prototype._parseDeps = function() {
  var projectPath = process.cwd();
  var configPath = path.join(projectPath, 'depend.json');
  try {
    var rawConfig = fs.readFileSync(configPath).toString();
    this.deps = JSON.parse(rawConfig);
  } catch(e) {}
};

Installer.prototype._findMeteor = function(fn) {
  var self = this;
  var meteorPath;
  var whichMeteor = spawn('which', ['meteor']);

  whichMeteor.stdout.on('data', function (data) {
    self.meteorPath = data.toString().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    fn();
  });
};

Installer.prototype._findMeteoriteDir = function() {
  var homeDir = process.env.HOME;
  this.meteoriteDir = path.join(homeDir, '.meteorite');
};

Installer.prototype._prepareFS = function() {
  if (!path.existsSync(this.meteoriteDir))
    fs.mkdir(this.meteoriteDir);
};

module.exports = Installer;
{'fraction_non_alphanumeric': 0.16322869955156952, 'fraction_numerical': 0.0004484304932735426, 'mean_word_length': 3.6275933609958506, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6839275', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1481, 'n_words': 272}