/**
 * Vite analyzer
 * Analyzes Vite projects with API proxy configurations
 */
import * as fs from 'fs';
import * as path from 'path';
/**
 * Analyze Vite API proxy routes
 */
export async function analyzeVite(viteConfigPath = 'vite.config.js') {
    const routes = [];
    try {
        const configPath = path.join(process.cwd(), viteConfigPath);
        if (!fs.existsSync(configPath)) {
            console.warn('vite.config.js not found');
            return routes;
        }
        const content = fs.readFileSync(configPath, 'utf-8');
        // Extract proxy configurations
        const proxyRegex = /proxy:\s*{([^}]+)}/gs;
        const proxyMatch = content.match(proxyRegex);
        if (proxyMatch) {
            const proxyContent = proxyMatch[0];
            // Extract proxy routes like '/api': { target: 'http://localhost:3000' }
            const routeRegex = /['"`]([^'"`]+)['"`]\s*:\s*{/g;
            let match;
            while ((match = routeRegex.exec(proxyContent)) !== null) {
                const proxyPath = match[1];
                // Create route entry
                routes.push({
                    method: 'ALL',
                    path: proxyPath,
                    description: `Vite proxy: ${proxyPath}`,
                    tags: ['proxy'],
                    middleware: [],
                    responses: {
                        '200': { description: 'Proxied response' }
                    }
                });
            }
        }
        console.log(`✅ Found ${routes.length} Vite proxy routes`);
    }
    catch (error) {
        console.error('Error analyzing Vite config:', error.message);
    }
    return routes;
}
