@crossdelta/infrastructure 0.3.0-beta.2 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/generate-env.ts +8 -0
- package/package.json +1 -1
package/bin/generate-env.ts
CHANGED
|
@@ -20,6 +20,7 @@ type PulumiConfigEntry = {
|
|
|
20
20
|
|
|
21
21
|
interface MinimalServiceConfig {
|
|
22
22
|
name: string
|
|
23
|
+
primaryPort?: number
|
|
23
24
|
containerPort?: number
|
|
24
25
|
httpPort?: number
|
|
25
26
|
internalPorts?: number[]
|
|
@@ -94,8 +95,14 @@ const discoverServices = (servicesDir: string): MinimalServiceConfig[] => {
|
|
|
94
95
|
return files.map((file) => {
|
|
95
96
|
const content = readFileSync(join(servicesDir, file), 'utf-8')
|
|
96
97
|
|
|
98
|
+
// Extract port from new ports() API: ports().http(4001) or ports().primary(4222)
|
|
99
|
+
const portsApiMatch =
|
|
100
|
+
content.match(/ports\(\)\.(?:http|https|grpc|primary)\((\d+)\)/) ||
|
|
101
|
+
content.match(/ports\(\)\.add\((\d+)/)
|
|
102
|
+
|
|
97
103
|
return {
|
|
98
104
|
name: extract.string(content, /name:\s*['"]([^'"]+)['"]/) ?? file.replace('.ts', ''),
|
|
105
|
+
primaryPort: portsApiMatch?.[1] ? Number.parseInt(portsApiMatch[1], 10) : undefined,
|
|
99
106
|
containerPort: extract.number(content, /containerPort:\s*(\w+)/),
|
|
100
107
|
httpPort: extract.number(content, /httpPort:\s*(\w+)/),
|
|
101
108
|
internalPorts: extract.numberArray(content, /internalPorts:\s*\[([^\]]+)\]/),
|
|
@@ -105,6 +112,7 @@ const discoverServices = (servicesDir: string): MinimalServiceConfig[] => {
|
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
const getServicePort = (config: MinimalServiceConfig): number | undefined => {
|
|
115
|
+
if (config.primaryPort) return config.primaryPort // New ports() API
|
|
108
116
|
if (config.containerPort) return config.containerPort
|
|
109
117
|
if (config.httpPort) return config.httpPort
|
|
110
118
|
if (config.internalPorts?.[0]) return config.internalPorts[0]
|