genbox 1.0.72 → 1.0.73
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 +40 -10
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -1539,11 +1539,17 @@ function sshToHttps(url) {
|
|
|
1539
1539
|
/**
|
|
1540
1540
|
* Auto-detect database URLs from project configuration
|
|
1541
1541
|
* Scans .env files, docker-compose, and other config sources
|
|
1542
|
+
*
|
|
1543
|
+
* Priority order:
|
|
1544
|
+
* 1. MONGODB_URI from .env files (what the app actually uses)
|
|
1545
|
+
* 2. Other database URL variables from .env files
|
|
1546
|
+
* 3. Docker-compose MongoDB port mappings (fallback)
|
|
1542
1547
|
*/
|
|
1543
1548
|
function detectDatabaseUrls(rootDir, detected) {
|
|
1544
1549
|
const results = [];
|
|
1545
1550
|
const seenUrls = new Set();
|
|
1546
1551
|
// 1. Scan .env files in various locations for MONGODB_URI, DATABASE_URL, etc.
|
|
1552
|
+
// Check multiple locations where .env files might exist
|
|
1547
1553
|
const envPatterns = [
|
|
1548
1554
|
'.env',
|
|
1549
1555
|
'.env.local',
|
|
@@ -1551,15 +1557,22 @@ function detectDatabaseUrls(rootDir, detected) {
|
|
|
1551
1557
|
'api/.env',
|
|
1552
1558
|
'api/.env.local',
|
|
1553
1559
|
'api/.env.development',
|
|
1560
|
+
'packages/api/.env',
|
|
1561
|
+
'packages/api/.env.local',
|
|
1562
|
+
'packages/api/.env.development',
|
|
1554
1563
|
];
|
|
1555
|
-
// Also check microservice-specific env files
|
|
1564
|
+
// Also check microservice-specific env files (NestJS monorepo pattern)
|
|
1556
1565
|
const microserviceDirs = ['gateway', 'auth', 'products', 'notifications', 'partner-api'];
|
|
1557
1566
|
for (const service of microserviceDirs) {
|
|
1558
1567
|
envPatterns.push(`api/apps/${service}/.env`);
|
|
1559
1568
|
envPatterns.push(`api/apps/${service}/.env.local`);
|
|
1560
1569
|
envPatterns.push(`api/apps/${service}/.env.development`);
|
|
1570
|
+
envPatterns.push(`packages/api/apps/${service}/.env`);
|
|
1571
|
+
envPatterns.push(`packages/api/apps/${service}/.env.local`);
|
|
1572
|
+
envPatterns.push(`packages/api/apps/${service}/.env.development`);
|
|
1561
1573
|
}
|
|
1562
|
-
// Database URL variable patterns to look for
|
|
1574
|
+
// Database URL variable patterns to look for (in priority order)
|
|
1575
|
+
// MONGODB_URI is the standard variable name used by most apps
|
|
1563
1576
|
const dbVarPatterns = [
|
|
1564
1577
|
'MONGODB_URI',
|
|
1565
1578
|
'MONGODB_URL',
|
|
@@ -1607,11 +1620,23 @@ function detectDatabaseUrls(rootDir, detected) {
|
|
|
1607
1620
|
// Extract port from URL
|
|
1608
1621
|
const portMatch = value.match(/mongodb:\/\/[^:]+:(\d+)/);
|
|
1609
1622
|
const port = portMatch ? parseInt(portMatch[1], 10) : undefined;
|
|
1623
|
+
// Calculate priority: MONGODB_URI with database name gets highest priority
|
|
1624
|
+
let priority = 10;
|
|
1625
|
+
if (varName === 'MONGODB_URI' && database)
|
|
1626
|
+
priority = 1;
|
|
1627
|
+
else if (varName === 'MONGODB_URI')
|
|
1628
|
+
priority = 2;
|
|
1629
|
+
else if (database)
|
|
1630
|
+
priority = 3;
|
|
1631
|
+
else
|
|
1632
|
+
priority = 5;
|
|
1610
1633
|
results.push({
|
|
1611
1634
|
url: value,
|
|
1612
1635
|
source: envPattern,
|
|
1613
1636
|
database,
|
|
1614
1637
|
port,
|
|
1638
|
+
priority,
|
|
1639
|
+
varName,
|
|
1615
1640
|
});
|
|
1616
1641
|
}
|
|
1617
1642
|
}
|
|
@@ -1619,7 +1644,7 @@ function detectDatabaseUrls(rootDir, detected) {
|
|
|
1619
1644
|
// Skip if can't read
|
|
1620
1645
|
}
|
|
1621
1646
|
}
|
|
1622
|
-
// 2. Check docker-compose for MongoDB services and construct URLs
|
|
1647
|
+
// 2. Check docker-compose for MongoDB services and construct URLs (lower priority)
|
|
1623
1648
|
if (detected.infrastructure) {
|
|
1624
1649
|
for (const infra of detected.infrastructure) {
|
|
1625
1650
|
if (infra.type !== 'database')
|
|
@@ -1635,27 +1660,32 @@ function detectDatabaseUrls(rootDir, detected) {
|
|
|
1635
1660
|
url,
|
|
1636
1661
|
source: `docker-compose (${infra.name})`,
|
|
1637
1662
|
port,
|
|
1663
|
+
priority: 20, // Lower priority than .env file URLs
|
|
1638
1664
|
});
|
|
1639
1665
|
}
|
|
1640
1666
|
}
|
|
1641
1667
|
}
|
|
1668
|
+
// Sort by priority (lower is better)
|
|
1669
|
+
results.sort((a, b) => a.priority - b.priority);
|
|
1642
1670
|
return results;
|
|
1643
1671
|
}
|
|
1644
1672
|
/**
|
|
1645
1673
|
* Build a suggested MongoDB URL from detected info
|
|
1674
|
+
* Returns the highest priority URL (already sorted by detectDatabaseUrls)
|
|
1646
1675
|
*/
|
|
1647
1676
|
function buildMongoDbUrl(detected, preferredDatabase) {
|
|
1648
1677
|
if (detected.length === 0)
|
|
1649
1678
|
return undefined;
|
|
1650
|
-
//
|
|
1679
|
+
// If preferredDatabase specified, try to find a match first
|
|
1680
|
+
if (preferredDatabase) {
|
|
1681
|
+
const match = detected.find(d => d.database === preferredDatabase);
|
|
1682
|
+
if (match)
|
|
1683
|
+
return match.url;
|
|
1684
|
+
}
|
|
1685
|
+
// Return the highest priority URL (list is already sorted)
|
|
1686
|
+
// Prefer URLs with database names
|
|
1651
1687
|
const withDb = detected.filter(d => d.database);
|
|
1652
1688
|
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
1689
|
return withDb[0].url;
|
|
1660
1690
|
}
|
|
1661
1691
|
// Fall back to first detected URL
|