<commit_before>var fs = require('fs');
var path = require('path');

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

var config = {
  PORT: 8080,
  plugins: ['brain', 'settings', 'content', 'timer', 'reset', 'namer'],
  STATE_DIR_PATH: 'state',
};


function parse(val) {
  try {
    return JSON.parse(val);
  } catch (e) {
    return val;
  }
}


for (var key in process.env) {
  config[key] = parse(process.env[key]);
}


// Load settings from a .env file. This will override the defaults, but
// not the environment.
try {
  var dotEnvPath = path.resolve(path.join(__dirname, '..', '.env'));
  var env = fs.readFileSync(dotEnvPath, {encoding: 'utf8'});
  env.split('\n').forEach(function(line) {
    var parts = line.split('=');
    var key = parts[0];
    var value = parse(parts.slice(1).join('='));
    if (!(key in process.env)) {
      config[key] = value;
    }
  });
} catch(e) {
}


module.exports = config;<commit_msg>Deference envvars that start with $.<commit_after>var fs = require('fs');
var path = require('path');

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

var config = {
  PORT: 8080,
  plugins: ['brain', 'settings', 'content', 'timer', 'reset', 'namer'],
  STATE_DIR_PATH: 'state',
};


function parse(val) {
  try {
    return JSON.parse(val);
  } catch (e) {
    return val;
  }
}


for (var key in process.env) {
  config[key] = parse(process.env[key]);
}


// Load settings from a .env file. This will override the defaults, but
// not the environment.
try {
  var dotEnvPath = path.resolve(path.join(__dirname, '..', '.env'));
  var env = fs.readFileSync(dotEnvPath, {encoding: 'utf8'});
  env.split('\n').forEach(function(line) {
    var parts = line.split('=');
    var key = parts[0];
    var value = parse(parts.slice(1).join('='));
    if (!(key in process.env)) {
      config[key] = value;
    }
  });
} catch(e) {
}

// If a variable starts with '$', look up *that* envvar, and use it instead.
for (var key in config) {
  val = config[key];
  if (val === null || val === undefined || val.charAt === undefined) {
    continue;
  }
  if (val.charAt(0) === '$') {
    var val = config[val.slice(1)] || val;
    config[key] = val;
  } else if (val.charAt(0) === '\\') {
    val = val.slice(1);
  }
}


module.exports = config;
{'fraction_non_alphanumeric': 0.19811743612729718, 'fraction_numerical': 0.008068130883012102, 'mean_word_length': 3.2676864244741872, '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': '1621554', 'n_tokens_mistral': 800, 'n_tokens_neox': 784, 'n_words': 209}