lib/importer.js
function importerSync(options, handler) {
    var modulePath, recursive = false, parent = '';

    if (typeof options === 'string') {
        modulePath = options;

    } else {
        modulePath = options.path;
        recursive = options.recursive || recursive;
        parent = options.parent || parent;
        if (!modulePath) throw new Error("module directory path must be given.");
    }

    // absolute path? or relevant path?
    if (modulePath.indexOf('/') != 0) {
        // relevant. join with parent module's path
        modulePath = path.join(path.dirname(module.parent.parent.filename), modulePath);
    }

    var files = fs.readdirSync(modulePath);
    for (var i in files) {
        var name = files[i];

        if (recursive && fs.lstatSync(path.join(modulePath, name)).isDirectory()) {
            importerSync({
                path: path.join(modulePath, name),
                recursive: true,
                parent: path.join(parent, name)
            }, handler);
            continue;
        }
        if (name.lastIndexOf('.js') != name.length - 3) continue;

        name = name.substring(0, name.lastIndexOf('.')); // remove ext
        var moduleObj = require(path.join(modulePath, name));
        if (handler) handler(moduleObj, path.join(parent, name));
    }
}
function importerSync(options, handler) {
    var modulePath, recursive = false, parent = '';

    if (typeof options === 'string') {
        modulePath = options;

    } else {
        modulePath = options.path;
        recursive = options.recursive || recursive;
        parent = options.parent || parent;
        if (!modulePath) throw new Error("module directory path must be given.");
    }

    // absolute path? or relevant path?
    if (modulePath.indexOf('/') != 0) {
        // relevant. join with parent module's path
        modulePath = path.join(path.dirname(module.parent.parent.filename), modulePath);
    }

    var files = fs.readdirSync(modulePath);
    for (var i in files) {
        var name = files[i];

        if (recursive && fs.lstatSync(path.join(modulePath, name)).isDirectory()) {
            importerSync({
                path: path.join(modulePath, name),
                recursive: true,
                parent: path.join(parent, name)
            }, handler);
            continue;
        }
        if (name.lastIndexOf('.js') != name.length - 3) continue;

        name = name.substring(0, name.lastIndexOf('.')); // remove ext
        var moduleObj = require(path.join(modulePath, name));
        if (handler) handler(moduleObj, path.join(parent, name));
    }
}
function importerSync ( options , handler ) { var modulePath , recursive = false , parent = '' ; if ( typeof options === 'string' ) { modulePath = options ; } else { modulePath = options . path ; recursive = options . recursive || recursive ; parent = options . parent || parent ; if ( ! modulePath ) throw new Error ( "module directory path must be given." ) ; } // absolute path? or relevant path? if ( modulePath . indexOf ( '/' ) != 0 ) { // relevant. join with parent module's path modulePath = path . join ( path . dirname ( module . parent . parent . filename ) , modulePath ) ; } var files = fs . readdirSync ( modulePath ) ; for ( var i in files ) { var name = files [ i ] ; if ( recursive && fs . lstatSync ( path . join ( modulePath , name ) ) . isDirectory ( ) ) { importerSync ( { path : path . join ( modulePath , name ) , recursive : true , parent : path . join ( parent , name ) } , handler ) ; continue ; } if ( name . lastIndexOf ( '.js' ) != name . length - 3 ) continue ; name = name . substring ( 0 , name . lastIndexOf ( '.' ) ) ; // remove ext var moduleObj = require ( path . join ( modulePath , name ) ) ; if ( handler ) handler ( moduleObj , path . join ( parent , name ) ) ; } }
Retrieves all sources in a given directory and calls handler.

@param options Import options. (or module directory path)
@param {eachModule} [handler] Called when import each module.
Retrieves all sources in a given directory and calls handler .