<commit_before>const fs = require('fs');
const path = require('path');
const merge = require('merge');

/** kernel class generates all module instances */
class Kernel {

    constructor() {

        // get rootpath of application
        let rootPath = path.dirname(require.main.filename) + '/';

        // get default config
        this._defaultConfig = require('../config/config.json');

        // get application config
        this._appConfig = require(rootPath + 'app/config/config.json');

        // merge default config with app config
        this._config = merge.recursive(this._defaultConfig, this._appConfig);

        // add path informations to config
        this._config.path = {
            root : rootPath,
            app : rootPath + 'app/',
        };

        // create app modules
        this._modules = {};

        for(let module in this._config.modules) {

            // check if module is active
            let active = this._config.modules[module].active;
            if(true !== active) continue;

            let pathToModule = this._config.path.app + 'modules/' + module;

            // check if module is an app module, if not module is an core module
            if(!fs.existsSync(pathToModule + '.js')) {
                pathToModule = __dirname + '/../modules/' + module
            }

            // check if module exists
            if(!fs.existsSync(pathToModule + '.js')) console.error('module does not exists: ' + pathToModule + '.js');

            // get args for generate module instances
            let moduleArguments = this._config.modules[module]['args'];

            let args = [];

            for(let moduleArgument in moduleArguments) args.push(moduleArguments[moduleArgument]);

            // create instance of module
            let moduleClass = require(pathToModule);
            this._modules[module] = eval("new moduleClass('" + args.join("','") + "')");

        }

    }

    get config() {
        return this._config;
    }

    get modules() {
        return this._modules;
    }

}

module.exports = new Kernel();<commit_msg>optimize kernel module<commit_after>const fs = require('fs');
const path = require('path');
const merge = require('merge');

/** kernel class generates all module instances */
class Kernel {

    constructor() {

        // get root path of application
        let rootPath = path.dirname(require.main.filename);

        // get default config
        this._defaultConfig = require('../config/config.json');

        // get application config
        this._appConfig = require(path.join(rootPath, 'app/config/config.json'));

        // merge default config with app config
        this._config = merge.recursive(this._defaultConfig, this._appConfig);

        // add path informations to config
        this._config.path = {
            root : rootPath,
            app : path.join(rootPath, 'app'),
        };

        // create app modules
        this._modules = {};

        for(let module in this._config.modules) {

            // check if module is active
            let active = this._config.modules[module].active;
            if(true !== active) continue;

            let pathToModule = path.join(this._config.path.app, 'modules', module + '.js');

            // check if module is an app module, if not module is an core module
            if(!fs.existsSync(pathToModule, '.js')) {
                pathToModule = path.join(__dirname, '/../modules/', module + '.js');
            }

            // check if module exists
            if(!fs.existsSync(pathToModule)) console.error('module does not exists: ' + pathToModule);

            // get args for generate module instances
            let moduleArguments = this._config.modules[module]['args'];

            let args = [];

            for(let moduleArgument in moduleArguments) args.push(moduleArguments[moduleArgument]);

            // create instance of module
            let moduleClass = require(pathToModule);
            this._modules[module] = eval("new moduleClass('" + args.join("','") + "')");

        }

    }

    get config() {
        return this._config;
    }

    get modules() {
        return this._modules;
    }

}

module.exports = new Kernel();
{'fraction_non_alphanumeric': 0.12329090051862329, 'fraction_numerical': 0.0, 'mean_word_length': 2.026390870185449, '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': '7435950', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1054, 'n_words': 302}