genbox 1.0.28 → 1.0.29
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/dist/commands/init.js +63 -41
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -153,44 +153,65 @@ function getServiceNameFromUrl(baseUrl) {
|
|
|
153
153
|
return { name: 'unknown', varPrefix: 'UNKNOWN', description: 'Unknown Service' };
|
|
154
154
|
}
|
|
155
155
|
/**
|
|
156
|
-
*
|
|
156
|
+
* Create service URL mappings based on configured environments
|
|
157
|
+
* Uses URLs from configured environments instead of prompting again
|
|
157
158
|
*/
|
|
158
|
-
async function
|
|
159
|
+
async function createServiceUrlMappings(serviceUrls, configuredEnvs) {
|
|
159
160
|
const mappings = [];
|
|
160
161
|
if (serviceUrls.size === 0) {
|
|
161
162
|
return mappings;
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
// Determine which environment to use (prefer staging, then production)
|
|
165
|
+
const envNames = Object.keys(configuredEnvs || {});
|
|
166
|
+
const primaryEnv = envNames.includes('staging') ? 'staging' :
|
|
167
|
+
envNames.includes('production') ? 'production' :
|
|
168
|
+
envNames[0];
|
|
169
|
+
if (!primaryEnv || !configuredEnvs?.[primaryEnv]) {
|
|
170
|
+
// No environments configured - skip service URL mapping
|
|
171
|
+
return mappings;
|
|
172
|
+
}
|
|
173
|
+
const envConfig = configuredEnvs[primaryEnv];
|
|
174
|
+
const apiUrl = envConfig.urls?.api;
|
|
175
|
+
if (!apiUrl) {
|
|
176
|
+
// No API URL configured - skip
|
|
177
|
+
return mappings;
|
|
178
|
+
}
|
|
168
179
|
// Sort by port number for consistent ordering
|
|
169
180
|
const sortedServices = Array.from(serviceUrls.entries()).sort((a, b) => {
|
|
170
181
|
const portA = parseInt(a[0].match(/:(\d+)/)?.[1] || '0');
|
|
171
182
|
const portB = parseInt(b[0].match(/:(\d+)/)?.[1] || '0');
|
|
172
183
|
return portA - portB;
|
|
173
184
|
});
|
|
174
|
-
|
|
185
|
+
console.log('');
|
|
186
|
+
console.log(chalk_1.default.blue('=== Service URL Mapping ==='));
|
|
187
|
+
console.log(chalk_1.default.dim(`Mapping localhost URLs to ${primaryEnv} environment`));
|
|
188
|
+
console.log('');
|
|
189
|
+
for (const [baseUrl, { vars }] of sortedServices) {
|
|
175
190
|
const serviceInfo = getServiceNameFromUrl(baseUrl);
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
// Auto-map API/gateway URLs to the configured API URL
|
|
192
|
+
const isApiService = serviceInfo.name === 'gateway' ||
|
|
193
|
+
baseUrl.includes(':3050') ||
|
|
194
|
+
baseUrl.includes(':3105') ||
|
|
195
|
+
vars.some(v => v.toLowerCase().includes('api'));
|
|
196
|
+
if (isApiService && apiUrl) {
|
|
197
|
+
console.log(chalk_1.default.green(`✓ ${serviceInfo.description}: ${baseUrl} → ${apiUrl}`));
|
|
198
|
+
mappings.push({
|
|
199
|
+
varName: `${serviceInfo.varPrefix}_URL`,
|
|
200
|
+
localUrl: baseUrl,
|
|
201
|
+
remoteUrl: apiUrl,
|
|
202
|
+
remoteEnv: primaryEnv,
|
|
203
|
+
description: serviceInfo.description,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// For non-API services, just record the local URL without remote
|
|
208
|
+
console.log(chalk_1.default.dim(` ${serviceInfo.description}: ${baseUrl} (local only)`));
|
|
209
|
+
mappings.push({
|
|
210
|
+
varName: `${serviceInfo.varPrefix}_URL`,
|
|
211
|
+
localUrl: baseUrl,
|
|
212
|
+
description: serviceInfo.description,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
194
215
|
}
|
|
195
216
|
return mappings;
|
|
196
217
|
}
|
|
@@ -202,19 +223,19 @@ function transformEnvWithVariables(envContent, mappings, frontendApps) {
|
|
|
202
223
|
return envContent;
|
|
203
224
|
}
|
|
204
225
|
let result = envContent;
|
|
226
|
+
// Determine the environment name for comments
|
|
227
|
+
const envName = mappings.find(m => m.remoteEnv)?.remoteEnv?.toUpperCase() || 'REMOTE';
|
|
205
228
|
// Build GLOBAL section additions
|
|
206
229
|
const globalAdditions = [
|
|
207
230
|
'',
|
|
208
231
|
'# Service URL Configuration',
|
|
209
|
-
|
|
232
|
+
`# These expand based on profile: \${GATEWAY_URL} → LOCAL or ${envName} value`,
|
|
210
233
|
];
|
|
211
234
|
for (const mapping of mappings) {
|
|
212
235
|
globalAdditions.push(`LOCAL_${mapping.varName}=${mapping.localUrl}`);
|
|
213
|
-
if (mapping.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
else {
|
|
217
|
-
globalAdditions.push(`# STAGING_${mapping.varName}=https://your-staging-url.com`);
|
|
236
|
+
if (mapping.remoteUrl && mapping.remoteEnv) {
|
|
237
|
+
const prefix = mapping.remoteEnv.toUpperCase();
|
|
238
|
+
globalAdditions.push(`${prefix}_${mapping.varName}=${mapping.remoteUrl}`);
|
|
218
239
|
}
|
|
219
240
|
}
|
|
220
241
|
globalAdditions.push('');
|
|
@@ -1495,17 +1516,18 @@ async function setupEnvFile(projectName, config, nonInteractive = false, scan, i
|
|
|
1495
1516
|
// Fall back to extracting from collected env content
|
|
1496
1517
|
serviceUrls = extractFrontendHttpUrls(segregatedContent, frontendApps);
|
|
1497
1518
|
}
|
|
1498
|
-
if (serviceUrls.size > 0) {
|
|
1499
|
-
//
|
|
1500
|
-
const
|
|
1501
|
-
(config.environments?.staging?.urls?.api);
|
|
1502
|
-
// Prompt for staging equivalents
|
|
1503
|
-
const urlMappings = await promptForStagingUrls(serviceUrls, existingStagingApiUrl);
|
|
1519
|
+
if (serviceUrls.size > 0 && config.environments) {
|
|
1520
|
+
// Create mappings based on configured environments (no prompting needed)
|
|
1521
|
+
const urlMappings = await createServiceUrlMappings(serviceUrls, config.environments);
|
|
1504
1522
|
// Transform content with expandable variables
|
|
1505
1523
|
if (urlMappings.length > 0) {
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1524
|
+
const mappedCount = urlMappings.filter(m => m.remoteUrl).length;
|
|
1525
|
+
if (mappedCount > 0) {
|
|
1526
|
+
segregatedContent = transformEnvWithVariables(segregatedContent, urlMappings, frontendApps);
|
|
1527
|
+
const envName = urlMappings.find(m => m.remoteEnv)?.remoteEnv || 'remote';
|
|
1528
|
+
console.log('');
|
|
1529
|
+
console.log(chalk_1.default.green(`✓ Configured ${mappedCount} service URL(s) for ${envName} environment`));
|
|
1530
|
+
}
|
|
1509
1531
|
}
|
|
1510
1532
|
}
|
|
1511
1533
|
}
|