function findInstalled(folder) {
    var options = {
        dev: false,
        log: function() {},
        depth: 4
    };
    var results = Immutable.OrderedMap();

    function onPackage(pkg, parent) {
        if (!pkg.name) return;

        var name = pkg.name;
        var version = pkg.version;
        var pkgPath = pkg.realPath;
        var depth = pkg.depth;
        var dependencies = pkg.dependencies;

        var pluginName = name.slice(PREFIX.length);

        if (!validateId(name)){
            if (parent) return;
        } else {
            results = results.set(pluginName, Plugin({
                name: pluginName,
                version: version,
                path: pkgPath,
                depth: depth,
                parent: parent
            }));
        }

        Immutable.Map(dependencies).forEach(function(dep) {
            onPackage(dep, pluginName);
        });
    }

    // Search for gitbook-plugins in node_modules folder
    var node_modules = path.join(folder, 'node_modules');

    // List all folders in node_modules
    return fs.readdir(node_modules)
    .fail(function() {
        return Promise([]);
    })
    .then(function(modules) {
        return Promise.serie(modules, function(module) {
            // Not a gitbook-plugin
            if (!validateId(module)) {
                return Promise();
            }

            // Read gitbook-plugin package details
            var module_folder = path.join(node_modules, module);
            return Promise.nfcall(readInstalled, module_folder, options)
            .then(function(data) {
                onPackage(data);
            });
        });
    })
    .then(function() {
        // Return installed plugins
        return results;
    });
}
function findInstalled(folder) {
    var options = {
        dev: false,
        log: function() {},
        depth: 4
    };
    var results = Immutable.OrderedMap();

    function onPackage(pkg, parent) {
        if (!pkg.name) return;

        var name = pkg.name;
        var version = pkg.version;
        var pkgPath = pkg.realPath;
        var depth = pkg.depth;
        var dependencies = pkg.dependencies;

        var pluginName = name.slice(PREFIX.length);

        if (!validateId(name)){
            if (parent) return;
        } else {
            results = results.set(pluginName, Plugin({
                name: pluginName,
                version: version,
                path: pkgPath,
                depth: depth,
                parent: parent
            }));
        }

        Immutable.Map(dependencies).forEach(function(dep) {
            onPackage(dep, pluginName);
        });
    }

    // Search for gitbook-plugins in node_modules folder
    var node_modules = path.join(folder, 'node_modules');

    // List all folders in node_modules
    return fs.readdir(node_modules)
    .fail(function() {
        return Promise([]);
    })
    .then(function(modules) {
        return Promise.serie(modules, function(module) {
            // Not a gitbook-plugin
            if (!validateId(module)) {
                return Promise();
            }

            // Read gitbook-plugin package details
            var module_folder = path.join(node_modules, module);
            return Promise.nfcall(readInstalled, module_folder, options)
            .then(function(data) {
                onPackage(data);
            });
        });
    })
    .then(function() {
        // Return installed plugins
        return results;
    });
}
function findInstalled ( folder ) { var options = { dev : false , log : function ( ) { } , depth : 4 } ; var results = Immutable . OrderedMap ( ) ; function onPackage ( pkg , parent ) { if ( ! pkg . name ) return ; var name = pkg . name ; var version = pkg . version ; var pkgPath = pkg . realPath ; var depth = pkg . depth ; var dependencies = pkg . dependencies ; var pluginName = name . slice ( PREFIX . length ) ; if ( ! validateId ( name ) ) { if ( parent ) return ; } else { results = results . set ( pluginName , Plugin ( { name : pluginName , version : version , path : pkgPath , depth : depth , parent : parent } ) ) ; } Immutable . Map ( dependencies ) . forEach ( function ( dep ) { onPackage ( dep , pluginName ) ; } ) ; } // Search for gitbook-plugins in node_modules folder var node_modules = path . join ( folder , 'node_modules' ) ; // List all folders in node_modules return fs . readdir ( node_modules ) . fail ( function ( ) { return Promise ( [ ] ) ; } ) . then ( function ( modules ) { return Promise . serie ( modules , function ( module ) { // Not a gitbook-plugin if ( ! validateId ( module ) ) { return Promise ( ) ; } // Read gitbook-plugin package details var module_folder = path . join ( node_modules , module ) ; return Promise . nfcall ( readInstalled , module_folder , options ) . then ( function ( data ) { onPackage ( data ) ; } ) ; } ) ; } ) . then ( function ( ) { // Return installed plugins return results ; } ) ; }
List all packages installed inside a folder

@param {String} folder
@return {OrderedMap<String:Plugin>}
List all packages installed inside a folder
Find installed gitbook - plugins in a folder