diff --git a/app/api/projects/[projectId]/apps/route.ts b/app/api/projects/[projectId]/apps/route.ts index 727a5e0..d0d2701 100644 --- a/app/api/projects/[projectId]/apps/route.ts +++ b/app/api/projects/[projectId]/apps/route.ts @@ -59,27 +59,24 @@ export async function GET( // No apps/ dir — fall through to import detection below } - // Fallback for imported (non-turborepo) projects: - // Detect deployable components from top-level dirs and CODEBASE_MAP.md - if (apps.length === 0 && (data.isImport || data.creationMode === 'migration')) { + // Fallback: no apps/ dir — scan repo root for deployable components. + // Works for any project structure (imported, single-repo, monorepo variants). + if (apps.length === 0) { 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); if (mapFile?.content) { 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 parsedApps = matches .map(m => m[1].trim().replace(/^`|`$/g, '').replace(/\/$/, '')) .filter(p => p && p.length > 0 && !p.includes(' ') && !p.startsWith('http') && p !== '.') .map(p => ({ name: p.split('/').pop() ?? p, path: p })); - if (parsedApps.length > 0) { - apps = parsedApps; - } + if (parsedApps.length > 0) apps = parsedApps; } - } catch { /* CODEBASE_MAP not ready yet */ } + } catch { /* CODEBASE_MAP not available */ } - // 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) { try { 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 }> = await giteaGet(`/repos/${giteaRepo}/contents/`); - const dirs = root.filter(i => i.type === 'dir' && !SKIP.has(i.name)); - - const candidates = await Promise.all( - dirs.map(async (dir) => { - try { - 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) - const hasDirectSignal = sub.some(f => APP_SIGNALS.includes(f.name)); - return hasDirectSignal ? { name: dir.name, path: dir.path } : null; - } catch { return null; } - }) - ); - - apps = candidates.filter((a): a is { name: string; path: string } => a !== null && a.name.length > 0); + // 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 candidates = await Promise.all( + dirs.map(async (dir) => { + try { + const sub: Array<{ name: string; type: string }> = await giteaGet(`/repos/${giteaRepo}/contents/${dir.path}`); + return sub.some(f => APP_SIGNALS.includes(f.name)) ? { name: dir.name, path: dir.path } : null; + } catch { return null; } + }) + ); + apps = candidates.filter((a): a is { name: string; path: string } => a !== null); + } } 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: '' }]; + } } }