feat: detect apps for imported non-turborepo projects

- Fall back to CODEBASE_MAP.md parsing when no apps/ dir exists
- Further fallback: scan top-level dirs for deployable app signals
  (package.json, Dockerfile, requirements.txt, next.config.*, etc.)
- Skips docs, scripts, keys, and other non-app directories
- Returns isImport flag to frontend for context

Made-with: Cursor
This commit is contained in:
2026-03-09 11:52:10 -07:00
parent 01dd9fda8e
commit 65adcd4897

View File

@@ -48,6 +48,7 @@ export async function GET(
let apps: { name: string; path: string }[] = []; let apps: { name: string; path: string }[] = [];
if (giteaRepo) { if (giteaRepo) {
// First: try the standard turborepo apps/ directory
try { try {
const contents: Array<{ name: string; path: string; type: string }> = const contents: Array<{ name: string; path: string; type: string }> =
await giteaGet(`/repos/${giteaRepo}/contents/apps`); await giteaGet(`/repos/${giteaRepo}/contents/apps`);
@@ -55,11 +56,57 @@ export async function GET(
.filter((item) => item.type === 'dir') .filter((item) => item.type === 'dir')
.map(({ name, path }) => ({ name, path })); .map(({ name, path }) => ({ name, path }));
} catch { } 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') });
} }
/** /**