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.
@@ -153,44 +153,65 @@ function getServiceNameFromUrl(baseUrl) {
153
153
  return { name: 'unknown', varPrefix: 'UNKNOWN', description: 'Unknown Service' };
154
154
  }
155
155
  /**
156
- * Prompt user for staging URLs for each unique service URL found in frontend apps
156
+ * Create service URL mappings based on configured environments
157
+ * Uses URLs from configured environments instead of prompting again
157
158
  */
158
- async function promptForStagingUrls(serviceUrls, existingStagingApiUrl) {
159
+ async function createServiceUrlMappings(serviceUrls, configuredEnvs) {
159
160
  const mappings = [];
160
161
  if (serviceUrls.size === 0) {
161
162
  return mappings;
162
163
  }
163
- console.log('');
164
- console.log(chalk_1.default.blue('=== Frontend Service URL Configuration ==='));
165
- console.log(chalk_1.default.dim('Frontend apps have service URLs that need staging equivalents.'));
166
- console.log(chalk_1.default.dim('This enables profiles like admin-quick to connect to staging backend.'));
167
- console.log('');
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
- for (const [baseUrl, { urls, vars }] of sortedServices) {
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
- // Show what URLs use this service
177
- console.log(chalk_1.default.cyan(`${serviceInfo.description} (${baseUrl})`));
178
- console.log(chalk_1.default.dim(` Used by: ${vars.slice(0, 3).join(', ')}${vars.length > 3 ? ` +${vars.length - 3} more` : ''}`));
179
- // For gateway, suggest existing staging URL if available
180
- let defaultUrl = '';
181
- if ((serviceInfo.name === 'gateway' || baseUrl.includes(':3050')) && existingStagingApiUrl) {
182
- defaultUrl = existingStagingApiUrl;
183
- }
184
- const stagingUrl = await prompts.input({
185
- message: ` Staging URL (leave empty to skip):`,
186
- default: defaultUrl,
187
- });
188
- mappings.push({
189
- varName: `${serviceInfo.varPrefix}_URL`,
190
- localUrl: baseUrl,
191
- stagingUrl: stagingUrl || undefined,
192
- description: serviceInfo.description,
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
- '# These expand based on profile: ${GATEWAY_URL} → LOCAL or STAGING value',
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.stagingUrl) {
214
- globalAdditions.push(`STAGING_${mapping.varName}=${mapping.stagingUrl}`);
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
- // Get existing staging API URL if configured
1500
- const existingStagingApiUrl = extraEnvVars['STAGING_API_URL'] ||
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
- segregatedContent = transformEnvWithVariables(segregatedContent, urlMappings, frontendApps);
1507
- console.log('');
1508
- console.log(chalk_1.default.green(`✓ Configured ${urlMappings.length} service URL(s) for staging support`));
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genbox",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Genbox CLI - AI-Powered Development Environments",
5
5
  "main": "dist/index.js",
6
6
  "bin": {