fix: detect apps in any repo structure, not just turborepo or flagged imports

Made-with: Cursor
This commit is contained in:
2026-03-09 17:23:38 -07:00
parent 22f4c4f1c3
commit 7979fd0518

View File

@@ -59,27 +59,24 @@ export async function GET(
// No apps/ dir — fall through to import detection below // No apps/ dir — fall through to import detection below
} }
// Fallback for imported (non-turborepo) projects: // Fallback: no apps/ dir — scan repo root for deployable components.
// Detect deployable components from top-level dirs and CODEBASE_MAP.md // Works for any project structure (imported, single-repo, monorepo variants).
if (apps.length === 0 && (data.isImport || data.creationMode === 'migration')) { if (apps.length === 0) {
try { try {
// Try to read CODEBASE_MAP.md first (written by ImportAnalyzer) // Try CODEBASE_MAP.md first (written by ImportAnalyzer for imported repos)
const mapFile = await giteaGet(`/repos/${giteaRepo}/contents/CODEBASE_MAP.md`).catch(() => null); const mapFile = await giteaGet(`/repos/${giteaRepo}/contents/CODEBASE_MAP.md`).catch(() => null);
if (mapFile?.content) { if (mapFile?.content) {
const decoded = Buffer.from(mapFile.content, 'base64').toString('utf-8'); const decoded = Buffer.from(mapFile.content, 'base64').toString('utf-8');
// Extract component folder paths from lines like "### Name — `folder/path`" or "### Name — folder/path"
const matches = [...decoded.matchAll(/###\s+.+?[—–-]\s+[`]?([^`\n(]+)[`]?/g)]; const matches = [...decoded.matchAll(/###\s+.+?[—–-]\s+[`]?([^`\n(]+)[`]?/g)];
const parsedApps = matches const parsedApps = matches
.map(m => m[1].trim().replace(/^`|`$/g, '').replace(/\/$/, '')) .map(m => m[1].trim().replace(/^`|`$/g, '').replace(/\/$/, ''))
.filter(p => p && p.length > 0 && !p.includes(' ') && !p.startsWith('http') && p !== '.') .filter(p => p && p.length > 0 && !p.includes(' ') && !p.startsWith('http') && p !== '.')
.map(p => ({ name: p.split('/').pop() ?? p, path: p })); .map(p => ({ name: p.split('/').pop() ?? p, path: p }));
if (parsedApps.length > 0) { if (parsedApps.length > 0) apps = parsedApps;
apps = parsedApps;
} }
} } catch { /* CODEBASE_MAP not available */ }
} catch { /* CODEBASE_MAP not ready yet */ }
// If still empty, scan top-level dirs and pick ones that look like apps // Scan top-level dirs for app signals
if (apps.length === 0) { if (apps.length === 0) {
try { try {
const SKIP = new Set(['docs', 'scripts', 'keys', '.github', 'node_modules', '.git', 'dist', 'build', 'coverage']); const SKIP = new Set(['docs', 'scripts', 'keys', '.github', 'node_modules', '.git', 'dist', 'build', 'coverage']);
@@ -88,22 +85,31 @@ export async function GET(
const root: Array<{ name: string; path: string; type: string }> = const root: Array<{ name: string; path: string; type: string }> =
await giteaGet(`/repos/${giteaRepo}/contents/`); await giteaGet(`/repos/${giteaRepo}/contents/`);
// Check if the root itself is an app (single-repo projects)
const rootIsApp = root.some(f => f.type === 'file' && APP_SIGNALS.includes(f.name));
if (rootIsApp) {
// Repo root is the app — use repo name as label, empty string as path
apps = [{ name: giteaRepo.split('/').pop() ?? 'app', path: '' }];
} else {
// Scan subdirs
const dirs = root.filter(i => i.type === 'dir' && !SKIP.has(i.name)); const dirs = root.filter(i => i.type === 'dir' && !SKIP.has(i.name));
const candidates = await Promise.all( const candidates = await Promise.all(
dirs.map(async (dir) => { dirs.map(async (dir) => {
try { try {
const sub: Array<{ name: string; type: string }> = await giteaGet(`/repos/${giteaRepo}/contents/${dir.path}`); const sub: Array<{ name: string; type: string }> = await giteaGet(`/repos/${giteaRepo}/contents/${dir.path}`);
// Check direct app signals OR subdirs that each contain app signals (monorepo-style) return sub.some(f => APP_SIGNALS.includes(f.name)) ? { name: dir.name, path: dir.path } : null;
const hasDirectSignal = sub.some(f => APP_SIGNALS.includes(f.name));
return hasDirectSignal ? { name: dir.name, path: dir.path } : null;
} catch { return null; } } catch { return null; }
}) })
); );
apps = candidates.filter((a): a is { name: string; path: string } => a !== null);
apps = candidates.filter((a): a is { name: string; path: string } => a !== null && a.name.length > 0); }
} catch { /* scan failed */ } } catch { /* scan failed */ }
} }
// Last resort: expose the repo root so the file tree still works
if (apps.length === 0) {
apps = [{ name: giteaRepo.split('/').pop() ?? 'app', path: '' }];
}
} }
} }