<commit_before>/* Copyright 2015, Yahoo Inc.
   Inspired by https://github.com/babel/babel/blob/d06cfe63c272d516dc4d6f1f200b01b8dfdb43b1/packages/babel-cli/src/babel-doctor/rules/has-config.js
   Copyrights licensed under the MIT License.
   See the accompanying LICENSE file for terms. */

var path = require('path');
var xtend = require('xtend');
var defaultConfig = require('./defaults');
var TransformConfig = require('./transform-config');
var BundleConfig = require('./bundle-config');
var VariationConfig = require('./variation-config');
var BaseConfig = require('./base-config');
var TypesConfig = require('./types-config');

module.exports = function(config) {
    var defaults = defaultConfig();

    // merge by priority
    config = deepMerge(defaults, config);

    // merge environment based config
    config.environment = config.environment || process.env.MENDEL_ENV || process.env.NODE_ENV;
    var envConfig = config.env[config.environment];

    if (envConfig) {
        config = deepMerge(config, envConfig);
    }
    delete config.env;

    // Use absolute path for path configs
    config.cwd = path.resolve(config.cwd);
    config.baseConfig = new BaseConfig(config);
    config.variationConfig = new VariationConfig(config);
    config.types = Object.keys(config.types).map(function(typeName) {
        return new TypesConfig(typeName, config.types[typeName]);
    });
    config.transforms = Object.keys(config.transforms).map(function(transformId) {
        return new TransformConfig(transformId, config.transforms[transformId]);
    });
    config.bundles = Object.keys(config.bundles).map(function(bundleId) {
        return new BundleConfig(bundleId, config.bundles[bundleId]);
    });

    return config;
};

function deepMerge(dest, src) {
    for (var key in src) {
        // istanbul ignore else
        if (src.hasOwnProperty(key)) {
            if (isObject(dest[key]) && isObject(src[key])) {
                dest[key] = deepMerge(dest[key], src[key]);
            } else {
                dest[key] = src[key];
            }
        }
    }
    return dest;
}
<commit_msg>Small adjustment to environments on mendel-config<commit_after>/* Copyright 2015, Yahoo Inc.
   Inspired by https://github.com/babel/babel/blob/d06cfe63c272d516dc4d6f1f200b01b8dfdb43b1/packages/babel-cli/src/babel-doctor/rules/has-config.js
   Copyrights licensed under the MIT License.
   See the accompanying LICENSE file for terms. */

var path = require('path');
var debug = require('debug')('mendel:config');
var defaultConfig = require('./defaults');
var TransformConfig = require('./transform-config');
var BundleConfig = require('./bundle-config');
var VariationConfig = require('./variation-config');
var BaseConfig = require('./base-config');
var TypesConfig = require('./types-config');

module.exports = function(config) {
    var defaults = defaultConfig();

    // merge by priority
    config = deepMerge(defaults, config);

    // merge environment based config
    config.environment = config.environment ||
                         process.env.MENDEL_ENV ||
                         process.env.NODE_ENV ||
                         'development';
    var envConfig = config.env[config.environment];

    if (envConfig) {
        config = deepMerge(config, envConfig);
    }

    // Use absolute path for path configs
    config.cwd = path.resolve(config.cwd);
    config.baseConfig = new BaseConfig(config);
    config.variationConfig = new VariationConfig(config);
    config.types = Object.keys(config.types).map(function(typeName) {
        return new TypesConfig(typeName, config.types[typeName]);
    });
    config.transforms = Object.keys(config.transforms).map(transformId => {
        return new TransformConfig(transformId, config.transforms[transformId]);
    });
    config.bundles = Object.keys(config.bundles).map(function(bundleId) {
        return new BundleConfig(bundleId, config.bundles[bundleId]);
    });

    const inspect = require('util').inspect;
    debug(inspect(config, {
        colors: true,
        depth: null,
    }));

    return config;
};

function deepMerge(dest, src) {
    for (var key in src) {
        // istanbul ignore else
        if (src.hasOwnProperty(key)) {
            if (isObject(dest[key]) && isObject(src[key])) {
                dest[key] = deepMerge(dest[key], src[key]);
            } else {
                dest[key] = src[key];
            }
        }
    }
    return dest;
}

{'fraction_non_alphanumeric': 0.1305711086226204, 'fraction_numerical': 0.011646136618141097, 'mean_word_length': 3.041628959276018, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5545858', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1263, 'n_words': 276}