complex-module

    1.0.2 • Public • Published

    complex-module

    Converts directory structure to exported object.

    Travis CI build

    Please overview tests to see what that tool does: https://github.com/amuzalevskiy/complex-module/tree/master/test

    Sample:

    Directory structure

    tools/
        usefullTool.js
    exportedClass.js

    will be converted to

    module.exports = {
        tools: {
            usefullTool: require('./tools/usefullTool.js'),
        },
        exportedClass: require('./exportedClass.js')
    }

    Using following script (e.g. index.js):

    // will populate all modules in current directory to module.exports object
    require('complex-module').make(module);

    Or if your library is placed in sub-folder:

    var complexModule = require('complex-module');
    complexModule.make(complexModule.baseDir(module.filename) + '/lib', module.exports);

    baseDir(str) ⇒ string

    Removes filename from full filename leaving base dir only

    Kind: global function

    Param Type
    str string

    make(moduleInfoOrDir, [res], [filter]) ⇒ Object

    Finds all javascripts inside folder and inserts into result. Converts directory structure to object structure

    Usual use case:

    // will populate all modules in current directory to module.exports object
    require('complex-module').make(module);

    If your library is in subfolder (shorthand - makeFromDirectory() fn):

    var complexModule = require('complex-module');
    complexModule.make(complexModule.baseDir(module.filename) + '/lib', module.exports);

    Kind: global function
    Returns: Object - object passed as an argument or new object populated with all modules inside baseDir

    Param Type Description
    moduleInfoOrDir string | Object module information or directory where search files
    [res] Object result where to store found modules, uses moduleInfoOrDir.exports if not defined
    [filter] Object see fs-walker filter for details.
                        Default behaviour is to add all `*.js` files, ignoring files placed in `node_modules`, `test`
                        and dot-started directories |
    

    makeFromDirectory(moduleInfo, innerPath) ⇒ Object

    Shorthand for creating modules from sub directory

    Kind: global function

    Param Type
    moduleInfo Object
    innerPath string

    Keywords

    Install

    npm i complex-module

    DownloadsWeekly Downloads

    1

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • amuzalevskyi