<commit_before>'use strict';

var path = require('path');
var fs = require('fs');
var proc = require('child_process');
var nex = require('nex-api');
var github = require('nex-github');
var _ = require('lodash');
var targz = require('tar.gz');
var rimraf = require('rimraf');
var log = require('npmlog');

var handler = module.exports = new nex.Handler('repository');

/**
 * @override
 */
handler.do = function (pkg) {
  let packageName = pkg.name + '-' + pkg.version;
  let repository = _.extend({ version: pkg.version }, pkg[this.field]);

  // skip, if already cloned
  if (fs.existsSync(path.resolve(process.cwd(), '.git'))) {
    log.info(packageName, 'found existing .git directory. skipping');
    return;
  }

  github.getRelease(repository)
    .then(function (tarball) {
      log.info('tarball', 'extracting', tarball);

      new targz().extract(tarball, path.resolve(process.cwd(), 'extract'), function (err) {
        if (err) {
          log.error('extract', err);
          throw err;
        }

        log.info('tarball', 'extracted');

        proc.execSync([ 'cp -r', path.resolve('extract', packageName, '*'), process.cwd() ].join(' '));
        rimraf.sync(path.resolve(process.cwd(), 'extract'));
        rimraf.sync(path.resolve(process.cwd(), packageName + '.tar.gz'));
      }); 
    },  
    function () {
      log.error('install', 'Failed to download', pkg.name, 'Please try again');
      process.exit(1);
    }); 
};

/**
 * @override
 */
handler.undo = function (pkg) {
  rimraf.sync('node_modules');
};<commit_msg>check for npmignore as indicator of previous install<commit_after>'use strict';

var path = require('path');
var fs = require('fs');
var proc = require('child_process');
var nex = require('nex-api');
var github = require('nex-github');
var _ = require('lodash');
var targz = require('tar.gz');
var rimraf = require('rimraf');
var log = require('npmlog');

var handler = module.exports = new nex.Handler('repository');

/**
 * @override
 */
handler.do = function (pkg) {
  let packageName = pkg.name + '-' + pkg.version;
  let repository = _.extend({ version: pkg.version }, pkg[this.field]);

  // skip, if already installed from git
  if (fs.existsSync(path.resolve(process.cwd(), '.npmignore'))) {
    log.info(packageName, 'found existing github release install. skipping...');
    return;
  }

  github.getRelease(repository)
    .then(function (tarball) {
      log.info('tarball', 'extracting', tarball);

      new targz().extract(tarball, path.resolve(process.cwd(), 'extract'), function (err) {
        if (err) {
          log.error('extract', err);
          throw err;
        }

        log.info('tarball', 'extracted');

        proc.execSync([ 'cp -r', path.resolve('extract', packageName, '*'), process.cwd() ].join(' '));
        rimraf.sync(path.resolve(process.cwd(), 'extract'));
        rimraf.sync(path.resolve(process.cwd(), packageName + '.tar.gz'));
      }); 
    },  
    function () {
      log.error('install', 'Failed to download', pkg.name, 'Please try again');
      process.exit(1);
    }); 
};

/**
 * @override
 */
handler.undo = function (pkg) {
  rimraf.sync('.npmignore');
};
{'fraction_non_alphanumeric': 0.1920886075949367, 'fraction_numerical': 0.0006329113924050633, 'mean_word_length': 3.3539944903581267, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2687425', 'n_tokens_mistral': 1027, 'n_tokens_neox': 985, 'n_words': 226}