diff --git a/app/api/projects/[projectId]/apps/route.ts b/app/api/projects/[projectId]/apps/route.ts index 9b9dc5b..dee52d5 100644 --- a/app/api/projects/[projectId]/apps/route.ts +++ b/app/api/projects/[projectId]/apps/route.ts @@ -48,6 +48,7 @@ export async function GET( let apps: { name: string; path: string }[] = []; if (giteaRepo) { + // First: try the standard turborepo apps/ directory try { const contents: Array<{ name: string; path: string; type: string }> = await giteaGet(`/repos/${giteaRepo}/contents/apps`); @@ -55,11 +56,57 @@ export async function GET( .filter((item) => item.type === 'dir') .map(({ name, path }) => ({ name, path })); } catch { - // Repo may not have an apps/ dir yet — return empty list gracefully + // 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')) { + try { + // Try to read CODEBASE_MAP.md first (written by ImportAnalyzer) + 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 the map (lines like "### [name] — folder/path") + const matches = [...decoded.matchAll(/###\s+.+?—\s+([^\n(]+)/g)]; + const parsedApps = matches + .map(m => m[1].trim()) + .filter(p => p && !p.includes(' ') && !p.startsWith('http')) + .map(p => ({ name: p.split('/').pop() ?? p, path: p })); + if (parsedApps.length > 0) { + apps = parsedApps; + } + } + } catch { /* CODEBASE_MAP not ready yet */ } + + // If still empty, scan top-level dirs and pick ones that look like apps + if (apps.length === 0) { + try { + const SKIP = new Set(['docs', 'scripts', 'keys', '.github', 'node_modules', '.git', 'dist', 'build', 'coverage']); + const APP_SIGNALS = ['package.json', 'requirements.txt', 'pyproject.toml', 'Dockerfile', 'next.config.ts', 'next.config.js', 'vite.config.ts', 'main.py', 'app.py', 'index.js', 'server.ts']; + + 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 }> = await giteaGet(`/repos/${giteaRepo}/contents/${dir.path}`); + const isApp = sub.some(f => APP_SIGNALS.includes(f.name)); + return isApp ? { 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 */ } + } } } - return NextResponse.json({ apps, designPackages, giteaRepo }); + return NextResponse.json({ apps, designPackages, giteaRepo, isImport: !!(data.isImport || data.creationMode === 'migration') }); } /**