UNPKG

@vibe-dev-kit/cli

Version:

Advanced Command-line toolkit that analyzes your codebase and deploys project-aware rules, memories, commands and agents to any AI coding assistant - VDK is the world's first Vibe Development Kit

80 lines (70 loc) 2.26 kB
/** * TypeScript Parser * Provides TypeScript parsing functionality for code analysis */ import fs from 'fs/promises'; import path from 'path'; /** * Parses TypeScript files for analysis */ export class TypeScriptParser { /** * Determine if a file is likely TypeScript based on extension * * @param {string} filePath - Path to the file * @returns {boolean} - True if file is TypeScript */ static isTypeScriptFile(filePath) { const ext = path.extname(filePath).toLowerCase(); return ext === '.ts' || ext === '.tsx' || ext === '.d.ts'; } /** * Safely parse TypeScript file content * * @param {string} filePath - Path to the TypeScript file * @returns {Promise<{content: string, success: boolean, error: Error|null}>} - Parse result */ static async parseFile(filePath) { try { // For now, we just read the file, but don't try to parse the syntax // In a real implementation, we'd use the TypeScript compiler API const content = await fs.readFile(filePath, 'utf8'); return { content, success: true, error: null }; } catch (error) { return { content: '', success: false, error }; } } /** * Extract imports from TypeScript file * * @param {string} content - File content * @returns {string[]} - Array of imported modules */ static extractImports(content) { // Simple regex to extract imports - this is a simplification // A real implementation would use the TypeScript AST const importRegex = /import\s+(?:{[^}]*}|\*\s+as\s+\w+|\w+)\s+from\s+['"]([^'"]+)['"]/g; const imports = []; let match; while ((match = importRegex.exec(content)) !== null) { imports.push(match[1]); } return imports; } /** * Extract exports from TypeScript file * * @param {string} content - File content * @returns {string[]} - Array of exported items */ static extractExports(content) { // Simple regex to extract exports - this is a simplification const exportRegex = /export\s+(const|let|var|function|class|interface|type|enum)\s+(\w+)/g; const exports = []; let match; while ((match = exportRegex.exec(content)) !== null) { exports.push(match[2]); } return exports; } }