-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
40 lines (30 loc) · 1.17 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as chewy from '@gochewy/lib';
import * as pulumi from "@pulumi/pulumi";
import ComponentOutput from "./component-output";
import dev from "./dev";
export = async (): Promise<ComponentOutput | undefined> => {
const stackName = pulumi.getStack();
const environment = stackName.split('--')[0]
const graph = chewy.project.getDependencyGraph(environment)
const componentName = chewy.components.getComponentName();
if(!componentName) {
throw new Error('Could not find component name')
}
const deployedId = chewy.components.getDeployedComponentId({name: componentName}, environment)
// get infra dependency
const infraDepIds = graph.dependenciesOf(deployedId)
.filter(depedency => {
const nodeData = graph.getNodeData(depedency)
return nodeData.type === chewy.config.component.componentTypeSchema.Values.infrastructure
})
if(infraDepIds.length > 1) {
throw new Error('More than one infra dependency found')
}
if(infraDepIds.length === 0) {
throw new Error('No infra dependency found')
}
const infraDep = graph.getNodeData(infraDepIds[0])
if(infraDep.definition.name === 'docker-development-host') {
return dev();
}
};