<commit_before>/*
 * Copyright 2013, All Rights Reserved.
 *
 * Code licensed under the BSD License:
 * https://github.com/node-gh/gh/blob/master/LICENSE.md
 *
 * @author <NAME> <<EMAIL>>
 */

'use strict';

var fs = require('fs'),
    logger = require('./logger'),
    npm = require('npm'),
    path = require('path'),
    userhome = require('userhome'),
    which = require('which'),
    cache = {},
    plugins;

// -- Config -------------------------------------------------------------------

exports.getNodeModulesGlobalPath = function() {
    return npm.globalDir;
};

exports.getUserHomePath = function() {
    return userhome('.gh.json');
};

function getConfig(opt_plugin) {
    var globalConfig = exports.getGlobalConfig(opt_plugin),
        projectConfig,
        result = {};

    try {
        projectConfig = require(exports.getProjectConfigPath());

        Object.keys(globalConfig).forEach(function(key) {
            result[key] = globalConfig[key];
        });

        Object.keys(projectConfig).forEach(function(key) {
            result[key] = projectConfig[key];
        });

        return result;
    }
    catch (e) {
        if (e.code !== 'MODULE_NOT_FOUND') {
            throw e;
        }

        return globalConfig;
    }
}

exports.getConfig = function(opt_plugin) {
    if (!cache[opt_plugin]) {
        cache[opt_plugin] = getConfig(opt_plugin);
    }

    return cache[opt_plugin];
};

exports.getGlobalConfig = function(opt_plugin) {
    var config,
        configPath,
        userConfig;

    configPath = exports.getUserHomePath();

    if (!fs.existsSync(configPath)) {
        fs.writeFileSync(configPath, '{}');
        cache = {};
    }

    try {
        config = require(exports.getGlobalConfigPath());
        userConfig = require(configPath);

        Object.keys(userConfig).forEach(function(key) {
            config[key] = userConfig[key];
        });

        if (opt_plugin) {
            exports.getPlugins().forEach(function(plugin) {
                exports.addPluginConfig(config, plugin);
            });
        }

        return config;
    }
    catch (err) {
        logger.error('Reading the config: ' + err);
        return {};
    }
};

exports.getGlobalConfigPath = function() {
    return path.join(__dirname, '../', 'default.gh.json');
};

exports.getProjectConfigPath = function() {
    return path.join(process.cwd(), '.gh.json');
};

exports.removeGlobalConfig = function(key) {
    var config = exports.getGlobalConfig();
<commit_msg>Source formatting.<commit_after>/*
 * Copyright 2013, All Rights Reserved.
 *
 * Code licensed under the BSD License:
 * https://github.com/node-gh/gh/blob/master/LICENSE.md
 *
 * @author <NAME> <<EMAIL>>
 */

'use strict';

var fs = require('fs'),
    logger = require('./logger'),
    npm = require('npm'),
    path = require('path'),
    userhome = require('userhome'),
    which = require('which'),
    child_process = require('child_process'),
    cache = {},
    plugins;

// -- Config -------------------------------------------------------------------

exports.getNodeModulesGlobalPath = function() {
    return npm.globalDir;
};

exports.getUserHomePath = function() {
    return userhome('.gh.json');
};

function getConfig(opt_plugin) {
    var globalConfig = exports.getGlobalConfig(opt_plugin),
        projectConfig,
        result = {};

    try {
        projectConfig = require(exports.getProjectConfigPath());

        Object.keys(globalConfig).forEach(function(key) {
            result[key] = globalConfig[key];
        });

        Object.keys(projectConfig).forEach(function(key) {
            result[key] = projectConfig[key];
        });

        return result;
    }
    catch (e) {
        if (e.code !== 'MODULE_NOT_FOUND') {
            throw e;
        }

        return globalConfig;
    }
}

exports.getConfig = function(opt_plugin) {
    if (!cache[opt_plugin]) {
        cache[opt_plugin] = getConfig(opt_plugin);
    }

    return cache[opt_plugin];
};

exports.getGlobalConfig = function(opt_plugin) {
    var config,
        configPath,
        userConfig;

    configPath = exports.getUserHomePath();

    if (!fs.existsSync(configPath)) {
        fs.writeFileSync(configPath, '{}');
        cache = {};
    }

    config = require(exports.getGlobalConfigPath());
    userConfig = require(configPath);

    Object.keys(userConfig).forEach(function(key) {
        config[key] = userConfig[key];
    });

    if (opt_plugin) {
        exports.getPlugins().forEach(function(plugin) {
            exports.addPluginConfig(config, plugin);
        });
    }

    return config;
};

exports.getGlobalConfigPath = function() {
    return path.join(__dirname, '../', 'default.gh.json');
};

exports.getProjectConfigPath = function() {
    return path.join(process.cwd(), '.gh.json');
};

exports.removeGlobalConfig = function(key) {
    var config = exports.getGlobalConfig();

{'fraction_non_alphanumeric': 0.17053317053317052, 'fraction_numerical': 0.001628001628001628, 'mean_word_length': 2.3990318118948823, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '4283028', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1400, 'n_words': 247}