UNPKG

arela

Version:

AI-powered CTO with multi-agent orchestration, code summarization, visual testing (web + mobile) for blazing fast development.

145 lines 3.92 kB
/** * File Scanner - Scans directories for TypeScript/JavaScript files */ import glob from "fast-glob"; import path from "path"; import fs from "fs"; const SUPPORTED_EXTENSIONS = [ // JavaScript/TypeScript '.ts', '.tsx', '.js', '.jsx', '.mts', '.mjs', // Python '.py', // Go '.go', // Rust '.rs', // Ruby '.rb', // PHP '.php', // Java '.java', // C# '.cs', // C/C++ '.c', '.cpp', '.h', '.hpp', // Swift '.swift', // Kotlin '.kt', ]; const IGNORED_PATTERNS = [ '**/node_modules/**', '**/.git/**', '**/dist/**', '**/build/**', '**/.next/**', '**/coverage/**', '**/test/**', '**/*.test.ts', '**/*.spec.ts', '**/*.d.ts', '.arela/**', // Mobile dependencies (without leading **) 'ios/Pods/**', 'android/build/**', 'android/.gradle/**', // Python dependencies 'venv/**', '.venv/**', '**/site-packages/**', // Ruby dependencies 'vendor/bundle/**', // Go dependencies 'vendor/**', ]; /** * Scan a directory for TypeScript/JavaScript files */ export async function scanDirectory(repoPath, options) { const absolutePath = path.resolve(repoPath); if (!fs.existsSync(absolutePath)) { throw new Error(`Directory not found: ${absolutePath}`); } const ignorePatterns = [...IGNORED_PATTERNS, ...(options?.ignore ?? [])]; try { // Build glob pattern: **/*.{ts,tsx,js,jsx,...} const extensionsWithoutDot = SUPPORTED_EXTENSIONS.map(ext => ext.slice(1)); const files = await glob(`**/*.{${extensionsWithoutDot.join(',')}}`, { cwd: absolutePath, ignore: ignorePatterns, absolute: false, dot: false, }); return files.filter(file => { // Filter by supported extensions const ext = path.extname(file); return SUPPORTED_EXTENSIONS.includes(ext); }); } catch (error) { throw new Error(`Failed to scan directory ${absolutePath}: ${error}`); } } /** * Get line count of a file */ export function getLineCount(filePath) { try { const content = fs.readFileSync(filePath, 'utf-8'); return content.split('\n').length; } catch { return 0; } } /** * Determine file type based on path and content */ export function determineFileType(filePath, content) { const fileName = path.basename(filePath).toLowerCase(); const dirPath = path.dirname(filePath).toLowerCase(); // Type definitions if (fileName.endsWith('.d.ts')) return 'type'; // Configuration files if (fileName.includes('config') || fileName === 'vite.config.ts' || fileName === 'tsconfig.json' || fileName === 'jest.config.ts') { return 'config'; } // React Hooks if (fileName.startsWith('use') && (fileName.endsWith('.ts') || fileName.endsWith('.tsx'))) { return 'hook'; } // Components if (fileName.endsWith('.component.ts') || fileName.endsWith('.component.tsx') || dirPath.includes('component') || dirPath.includes('components') || (fileName[0] === fileName[0].toUpperCase() && fileName.endsWith('.tsx'))) { return 'component'; } // Services if (fileName.endsWith('.service.ts') || dirPath.includes('service') || dirPath.includes('services')) { return 'service'; } // Controllers if (fileName.endsWith('.controller.ts') || dirPath.includes('controller') || dirPath.includes('controllers')) { return 'controller'; } // Utilities if (fileName.includes('util') || fileName.includes('helper') || dirPath.includes('util') || dirPath.includes('utils')) { return 'util'; } return 'other'; } //# sourceMappingURL=file-scanner.js.map