<commit_before>/**
 * This module returns appropriate config values for the provided
 * platform, environment and project. It is used directly by the start
 * script in the bin directory.
 */

var url = require('url');
var path = require('path');
var ports = require('ports');
var _ = require('lodash/dist/lodash.underscore');
var path = require('path');

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


/**
 * Returns all config values for current environment
 */

exports.getConfig = function (platform, env, project_dir, argv) {

  // Remove driver letter on windows
  project_dir = '/' + path.relative('/', project_dir);

  // location of project's package.json
  var pkgfile = require(project_dir + '/package.json');

  // default platform-agnostic config
  var cfg = {
    default_file: function () {
      // the default file to serve when url does not match static file
      return path.resolve(project_dir, '' + this.www_root + '/index.html');
    },
    project_dir: project_dir,
    www_root: path.resolve(project_dir, 'www'),
    admin_root: path.resolve(project_dir + '/node_modules/hoodie-server/node_modules/hoodie-admin-dashboard/www'),
    host: process.env.HOODIE_BIND_ADDRESS || '127.0.0.1',
    app: pkgfile,
    domain: 'dev',
    local_tld: undefined,
    platform: platform,
    boring: false, // turn off fancy terminal stuff where possible
    // set the Hoodie instance ID, this is used to check
    // against the user roles when doing a test for Hoodie admin
    id: pkgfile.name,
    // add Hoodie paths to config
    hoodie: {
      app_path: path.resolve(project_dir, 'data')
    },
    couch: exports.getCouch(env),
    open_browser: process.env.CI ? false : true
  };

  // option to set server root url
  if (argv.hasOwnProperty('www') || argv.hasOwnProperty('w')) {
    cfg.www_root = path.resolve(project_dir + '/' + (argv.www || argv.w));
  }

  // option to configure custom ports
  if (argv.hasOwnProperty('custom-ports')) {
    var c_ports = argv['custom-ports'].split(',').reduce(function (memo, port) {
      port = parseInt(port, 10);
      if (port > 0) {
        memo.push(port);
      }
      return memo;
    }, []);
    if (c_ports.length === 3) {
      cfg.couch.port = c_ports[0];
      cfg.admin_port = c_ports[1];
      cfg.www_port = c_ports[2];
    } else {
      throw new Error('custom-ports option must contain 3 ports separated by ' +
                      'commas, ie: --custom-ports=3000,3001,3002');
    }
  } else {
    cfg.www_port = ports.getPort(cfg.id + '-www');
    cfg.admin_port = ports.getPort(cfg.id + '-admin');<commit_msg>fix(options): reverse order of custom ports arguments<commit_after>/**
 * This module returns appropriate config values for the provided
 * platform, environment and project. It is used directly by the start
 * script in the bin directory.
 */

var url = require('url');
var path = require('path');
var ports = require('ports');
var _ = require('lodash/dist/lodash.underscore');
var path = require('path');

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


/**
 * Returns all config values for current environment
 */

exports.getConfig = function (platform, env, project_dir, argv) {

  // Remove driver letter on windows
  project_dir = '/' + path.relative('/', project_dir);

  // location of project's package.json
  var pkgfile = require(project_dir + '/package.json');

  // default platform-agnostic config
  var cfg = {
    default_file: function () {
      // the default file to serve when url does not match static file
      return path.resolve(project_dir, '' + this.www_root + '/index.html');
    },
    project_dir: project_dir,
    www_root: path.resolve(project_dir, 'www'),
    admin_root: path.resolve(project_dir + '/node_modules/hoodie-server/node_modules/hoodie-admin-dashboard/www'),
    host: process.env.HOODIE_BIND_ADDRESS || '127.0.0.1',
    app: pkgfile,
    domain: 'dev',
    local_tld: undefined,
    platform: platform,
    boring: false, // turn off fancy terminal stuff where possible
    // set the Hoodie instance ID, this is used to check
    // against the user roles when doing a test for Hoodie admin
    id: pkgfile.name,
    // add Hoodie paths to config
    hoodie: {
      app_path: path.resolve(project_dir, 'data')
    },
    couch: exports.getCouch(env),
    open_browser: process.env.CI ? false : true
  };

  // option to set server root url
  if (argv.hasOwnProperty('www') || argv.hasOwnProperty('w')) {
    cfg.www_root = path.resolve(project_dir + '/' + (argv.www || argv.w));
  }

  // option to configure custom ports
  if (argv.hasOwnProperty('custom-ports')) {
    var c_ports = argv['custom-ports'].split(',').reduce(function (memo, port) {
      port = parseInt(port, 10);
      if (port > 0) {
        memo.push(port);
      }
      return memo;
    }, []);
    if (c_ports.length === 3) {
      cfg.www_port = c_ports[0];
      cfg.admin_port = c_ports[1];
      cfg.couch.port = c_ports[2];
    } else {
      throw new Error('custom-ports option must contain 3 ports separated by ' +
                      'commas, ie: --custom-ports=3000,3001,3002');
    }
  } else {
    cfg.www_port = ports.getPort(cfg.id + '-www');
    cfg.admin_port = ports.getPort(cfg.id + '-admin');
{'fraction_non_alphanumeric': 0.13926238955051864, 'fraction_numerical': 0.009988474836726853, 'mean_word_length': 3.0270688321732404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 20, 'xml': 0}, 'pii_count': 2, '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': '2937027', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1611, 'n_words': 455}