UNPKG

scai

Version:

> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.

45 lines (44 loc) 2.04 kB
import { log } from '../../utils/log.js'; import { detectFileType } from '../../fileRules/detectFileType.js'; import { extractFromJava } from './extractFromJava.js'; import { extractFromJS } from './extractFromJs.js'; import { extractFromXML } from './extractFromXML.js'; import { getDbForRepo } from '../client.js'; import { markFileAsFailedTemplate, markFileAsSkippedByPath } from '../sqlTemplates.js'; import { extractFromTS } from './extractFromTs.js'; /** * Detects file type and delegates to the appropriate extractor. */ export async function extractFunctionsFromFile(filePath, content, fileId) { const type = detectFileType(filePath).trim().toLowerCase(); const db = getDbForRepo(); try { if (type === 'js' || type === 'javascript') { log(`✅ Attempting to extract JS functions from ${filePath}`); return await extractFromJS(filePath, content, fileId); } if (type === 'ts' || type === 'typescript') { log(`📘 Extracting TS functions from ${filePath}`); return await extractFromTS(filePath, content, fileId); } if (type === 'java') { log(`❌ Nothing extracted for ${filePath} due to missing implementation`); await extractFromJava(filePath, content, fileId); return false; } if (type === 'xml') { log(`❌ Nothing extracted for ${filePath} due to missing implementation`); await extractFromXML(filePath, content, fileId); return false; } log(`⚠️ Unsupported file type: ${type} for function extraction. Skipping ${filePath}`); db.prepare(markFileAsSkippedByPath).run({ path: filePath }); return false; } catch (error) { log(`❌ Failed to extract functions from ${filePath}: ${error instanceof Error ? error.message : error}`); // Use the sqlTemplate to mark the file as 'failed' db.prepare(markFileAsFailedTemplate).run({ id: fileId }); return false; } }