genbox 1.0.72 → 1.0.74

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.
@@ -690,13 +690,15 @@ async function setupEnvironmentsAndServiceUrls(detected, existingEnvValues) {
690
690
  console.log('');
691
691
  console.log(chalk_1.default.blue('=== Environment Configuration ==='));
692
692
  console.log('');
693
- // Auto-detect database URLs from project
693
+ // Auto-detect database URLs from project (informational only)
694
+ // Note: These are typically LOCAL dev databases, not production sources for snapshots
694
695
  const detectedDbUrls = detectDatabaseUrls(detected._meta.scanned_root, detected);
695
696
  if (detectedDbUrls.length > 0) {
696
- console.log(chalk_1.default.dim('Detected database URLs in project:'));
697
+ console.log(chalk_1.default.dim('Detected database URLs in project (for reference):'));
697
698
  for (const db of detectedDbUrls) {
699
+ const info = db.varName ? `${db.varName} in ${db.source}` : db.source;
698
700
  console.log(chalk_1.default.dim(` • ${db.url}`));
699
- console.log(chalk_1.default.dim(` └─ from ${db.source}${db.database ? ` (database: ${db.database})` : ''}`));
701
+ console.log(chalk_1.default.dim(` └─ from ${info}${db.database ? ` (database: ${db.database})` : ''}`));
700
702
  }
701
703
  console.log('');
702
704
  }
@@ -714,11 +716,9 @@ async function setupEnvironmentsAndServiceUrls(detected, existingEnvValues) {
714
716
  if (envChoice !== 'skip') {
715
717
  console.log('');
716
718
  console.log(chalk_1.default.dim('These URLs will be used when connecting to external services.'));
717
- console.log(chalk_1.default.dim('MongoDB URLs are used for taking database snapshots to copy to genbox.'));
719
+ console.log(chalk_1.default.dim('MongoDB URLs should point to PRODUCTION/STAGING databases (source for snapshots).'));
718
720
  const configureStaging = envChoice === 'staging' || envChoice === 'both';
719
721
  const configureProduction = envChoice === 'production' || envChoice === 'both';
720
- // Build suggested MongoDB URL from detected sources
721
- const suggestedMongoUrl = buildMongoDbUrl(detectedDbUrls);
722
722
  if (configureStaging) {
723
723
  console.log('');
724
724
  console.log(chalk_1.default.cyan('Staging Environment:'));
@@ -730,13 +730,9 @@ async function setupEnvironmentsAndServiceUrls(detected, existingEnvValues) {
730
730
  };
731
731
  envVars['STAGING_API_URL'] = stagingApiUrl;
732
732
  }
733
- // Use auto-detected URL as default if no existing value
733
+ // Keep existing value - don't auto-suggest local dev URLs for snapshot sources
734
734
  const existingStagingMongo = existingEnvValues['STAGING_MONGODB_URL'];
735
- const stagingMongoDefault = existingStagingMongo || suggestedMongoUrl;
736
- if (stagingMongoDefault && !existingStagingMongo) {
737
- console.log(chalk_1.default.dim(` Auto-detected: ${stagingMongoDefault}`));
738
- }
739
- const stagingMongoUrl = await promptWithExisting(' Staging MongoDB URL (for snapshots):', stagingMongoDefault, true);
735
+ const stagingMongoUrl = await promptWithExisting(' Staging MongoDB URL (for snapshots):', existingStagingMongo, true);
740
736
  if (stagingMongoUrl) {
741
737
  envVars['STAGING_MONGODB_URL'] = stagingMongoUrl;
742
738
  }
@@ -756,13 +752,9 @@ async function setupEnvironmentsAndServiceUrls(detected, existingEnvValues) {
756
752
  };
757
753
  envVars['PRODUCTION_API_URL'] = prodApiUrl;
758
754
  }
759
- // Use auto-detected URL as default if no existing value
755
+ // Keep existing value - don't auto-suggest local dev URLs for snapshot sources
760
756
  const existingProdMongo = existingEnvValues['PROD_MONGODB_URL'] || existingEnvValues['PRODUCTION_MONGODB_URL'];
761
- const prodMongoDefault = existingProdMongo || suggestedMongoUrl;
762
- if (prodMongoDefault && !existingProdMongo) {
763
- console.log(chalk_1.default.dim(` Auto-detected: ${prodMongoDefault}`));
764
- }
765
- const prodMongoUrl = await promptWithExisting(' Production MongoDB URL (for snapshots):', prodMongoDefault, true);
757
+ const prodMongoUrl = await promptWithExisting(' Production MongoDB URL (for snapshots):', existingProdMongo, true);
766
758
  if (prodMongoUrl) {
767
759
  envVars['PROD_MONGODB_URL'] = prodMongoUrl;
768
760
  }
@@ -1539,11 +1531,17 @@ function sshToHttps(url) {
1539
1531
  /**
1540
1532
  * Auto-detect database URLs from project configuration
1541
1533
  * Scans .env files, docker-compose, and other config sources
1534
+ *
1535
+ * Priority order:
1536
+ * 1. MONGODB_URI from .env files (what the app actually uses)
1537
+ * 2. Other database URL variables from .env files
1538
+ * 3. Docker-compose MongoDB port mappings (fallback)
1542
1539
  */
1543
1540
  function detectDatabaseUrls(rootDir, detected) {
1544
1541
  const results = [];
1545
1542
  const seenUrls = new Set();
1546
1543
  // 1. Scan .env files in various locations for MONGODB_URI, DATABASE_URL, etc.
1544
+ // Check multiple locations where .env files might exist
1547
1545
  const envPatterns = [
1548
1546
  '.env',
1549
1547
  '.env.local',
@@ -1551,15 +1549,22 @@ function detectDatabaseUrls(rootDir, detected) {
1551
1549
  'api/.env',
1552
1550
  'api/.env.local',
1553
1551
  'api/.env.development',
1552
+ 'packages/api/.env',
1553
+ 'packages/api/.env.local',
1554
+ 'packages/api/.env.development',
1554
1555
  ];
1555
- // Also check microservice-specific env files
1556
+ // Also check microservice-specific env files (NestJS monorepo pattern)
1556
1557
  const microserviceDirs = ['gateway', 'auth', 'products', 'notifications', 'partner-api'];
1557
1558
  for (const service of microserviceDirs) {
1558
1559
  envPatterns.push(`api/apps/${service}/.env`);
1559
1560
  envPatterns.push(`api/apps/${service}/.env.local`);
1560
1561
  envPatterns.push(`api/apps/${service}/.env.development`);
1562
+ envPatterns.push(`packages/api/apps/${service}/.env`);
1563
+ envPatterns.push(`packages/api/apps/${service}/.env.local`);
1564
+ envPatterns.push(`packages/api/apps/${service}/.env.development`);
1561
1565
  }
1562
- // Database URL variable patterns to look for
1566
+ // Database URL variable patterns to look for (in priority order)
1567
+ // MONGODB_URI is the standard variable name used by most apps
1563
1568
  const dbVarPatterns = [
1564
1569
  'MONGODB_URI',
1565
1570
  'MONGODB_URL',
@@ -1607,11 +1612,23 @@ function detectDatabaseUrls(rootDir, detected) {
1607
1612
  // Extract port from URL
1608
1613
  const portMatch = value.match(/mongodb:\/\/[^:]+:(\d+)/);
1609
1614
  const port = portMatch ? parseInt(portMatch[1], 10) : undefined;
1615
+ // Calculate priority: MONGODB_URI with database name gets highest priority
1616
+ let priority = 10;
1617
+ if (varName === 'MONGODB_URI' && database)
1618
+ priority = 1;
1619
+ else if (varName === 'MONGODB_URI')
1620
+ priority = 2;
1621
+ else if (database)
1622
+ priority = 3;
1623
+ else
1624
+ priority = 5;
1610
1625
  results.push({
1611
1626
  url: value,
1612
1627
  source: envPattern,
1613
1628
  database,
1614
1629
  port,
1630
+ priority,
1631
+ varName,
1615
1632
  });
1616
1633
  }
1617
1634
  }
@@ -1619,7 +1636,7 @@ function detectDatabaseUrls(rootDir, detected) {
1619
1636
  // Skip if can't read
1620
1637
  }
1621
1638
  }
1622
- // 2. Check docker-compose for MongoDB services and construct URLs
1639
+ // 2. Check docker-compose for MongoDB services and construct URLs (lower priority)
1623
1640
  if (detected.infrastructure) {
1624
1641
  for (const infra of detected.infrastructure) {
1625
1642
  if (infra.type !== 'database')
@@ -1635,27 +1652,32 @@ function detectDatabaseUrls(rootDir, detected) {
1635
1652
  url,
1636
1653
  source: `docker-compose (${infra.name})`,
1637
1654
  port,
1655
+ priority: 20, // Lower priority than .env file URLs
1638
1656
  });
1639
1657
  }
1640
1658
  }
1641
1659
  }
1660
+ // Sort by priority (lower is better)
1661
+ results.sort((a, b) => a.priority - b.priority);
1642
1662
  return results;
1643
1663
  }
1644
1664
  /**
1645
1665
  * Build a suggested MongoDB URL from detected info
1666
+ * Returns the highest priority URL (already sorted by detectDatabaseUrls)
1646
1667
  */
1647
1668
  function buildMongoDbUrl(detected, preferredDatabase) {
1648
1669
  if (detected.length === 0)
1649
1670
  return undefined;
1650
- // Prefer URLs that have a database name
1671
+ // If preferredDatabase specified, try to find a match first
1672
+ if (preferredDatabase) {
1673
+ const match = detected.find(d => d.database === preferredDatabase);
1674
+ if (match)
1675
+ return match.url;
1676
+ }
1677
+ // Return the highest priority URL (list is already sorted)
1678
+ // Prefer URLs with database names
1651
1679
  const withDb = detected.filter(d => d.database);
1652
1680
  if (withDb.length > 0) {
1653
- // Prefer the one matching preferredDatabase if specified
1654
- if (preferredDatabase) {
1655
- const match = withDb.find(d => d.database === preferredDatabase);
1656
- if (match)
1657
- return match.url;
1658
- }
1659
1681
  return withDb[0].url;
1660
1682
  }
1661
1683
  // Fall back to first detected URL
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genbox",
3
- "version": "1.0.72",
3
+ "version": "1.0.74",
4
4
  "description": "Genbox CLI - AI-Powered Development Environments",
5
5
  "main": "dist/index.js",
6
6
  "bin": {