lib/lmd_common.js
function (config, configDir) {
    var modules = {},
        globalLazy = config.lazy || false,
        globalDepends = (config.depends === true ? DEFAULT_DEPENDS_MASK : config.depends) || false,
        moduleLazy = false,
        moduleTypeHint,
        moduleName,
        modulePath,
        moduleRealPath,
        moduleExists,
        moduleExports,
        moduleRequire,
        moduleBind,
        moduleFileName,
        moduleFilePath,
        moduleDesciptor,
        wildcardRegex,
        isMultiPathModule,
        moduleData,
        isThirdPartyModule,
        modulesDirPath = config.root || config.path || '';

    modulesDirPath = path.resolve(configDir, modulesDirPath);

    // grep paths
    for (moduleName in config.modules) {
        moduleDesciptor = config.modules[moduleName];
        // case "moduleName": null
        // case "moduleName": "path/to/module.js"
        if (moduleDesciptor === null || typeof moduleDesciptor === "string" || Array.isArray(moduleDesciptor)) {
            moduleTypeHint = false;
            moduleExports = false;
            moduleRequire = false;
            moduleBind = false;
            modulePath = moduleDesciptor;
            moduleLazy = globalLazy;
        } else { // case "moduleName": {"path": "path/to/module.js", "lazy": false}
            moduleTypeHint = moduleDesciptor.type || false;
            moduleExports = moduleDesciptor.exports || false;
            moduleRequire = moduleDesciptor.require || false;
            moduleBind = moduleDesciptor.bind || moduleDesciptor['this'] || false;
            modulePath = moduleDesciptor.path;
            moduleLazy = moduleDesciptor.lazy || false;
            moduleTypeHint = moduleDesciptor.type || false;
        }

        isMultiPathModule = false;
        if (Array.isArray(modulePath)) {
            // Try to glob
            // case when ['jquery*.js']
            modulePath = modulePath.reduce(function (paths, modulePath) {
                if (globPattern.test(modulePath)) {
                    modulePath = glob.sync(modulePath, {
                        cwd: modulesDirPath,
                        nosort: true
                    }) || [];
                }

                return paths.concat(modulePath);
            }, []);

            // case when ['jquery.js']
            if (modulePath.length === 1) {
                modulePath = modulePath[0];
            } else {
                isMultiPathModule = true;
            }
        }

        isThirdPartyModule = !!moduleExports || !!moduleRequire || !!moduleBind;

        // Override if cache flag = true
        if (config.cache) {
            moduleLazy = true;
        }

        // its a glob pattern
        // @see https://github.com/isaacs/node-glob
        if (!isMultiPathModule && globPattern.test(modulePath)) {
            var globModules = glob.sync(modulePath, {
                cwd: modulesDirPath,
                nosort: true
            });

            // * -> <%= file => for backward capability
            var moduleNameTemplate = template(moduleName.replace('*', '<%= file %>'));

            globModules.forEach(function (module) {
                var moduleRealPath = path.join(modulesDirPath, module),
                    basename = path.basename(moduleRealPath),
                    fileParts = basename.split('.'),
                    ext = fileParts.pop(),
                    file = fileParts.join('.'),
                    dir = path.dirname(moduleRealPath).split(path.sep).reverse(),
                    subdir = createSubdirTemplateVariable(modulesDirPath, moduleRealPath);

                // modify module name using template
                var newModuleName = moduleNameTemplate({
                    basename: basename,
                    file: file,
                    ext: ext,
                    dir: dir,
                    subdir: subdir
                });

                moduleExists = true;
                try {
                    moduleRealPath = fs.realpathSync(moduleRealPath);
                } catch (e) {
                    moduleExists = false;
                }

                moduleData = {
                    originalModuleDesciptor: moduleDesciptor,
                    name: newModuleName,
                    path: moduleRealPath,
                    originalPath: modulePath,
                    lines: 0,
                    extra_exports: moduleExports,
                    extra_require: moduleRequire,
                    extra_bind: moduleBind,
                    type_hint: moduleTypeHint,
                    is_exists: moduleExists,
                    is_third_party: isThirdPartyModule,
                    is_lazy: moduleLazy,
                    is_greedy: true,
                    is_shortcut: false,
                    is_coverage: isCoverage(config, newModuleName),
                    is_ignored: false,
                    is_sandbox: moduleDesciptor.sandbox || false,
                    is_multi_path_module: isMultiPathModule,
                    depends: typeof moduleDesciptor.depends === "undefined" ? globalDepends : moduleDesciptor.depends
                };

                // wildcard have a low priority
                // if module was directly named it pass
                if (!(modules[newModuleName] && !modules[newModuleName].is_greedy)) {
                    modules[newModuleName] = moduleData;
                }
            });
        } else if (!isMultiPathModule && /^@/.test(modulePath)) {
            // shortcut
            modules[moduleName] = {
                originalModuleDesciptor: moduleDesciptor,
                name: moduleName,
                originalPath: modulePath,
                lines: 0,
                path: modulePath,
                extra_exports: moduleExports,
                extra_require: moduleRequire,
                extra_bind: moduleBind,
                type_hint: moduleTypeHint,
                is_exists: true,
                is_third_party: isThirdPartyModule,
                is_lazy: moduleLazy,
                is_greedy: false,
                is_shortcut: true,
                is_coverage: false,
                is_ignored: false,
                is_sandbox: moduleDesciptor.sandbox || false,
                is_multi_path_module: isMultiPathModule,
                depends: typeof moduleDesciptor.depends === "undefined" ? globalDepends : moduleDesciptor.depends
            };
        } else if (modulePath === null) {
            modules[moduleName] = {
                originalModuleDesciptor: moduleDesciptor,
                name: moduleName,
                originalPath: modulePath,
                lines: 0,
                path: modulePath,
                extra_exports: moduleExports,
                extra_require: moduleRequire,
                extra_bind: moduleBind,
                type_hint: moduleTypeHint,
                is_exists: true,
                is_third_party: false,
                is_lazy: false,
                is_greedy: false,
                is_shortcut: false,
                is_coverage: false,
                is_ignored: true,
                is_sandbox: false,
                is_multi_path_module: false,
                depends: globalDepends
            };
        } else {
            modulePath = [].concat(modulePath);
            moduleExists = true;

            moduleRealPath = modulePath
                .map(function (modulePath) {
                    return path.join(modulesDirPath, modulePath);
                })
                .map(function (moduleRealPath) {
                    try {
                        return fs.realpathSync(moduleRealPath);
                    } catch (e) {
                        moduleExists = false;
                    }
                    return moduleRealPath;
                });

            // normal name
            // "name": "name.js"
            modules[moduleName] = {
                originalModuleDesciptor: moduleDesciptor,
                name: moduleName,
                path: isMultiPathModule ? moduleRealPath : moduleRealPath[0],
                originalPath: isMultiPathModule ? modulePath : modulePath[0],
                lines: 0,
                extra_exports: moduleExports,
                extra_require: moduleRequire,
                extra_bind: moduleBind,
                type_hint: moduleTypeHint,
                is_exists: moduleExists,
                is_third_party: isThirdPartyModule,
                is_lazy: moduleLazy,
                is_greedy: false,
                is_shortcut: false,
                // Cant use code coverage with multi path module
                is_coverage: !isMultiPathModule && isCoverage(config, moduleName),
                is_ignored: false,
                is_sandbox: moduleDesciptor.sandbox || false,
                is_multi_path_module: isMultiPathModule,
                depends: typeof moduleDesciptor.depends === "undefined" ? globalDepends : moduleDesciptor.depends
            };
        }
    }

    return modules;
}
function (config, configDir) {
    var modules = {},
        globalLazy = config.lazy || false,
        globalDepends = (config.depends === true ? DEFAULT_DEPENDS_MASK : config.depends) || false,
        moduleLazy = false,
        moduleTypeHint,
        moduleName,
        modulePath,
        moduleRealPath,
        moduleExists,
        moduleExports,
        moduleRequire,
        moduleBind,
        moduleFileName,
        moduleFilePath,
        moduleDesciptor,
        wildcardRegex,
        isMultiPathModule,
        moduleData,
        isThirdPartyModule,
        modulesDirPath = config.root || config.path || '';

    modulesDirPath = path.resolve(configDir, modulesDirPath);

    // grep paths
    for (moduleName in config.modules) {
        moduleDesciptor = config.modules[moduleName];
        // case "moduleName": null
        // case "moduleName": "path/to/module.js"
        if (moduleDesciptor === null || typeof moduleDesciptor === "string" || Array.isArray(moduleDesciptor)) {
            moduleTypeHint = false;
            moduleExports = false;
            moduleRequire = false;
            moduleBind = false;
            modulePath = moduleDesciptor;
            moduleLazy = globalLazy;
        } else { // case "moduleName": {"path": "path/to/module.js", "lazy": false}
            moduleTypeHint = moduleDesciptor.type || false;
            moduleExports = moduleDesciptor.exports || false;
            moduleRequire = moduleDesciptor.require || false;
            moduleBind = moduleDesciptor.bind || moduleDesciptor['this'] || false;
            modulePath = moduleDesciptor.path;
            moduleLazy = moduleDesciptor.lazy || false;
            moduleTypeHint = moduleDesciptor.type || false;
        }

        isMultiPathModule = false;
        if (Array.isArray(modulePath)) {
            // Try to glob
            // case when ['jquery*.js']
            modulePath = modulePath.reduce(function (paths, modulePath) {
                if (globPattern.test(modulePath)) {
                    modulePath = glob.sync(modulePath, {
                        cwd: modulesDirPath,
                        nosort: true
                    }) || [];
                }

                return paths.concat(modulePath);
            }, []);

            // case when ['jquery.js']
            if (modulePath.length === 1) {
                modulePath = modulePath[0];
            } else {
                isMultiPathModule = true;
            }
        }

        isThirdPartyModule = !!moduleExports || !!moduleRequire || !!moduleBind;

        // Override if cache flag = true
        if (config.cache) {
            moduleLazy = true;
        }

        // its a glob pattern
        // @see https://github.com/isaacs/node-glob
        if (!isMultiPathModule && globPattern.test(modulePath)) {
            var globModules = glob.sync(modulePath, {
                cwd: modulesDirPath,
                nosort: true
            });

            // * -> <%= file => for backward capability
            var moduleNameTemplate = template(moduleName.replace('*', '<%= file %>'));

            globModules.forEach(function (module) {
                var moduleRealPath = path.join(modulesDirPath, module),
                    basename = path.basename(moduleRealPath),
                    fileParts = basename.split('.'),
                    ext = fileParts.pop(),
                    file = fileParts.join('.'),
                    dir = path.dirname(moduleRealPath).split(path.sep).reverse(),
                    subdir = createSubdirTemplateVariable(modulesDirPath, moduleRealPath);

                // modify module name using template
                var newModuleName = moduleNameTemplate({
                    basename: basename,
                    file: file,
                    ext: ext,
                    dir: dir,
                    subdir: subdir
                });

                moduleExists = true;
                try {
                    moduleRealPath = fs.realpathSync(moduleRealPath);
                } catch (e) {
                    moduleExists = false;
                }

                moduleData = {
                    originalModuleDesciptor: moduleDesciptor,
                    name: newModuleName,
                    path: moduleRealPath,
                    originalPath: modulePath,
                    lines: 0,
                    extra_exports: moduleExports,
                    extra_require: moduleRequire,
                    extra_bind: moduleBind,
                    type_hint: moduleTypeHint,
                    is_exists: moduleExists,
                    is_third_party: isThirdPartyModule,
                    is_lazy: moduleLazy,
                    is_greedy: true,
                    is_shortcut: false,
                    is_coverage: isCoverage(config, newModuleName),
                    is_ignored: false,
                    is_sandbox: moduleDesciptor.sandbox || false,
                    is_multi_path_module: isMultiPathModule,
                    depends: typeof moduleDesciptor.depends === "undefined" ? globalDepends : moduleDesciptor.depends
                };

                // wildcard have a low priority
                // if module was directly named it pass
                if (!(modules[newModuleName] && !modules[newModuleName].is_greedy)) {
                    modules[newModuleName] = moduleData;
                }
            });
        } else if (!isMultiPathModule && /^@/.test(modulePath)) {
            // shortcut
            modules[moduleName] = {
                originalModuleDesciptor: moduleDesciptor,
                name: moduleName,
                originalPath: modulePath,
                lines: 0,
                path: modulePath,
                extra_exports: moduleExports,
                extra_require: moduleRequire,
                extra_bind: moduleBind,
                type_hint: moduleTypeHint,
                is_exists: true,
                is_third_party: isThirdPartyModule,
                is_lazy: moduleLazy,
                is_greedy: false,
                is_shortcut: true,
                is_coverage: false,
                is_ignored: false,
                is_sandbox: moduleDesciptor.sandbox || false,
                is_multi_path_module: isMultiPathModule,
                depends: typeof moduleDesciptor.depends === "undefined" ? globalDepends : moduleDesciptor.depends
            };
        } else if (modulePath === null) {
            modules[moduleName] = {
                originalModuleDesciptor: moduleDesciptor,
                name: moduleName,
                originalPath: modulePath,
                lines: 0,
                path: modulePath,
                extra_exports: moduleExports,
                extra_require: moduleRequire,
                extra_bind: moduleBind,
                type_hint: moduleTypeHint,
                is_exists: true,
                is_third_party: false,
                is_lazy: false,
                is_greedy: false,
                is_shortcut: false,
                is_coverage: false,
                is_ignored: true,
                is_sandbox: false,
                is_multi_path_module: false,
                depends: globalDepends
            };
        } else {
            modulePath = [].concat(modulePath);
            moduleExists = true;

            moduleRealPath = modulePath
                .map(function (modulePath) {
                    return path.join(modulesDirPath, modulePath);
                })
                .map(function (moduleRealPath) {
                    try {
                        return fs.realpathSync(moduleRealPath);
                    } catch (e) {
                        moduleExists = false;
                    }
                    return moduleRealPath;
                });

            // normal name
            // "name": "name.js"
            modules[moduleName] = {
                originalModuleDesciptor: moduleDesciptor,
                name: moduleName,
                path: isMultiPathModule ? moduleRealPath : moduleRealPath[0],
                originalPath: isMultiPathModule ? modulePath : modulePath[0],
                lines: 0,
                extra_exports: moduleExports,
                extra_require: moduleRequire,
                extra_bind: moduleBind,
                type_hint: moduleTypeHint,
                is_exists: moduleExists,
                is_third_party: isThirdPartyModule,
                is_lazy: moduleLazy,
                is_greedy: false,
                is_shortcut: false,
                // Cant use code coverage with multi path module
                is_coverage: !isMultiPathModule && isCoverage(config, moduleName),
                is_ignored: false,
                is_sandbox: moduleDesciptor.sandbox || false,
                is_multi_path_module: isMultiPathModule,
                depends: typeof moduleDesciptor.depends === "undefined" ? globalDepends : moduleDesciptor.depends
            };
        }
    }

    return modules;
}
@name LmdModuleStruct
@class

@field {String}  name            module name
@field {String}  path            full path to module
@field {String}  depends         depends file mask
@field {Boolean} is_lazy         is lazy module?
@field {Boolean} is_sandbox      is module sandboxed?
@field {Boolean} is_greedy       module is collected using wildcard
@field {Boolean} is_shortcut     is module shortcut?
@field {Boolean} is_coverage     is module under code coverage?
@field {Boolean} is_third_party  uses custom export/require?

 
Collecting module using merged config

@param config

@returns {Object}