import UndirectedGraph from "./UndirectedGraph" ; import ProjectConfig from "@dxatscale/sfpowerscripts.core/lib/project/ProjectConfig" ; /**
 * Class for the manipulation of package build collections
 */ export default class BuildCollections { private _graph : UndirectedGraph ; constructor ( projectDirectory ) { this . createGraphOfBuildCollections ( projectDirectory ) ; } get graph ( ) : UndirectedGraph { return this . _graph ; } param projectDirectory private createGraphOfBuildCollections ( projectDirectory ) { this . _graph = new UndirectedGraph ( ) ; let projectConfig = ProjectConfig . getSFDXPackageManifest ( projectDirectory ) ; for ( let pkg of projectConfig . packageDirectories ) { if ( pkg . buildCollection ) { if ( pkg . buildCollection instanceof Array ) { if ( ! this . _graph . adjacencyList [ pkg . package ] ) this . _graph . addVertex ( pkg . package ) ; pkg . buildCollection . forEach ( ( packageInCollection ) => { if ( ! this . _graph . adjacencyList [ packageInCollection ] ) { if ( projectConfig . packageDirectories . find ( ( elem ) => elem . package === packageInCollection ) ) { this . _graph . addVertex ( packageInCollection ) ; } else throw new Error ( `Package '${ packageInCollection }' in collection ${ pkg . buildCollection } is not a valid package` ) ; } this . _graph . addEdge ( pkg . package , packageInCollection ) ; } ) ; } else throw new Error ( `Property 'buildCollection' must be of type Array. Received ${ pkg . buildCollection }` ) ; } } } param pkg listPackagesInCollection ( pkg ) { return this . _graph . dfs ( pkg ) ; } isPackageInACollection ( pkg ) { return this . _graph . adjacencyList [ pkg ] ? true : false ; } }