{"size": 649, "ext": "js", "max_stars_repo_path": "lib/server/config.js", "max_stars_repo_name": "draftr/draftr", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/server/config.js", "max_issues_repo_name": "draftr/draftr", "max_issues_repo_issues_event_min_datetime": "2015-03-31T11:19:35.000Z", "max_issues_repo_issues_event_max_datetime": "2015-04-01T12:01:42.000Z", "max_forks_repo_path": "lib/server/config.js", "max_forks_repo_name": "draftr/draftr", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 18, "max_forks_count": null, "avg_line_length": 24.9615384615, "max_line_length": 68, "alphanum_fraction": 0.5839753467}
var Promise     = require('bluebird'),
    fs          = require('fs'),
    _           = require('underscore'),
    deepExtend  = require('underscore-deep-extend');

_.mixin({ deepExtend: deepExtend(_) });

module.exports = function loadConfig(path, env) {
  'use strict';

  env = env || process.env.NODE_ENV;

  return new Promise(function (resolve, reject) {
    fs.exists(path, function (isPresent) {
      if (!isPresent) {
        return reject(new Error('Cannot find config file ' + path));
      }

      var data = require(path),
          config;

      config = _.deepExtend(data.prod, data[env]);
      resolve(config);
    });
  });
};