import readInstalled from "read-installed" ; import Immutable from "immutable" ; import path from "path" ; import Promise from "../utils/promise" ; import fs from "../utils/fs" ; import Plugin from "../models/plugin" ; import PREFIX from "../constants/pluginPrefix" ; return { boolean } function validateId ( name ) { return name && name . indexOf ( PREFIX ) === 0 ; } param { string } folder return { OrderedMap < String function findInstalled ( folder ) { const options = { dev : false , log : function ( ) { } , depth : 4 , } ; let results = Immutable . OrderedMap ( ) ; function onPackage ( pkg , parent ) { if ( ! pkg . name ) return ; const name = pkg . name ; const version = pkg . version ; const pkgPath = pkg . realPath ; const depth = pkg . depth ; const dependencies = pkg . dependencies ; const pluginName = name . slice ( PREFIX . length ) ; if ( ! validateId ( name ) ) { if ( parent ) return ; } else { results = results . set ( pluginName , new Plugin ( { name : pluginName , version : version , path : pkgPath , depth : depth , parent : parent , } ) ) ; } Immutable . Map ( dependencies ) . forEach ( ( dep ) => { onPackage ( dep , pluginName ) ; } ) ; } const node_modules = path . join ( folder , "node_modules" ) ; return fs . readdir ( node_modules ) . fail ( ( ) => { return Promise ( [ ] ) ; } ) . then ( ( modules ) => { return Promise . serie ( modules , ( module ) => { if ( ! validateId ( module ) ) { return Promise ( ) ; } const module_folder = path . join ( node_modules , module ) ; return Promise . nfcall ( readInstalled , module_folder , options ) . then ( ( data ) => { onPackage ( data ) ; } ) ; } ) ; } ) . then ( ( ) => { return results ; } ) ; } export default findInstalled ;