lib/factories/module.plugin.factory.js
function loadModules(rootDir, paths) {
        var serverModules = {};
        var me = this;

        // return empty object if no rootDir or paths
        if (!rootDir || !paths) { return serverModules; }

        // loop through paths and load all modules in those directories
        _.each(paths, function (relativePath) {
            var fullPath = path.normalize(rootDir + delim + relativePath);

            // if the directory doesn't exist, then skip to the next loop iteration
            if (fs.existsSync(fullPath)) {

                _.each(fs.readdirSync(fullPath), function (fileName) {

                    // if it is a javascript file and it DOES NOT end in .service.js, then save the mapping
                    if (utils.isJavaScript(fileName) && !fileName.match(/^.*\.service\.js$/)) {
                        var nameLower = utils.getCamelCase(fileName).toLowerCase();
                        var fullFilePath = path.normalize(fullPath + '/' + fileName);

                        // there are 2 diff potential aliases for any given server module
                        serverModules[nameLower + 'fromplugin'] = serverModules[nameLower] = require(fullFilePath);
                    }

                    // else if we are dealing   with a directory, recurse down into the folder
                    else if (fs.lstatSync(path.join(fullPath, fileName)).isDirectory()) {
                        _.extend(serverModules, me.loadModules(rootDir, [relativePath + '/' + fileName]));
                    }

                });
            }
        });

        return serverModules;
    }
function loadModules(rootDir, paths) {
        var serverModules = {};
        var me = this;

        // return empty object if no rootDir or paths
        if (!rootDir || !paths) { return serverModules; }

        // loop through paths and load all modules in those directories
        _.each(paths, function (relativePath) {
            var fullPath = path.normalize(rootDir + delim + relativePath);

            // if the directory doesn't exist, then skip to the next loop iteration
            if (fs.existsSync(fullPath)) {

                _.each(fs.readdirSync(fullPath), function (fileName) {

                    // if it is a javascript file and it DOES NOT end in .service.js, then save the mapping
                    if (utils.isJavaScript(fileName) && !fileName.match(/^.*\.service\.js$/)) {
                        var nameLower = utils.getCamelCase(fileName).toLowerCase();
                        var fullFilePath = path.normalize(fullPath + '/' + fileName);

                        // there are 2 diff potential aliases for any given server module
                        serverModules[nameLower + 'fromplugin'] = serverModules[nameLower] = require(fullFilePath);
                    }

                    // else if we are dealing   with a directory, recurse down into the folder
                    else if (fs.lstatSync(path.join(fullPath, fileName)).isDirectory()) {
                        _.extend(serverModules, me.loadModules(rootDir, [relativePath + '/' + fileName]));
                    }

                });
            }
        });

        return serverModules;
    }
function loadModules ( rootDir , paths ) { var serverModules = { } ; var me = this ; // return empty object if no rootDir or paths if ( ! rootDir || ! paths ) { return serverModules ; } // loop through paths and load all modules in those directories _ . each ( paths , function ( relativePath ) { var fullPath = path . normalize ( rootDir + delim + relativePath ) ; // if the directory doesn't exist, then skip to the next loop iteration if ( fs . existsSync ( fullPath ) ) { _ . each ( fs . readdirSync ( fullPath ) , function ( fileName ) { // if it is a javascript file and it DOES NOT end in .service.js, then save the mapping if ( utils . isJavaScript ( fileName ) && ! fileName . match ( / ^.*\.service\.js$ / ) ) { var nameLower = utils . getCamelCase ( fileName ) . toLowerCase ( ) ; var fullFilePath = path . normalize ( fullPath + '/' + fileName ) ; // there are 2 diff potential aliases for any given server module serverModules [ nameLower + 'fromplugin' ] = serverModules [ nameLower ] = require ( fullFilePath ) ; } // else if we are dealing   with a directory, recurse down into the folder else if ( fs . lstatSync ( path . join ( fullPath , fileName ) ) . isDirectory ( ) ) { _ . extend ( serverModules , me . loadModules ( rootDir , [ relativePath + '/' + fileName ] ) ) ; } } ) ; } } ) ; return serverModules ; }
Recursively go through dirs and add modules to a server modules map that is returned
@param rootDir
@param paths
@returns {*}
Recursively go through dirs and add modules to a server modules map that is returned