lib/map.js
function simpleMap(map, lvls, opts, type, ext, callback) {
    opts = utils.clone(opts);
    lvls--;
    if(lvls < 1) {
        opts.simple = false;
        opts.recursive = true;
        opts.type = type;
        opts.ext = ext;
    }
    var folders = map.__filter({type:'directory'}, true);
    var count = folders.length;
    var errs = [];

    function end(err) {
        if(err) {
            errs.push(err);
        }
        if(--count !== 0) {
            return;
        }
        if(errs.length) {
            callback(errs);
            return;
        }
        callback(null, map);
    }
    folders.forEach(function (folder) {
        folder.__map(opts, function (err, fMap) {
            if(err) {
                end(err);
                return;
            }
            if(lvls < 1) {
                end();
            } else {
                simpleMap(fMap, lvls, opts, type, ext, end);
            }
        });
    });
}
function simpleMap(map, lvls, opts, type, ext, callback) {
    opts = utils.clone(opts);
    lvls--;
    if(lvls < 1) {
        opts.simple = false;
        opts.recursive = true;
        opts.type = type;
        opts.ext = ext;
    }
    var folders = map.__filter({type:'directory'}, true);
    var count = folders.length;
    var errs = [];

    function end(err) {
        if(err) {
            errs.push(err);
        }
        if(--count !== 0) {
            return;
        }
        if(errs.length) {
            callback(errs);
            return;
        }
        callback(null, map);
    }
    folders.forEach(function (folder) {
        folder.__map(opts, function (err, fMap) {
            if(err) {
                end(err);
                return;
            }
            if(lvls < 1) {
                end();
            } else {
                simpleMap(fMap, lvls, opts, type, ext, end);
            }
        });
    });
}
function simpleMap ( map , lvls , opts , type , ext , callback ) { opts = utils . clone ( opts ) ; lvls -- ; if ( lvls < 1 ) { opts . simple = false ; opts . recursive = true ; opts . type = type ; opts . ext = ext ; } var folders = map . __filter ( { type : 'directory' } , true ) ; var count = folders . length ; var errs = [ ] ; function end ( err ) { if ( err ) { errs . push ( err ) ; } if ( -- count !== 0 ) { return ; } if ( errs . length ) { callback ( errs ) ; return ; } callback ( null , map ) ; } folders . forEach ( function ( folder ) { folder . __map ( opts , function ( err , fMap ) { if ( err ) { end ( err ) ; return ; } if ( lvls < 1 ) { end ( ) ; } else { simpleMap ( fMap , lvls , opts , type , ext , end ) ; } } ) ; } ) ; }
Function for mapping simple first x lvls
@param map -> root map
@param lvls -> nr of levels
@param opts -> the options
@param type -> the final type to use
@param callback
Function for mapping simple first x lvls