<commit_before>// dependencies
var env = require('node-env-file');
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;

// export the setEnv for convenient usage in dev
module.exports = setEnv;

// set env if not already set externally
// .env must exist if setting env vars externally
function setEnv(defaultKey) {
  // optionally set defaultKey
  process.env.DEPLOY = process.env.DEPLOY || defaultKey;

  try {
    env(__dirname + '/.env', { overwrite: false });
    // reset port for dev
    if (process.env.NODE_ENV == 'development') { process.env.PORT = process.env.TEST_PORT };
    // then set env keys for the deployed bot
    console.log("Deploying using", process.env.DEPLOY)
    env(__dirname + '/bin/' + process.env.DEPLOY);
  } catch (e) {
    console.log(e)
    process.exit(1)
  }
}

// if this file is run directly by `node index.js`
/* istanbul ignore next */
if (require.main === module) {
  // call setEnv with a default key
  setEnv('.keys-aiva');
  
  // child processes by spawn
  var children = [];
  
  // so that hubot is killed when forever exits.
  process.on('exit', function() {
    children.forEach(function(child) {
      child.kill();
    });
    // kill the neo4j brain server too
    exec('neo4j stop')
    console.log("Shutting down")
  });
  
  // start and kill neo4j brain server
  exec('neo4j start');
  // run hubot
  var hb = spawn('./bin/hubot', ['-a', process.env.ADAPTER], {  stdio: 'inherit' })
  children.push(hb);
  
  
  
  var cleanExit = function() { process.exit() };
  process.on('SIGINT', cleanExit); // catch ctrl-c
  process.on('SIGTERM', cleanExit); // catch kill
};
<commit_msg>modularize index setEnv for dev<commit_after>// dependencies
var env = require('node-env-file');
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;

// export the setEnv for convenient usage in dev
module.exports = setEnv;

// set env if not already set externally
// .env must exist if setting env vars externally
function setEnv(defaultKey) {
  // optionally set defaultKey
  process.env.DEPLOY = process.env.DEPLOY || defaultKey;

  try {
    env(__dirname + '/.env', { overwrite: false });
    // reset port for dev
    if (process.env.NODE_ENV == 'development') { process.env.PORT = process.env.TEST_PORT };
    // then set env keys for the deployed bot
    console.log("Deploying using", process.env.DEPLOY)
    env(__dirname + '/bin/' + process.env.DEPLOY);
  } catch (e) {
    console.log(e)
    process.exit(1)
  }
}

// if this file is run directly by `node index.js`
/* istanbul ignore next */
if (require.main === module) {
  // call setEnv with a default key
  setEnv();
  
  // child processes by spawn
  var children = [];
  
  // so that hubot is killed when forever exits.
  process.on('exit', function() {
    children.forEach(function(child) {
      child.kill();
    });
    // kill the neo4j brain server too
    exec('neo4j stop')
    console.log("Shutting down")
  });
  
  // start and kill neo4j brain server
  exec('neo4j start');
  // run hubot
  var hb = spawn('./bin/hubot', ['-a', process.env.ADAPTER], {  stdio: 'inherit' })
  children.push(hb);
  
  
  
  var cleanExit = function() { process.exit() };
  process.on('SIGINT', cleanExit); // catch ctrl-c
  process.on('SIGTERM', cleanExit); // catch kill
};

{'fraction_non_alphanumeric': 0.14721723518850988, 'fraction_numerical': 0.002992220227408737, 'mean_word_length': 3.0521212121212122, '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': '429371', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1062, 'n_words': 316}