import { EnvironmentFlags , EnvironmentType , FabricEnvironmentRegistryEntry } from './FabricEnvironmentRegistryEntry' ; import { FileConfigurations } from './FileConfigurations' ; import { FileRegistry } from './FileRegistry' ; export class FabricEnvironmentRegistry extends FileRegistry < FabricEnvironmentRegistryEntry > { public static instance ( ) { return FabricEnvironmentRegistry . _instance ; } private static _instance : FabricEnvironmentRegistry = new FabricEnvironmentRegistry ( ) ; private constructor ( ) { super ( FileConfigurations . FABRIC_ENVIRONMENTS ) ; } public async getAll ( includeFilter = [ ] , excludeFilter = [ ] ) { let entries = await super . getAll ( ) ; const local = [ ] ; entries = this . filterEnvironments ( entries , includeFilter , excludeFilter ) ; entries = entries . filter ( ( entry ) => { if ( entry . environmentType === EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT ) { local . push ( entry ) ; return false ; } return true ; } ) ; entries . unshift ( ... local ) ; return entries ; } private filterEnvironments ( environments , includeFilter , excludeFilter ) { return environments . filter ( ( environment ) => { const environmentType = environment . environmentType ; for ( const exclude of excludeFilter ) { const result = environmentType & exclude ; if ( result === exclude ) { return false ; } } if ( includeFilter . length > 0 ) { let match = false ; for ( const include of includeFilter ) { const result = environmentType & include ; if ( result === include ) { match = true ; break ; } } return match ; } else { return true ; } } ) ; } }