const fs = require('fs'); const path = require('path'); const COMPONENTS_DIR = path.join(__dirname, 'src/components'); const APP_DIR = path.join(__dirname, 'src/app'); function getComponentType(filePath) { try { const content = fs.readFileSync(filePath, 'utf-8').trim(); // Only check the first 2 lines for 'use client' const firstLines = content.split('\n').slice(0, 2).join('\n'); if (firstLines.startsWith("'use client'") || firstLines.startsWith('"use client"')) { return 'Client Component'; } return 'Server Component'; } catch (error) { console.error(`Error reading file: ${filePath}`, error); return 'Unknown'; } } function getRenderingStrategy(filePath, componentType) { if (filePath.includes('/app/')) { if (filePath.includes('/api/')) return 'Server Only (API Route)'; if (filePath.endsWith('layout.tsx')) return 'Server Only (Layout)'; if (filePath.endsWith('page.tsx')) return componentType === 'Client Component' ? 'Client-Side Page' : 'Server Only (Page)'; return 'Server Component (Default)'; } if (filePath.includes('/components/')) { return 'Client-Side or Shared'; } return 'Unknown'; } function scanDirectory(directory) { let results = []; function scan(dir) { const files = fs.readdirSync(dir); for (const file of files) { const fullPath = path.join(dir, file); const stat = fs.statSync(fullPath); if (stat.isDirectory()) { scan(fullPath); } else if (file.endsWith('.tsx')) { const componentType = getComponentType(fullPath); const renderingStrategy = getRenderingStrategy(fullPath, componentType); results.push({ file: fullPath.replace(__dirname, ''), // Make paths relative type: componentType, rendering: renderingStrategy, }); } } } scan(directory); return results; } // Scan app and components directories const componentsAnalysis = [ ...scanDirectory(COMPONENTS_DIR), ...scanDirectory(APP_DIR), ]; // Display results console.table(componentsAnalysis);