@crossdelta/infrastructure 0.12.2 → 0.12.3
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.mjs +12 -1
- package/bin/generate-env.ts +19 -9
- package/package.json +1 -1
package/bin/generate-env.mjs
CHANGED
|
@@ -94,6 +94,13 @@ var getLocalUrl = (config) => {
|
|
|
94
94
|
}
|
|
95
95
|
return `http://localhost:${port}`;
|
|
96
96
|
};
|
|
97
|
+
var isDeploymentUrl = (value) => value.startsWith("https://") && !value.includes("localhost") && !value.includes("${");
|
|
98
|
+
var warnIfDeploymentUrl = (serviceName, key, value) => {
|
|
99
|
+
if (!isDeploymentUrl(value))
|
|
100
|
+
return;
|
|
101
|
+
console.warn(`⚠️ ${serviceName}: ${key}=${value} looks like a deployment URL and will be written to .env.local.
|
|
102
|
+
` + ` If this value is only meaningful in the deployed container, use containerEnv: instead of env:.`);
|
|
103
|
+
};
|
|
97
104
|
var buildServiceEnvLines = (serviceConfigs) => {
|
|
98
105
|
const lines = [];
|
|
99
106
|
lines.push("", "# Service URLs");
|
|
@@ -113,6 +120,7 @@ var buildServiceEnvLines = (serviceConfigs) => {
|
|
|
113
120
|
lines.push("", "# Service Environment");
|
|
114
121
|
for (const config of envLiteralConfigs) {
|
|
115
122
|
for (const [key, value] of Object.entries(config.envLiterals)) {
|
|
123
|
+
warnIfDeploymentUrl(config.name, key, value);
|
|
116
124
|
lines.push(`${key}=${value}`);
|
|
117
125
|
}
|
|
118
126
|
}
|
|
@@ -132,7 +140,10 @@ var findWorkspaceRoot = () => {
|
|
|
132
140
|
};
|
|
133
141
|
var loadPulumiConfig = async (infraDirectory, stack) => {
|
|
134
142
|
try {
|
|
135
|
-
const stdout = execSync(`pulumi config --show-secrets --json --stack ${stack} --cwd ${infraDirectory}`, {
|
|
143
|
+
const stdout = execSync(`pulumi config --show-secrets --json --stack ${stack} --cwd ${infraDirectory}`, {
|
|
144
|
+
encoding: "utf-8",
|
|
145
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
146
|
+
});
|
|
136
147
|
const config = JSON.parse(stdout);
|
|
137
148
|
return Object.entries(config).filter(([key]) => key.includes(":")).filter(([, entry]) => entry.value !== undefined && entry.value !== null && entry.value !== "undefined").map(([fullKey, entry]) => {
|
|
138
149
|
const [, rawKey] = fullKey.split(":");
|
package/bin/generate-env.ts
CHANGED
|
@@ -85,6 +85,17 @@ const getLocalUrl = (config: MinimalServiceConfig): string | undefined => {
|
|
|
85
85
|
return `http://localhost:${port}`
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
const isDeploymentUrl = (value: string): boolean =>
|
|
89
|
+
value.startsWith('https://') && !value.includes('localhost') && !value.includes('${')
|
|
90
|
+
|
|
91
|
+
const warnIfDeploymentUrl = (serviceName: string, key: string, value: string): void => {
|
|
92
|
+
if (!isDeploymentUrl(value)) return
|
|
93
|
+
console.warn(
|
|
94
|
+
`⚠️ ${serviceName}: ${key}=${value} looks like a deployment URL and will be written to .env.local.\n` +
|
|
95
|
+
` If this value is only meaningful in the deployed container, use containerEnv: instead of env:.`,
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
88
99
|
const buildServiceEnvLines = (serviceConfigs: MinimalServiceConfig[]): string[] => {
|
|
89
100
|
const lines: string[] = []
|
|
90
101
|
|
|
@@ -108,6 +119,7 @@ const buildServiceEnvLines = (serviceConfigs: MinimalServiceConfig[]): string[]
|
|
|
108
119
|
lines.push('', '# Service Environment')
|
|
109
120
|
for (const config of envLiteralConfigs) {
|
|
110
121
|
for (const [key, value] of Object.entries(config.envLiterals)) {
|
|
122
|
+
warnIfDeploymentUrl(config.name, key, value)
|
|
111
123
|
lines.push(`${key}=${value}`)
|
|
112
124
|
}
|
|
113
125
|
}
|
|
@@ -116,8 +128,7 @@ const buildServiceEnvLines = (serviceConfigs: MinimalServiceConfig[]): string[]
|
|
|
116
128
|
return lines
|
|
117
129
|
}
|
|
118
130
|
|
|
119
|
-
const hasLockFile = (directory: string): boolean =>
|
|
120
|
-
LOCK_FILES.some((file) => existsSync(join(directory, file)))
|
|
131
|
+
const hasLockFile = (directory: string): boolean => LOCK_FILES.some((file) => existsSync(join(directory, file)))
|
|
121
132
|
|
|
122
133
|
const findWorkspaceRoot = (): string => {
|
|
123
134
|
let directory = process.cwd()
|
|
@@ -131,10 +142,10 @@ const findWorkspaceRoot = (): string => {
|
|
|
131
142
|
|
|
132
143
|
const loadPulumiConfig = async (infraDirectory: string, stack: string): Promise<string[]> => {
|
|
133
144
|
try {
|
|
134
|
-
const stdout = execSync(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
)
|
|
145
|
+
const stdout = execSync(`pulumi config --show-secrets --json --stack ${stack} --cwd ${infraDirectory}`, {
|
|
146
|
+
encoding: 'utf-8',
|
|
147
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
148
|
+
})
|
|
138
149
|
|
|
139
150
|
const config = JSON.parse(stdout) as Record<string, PulumiConfigEntry>
|
|
140
151
|
|
|
@@ -160,8 +171,7 @@ const discoverServices = (servicesDirectory: string): MinimalServiceConfig[] =>
|
|
|
160
171
|
|
|
161
172
|
// Extract port from ports() API: ports().http(4001) or ports().primary(4222)
|
|
162
173
|
const portsApiMatch =
|
|
163
|
-
content.match(/ports\(\)\.(?:http|https|grpc|primary)\((\d+)\)/) ||
|
|
164
|
-
content.match(/ports\(\)\.add\((\d+)/)
|
|
174
|
+
content.match(/ports\(\)\.(?:http|https|grpc|primary)\((\d+)\)/) || content.match(/ports\(\)\.add\((\d+)/)
|
|
165
175
|
|
|
166
176
|
return {
|
|
167
177
|
name: extract.string(content, /name:\s*['"]([^'"]+)['"]/) ?? file.replace('.ts', ''),
|
|
@@ -193,7 +203,7 @@ const main = async () => {
|
|
|
193
203
|
}
|
|
194
204
|
|
|
195
205
|
const serviceConfigs = discoverServices(servicesDirectory)
|
|
196
|
-
|
|
206
|
+
|
|
197
207
|
if (serviceConfigs.length > 0) {
|
|
198
208
|
envLines.push(...buildServiceEnvLines(serviceConfigs))
|
|
199
209
|
console.log(`✅ Discovered ${serviceConfigs.length} services`)
|