<commit_before>/* 
 * For registering base services eg. Event
 */

var Event = require("../event.js");

var AnnotationScanner = require("../annotation-scanner.js");

var DbConnectionFactory = require("../db-connection-factory.js");

var Promise = require("bluebird");

var _ = require("underscore");

module.exports = function ($registerByClass, $register, $build, applicationMode) {

    //get application mode
    var $config = require("../../config/app.js");
    $config.applicationMode = applicationMode;
    $register("$config", $config);

    var log4js = require("log4js");
    log4js.configure($config.log);

    var $logger = log4js.getLogger($config.debug ? "app" : "production-app");
    if (!$config.debug) {
        $logger.setLevel(_($config.log.appenders)
                .findWhere({category: "production-app"})
                .level);
    } else {
        $logger.setLevel(_($config.log.appenders)
                .findWhere({category: "app"})
                .level);
    }

    $register("$logger", $logger);

    $registerByClass("$event", Event);
    $register("$dbConnectionFactory", $build(DbConnectionFactory));

    var directories = ["lib/service"];
    $config.scanDirectories.forEach(function (directory) {
        directories.push(directory);
    });
    var scanner = new AnnotationScanner();

    return new Promise(function (resolve, reject) {
        scanner.scan(directories)
                .then(function () {
                    var rootPath = "../../";
                    //all services
                    var serviceFilePaths = scanner.getFilesByAnnotation("Service");
                    serviceFilePaths.forEach(function (serviceFilePath) {
                        var serviceAnnotation = scanner.getAnnotation(serviceFilePath, "Service");
                        var ServiceClass = require(rootPath + serviceFilePath);
                        $registerByClass(serviceAnnotation.parameters["name"], ServiceClass);
                    });

                    resolve();
                })
                .catch(reject);
    });

};


<commit_msg>Fix bug: if cloudpify runs in app mode so don't load services in $config.removeService.names<commit_after>/* 
 * For registering base services eg. Event
 */

var Event = require("../event.js");

var AnnotationScanner = require("../annotation-scanner.js");

var DbConnectionFactory = require("../db-connection-factory.js");

var Promise = require("bluebird");

var _ = require("underscore");

module.exports = function ($registerByClass, $register, $build, applicationMode) {

    //get application mode
    var $config = require("../../config/app.js");
    $config.applicationMode = applicationMode;
    $register("$config", $config);

    var log4js = require("log4js");
    log4js.configure($config.log);

    var $logger = log4js.getLogger($config.debug ? "app" : "production-app");
    if (!$config.debug) {
        $logger.setLevel(_($config.log.appenders)
                .findWhere({category: "production-app"})
                .level);
    } else {
        $logger.setLevel(_($config.log.appenders)
                .findWhere({category: "app"})
                .level);
    }

    $register("$logger", $logger);

    $registerByClass("$event", Event);
    $register("$dbConnectionFactory", $build(DbConnectionFactory));

    var directories = ["lib/service"];
    $config.scanDirectories.forEach(function (directory) {
        directories.push(directory);
    });
    var scanner = new AnnotationScanner();

    return new Promise(function (resolve, reject) {
        scanner.scan(directories)
                .then(function () {
                    var rootPath = "../../";
                    //all services
                    var serviceFilePaths = scanner.getFilesByAnnotation("Service");
                    serviceFilePaths.forEach(function (serviceFilePath) {
                        var serviceAnnotation = scanner.getAnnotation(serviceFilePath, "Service");
                        var serviceName = serviceAnnotation.parameters["name"];

                        var b = $config.applicationMode != "app";
                        var b1 = $config.remoteService.names.indexOf(serviceName) >= 0;
                        if (b || (!b && !b1)) {
                            var ServiceClass = require(rootPath + serviceFilePath);
                            $registerByClass(serviceName, ServiceClass);
                        }
                    });

                    resolve();
                })
                .catch(reject);
    });

};



{'fraction_non_alphanumeric': 0.13990775312980452, 'fraction_numerical': 0.002415989457500549, 'mean_word_length': 2.1472011057360056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4980499', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1136, 'n_words': 230}