UNPKG

scai

Version:

> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.

48 lines (47 loc) 2.1 kB
import { getDbForRepo } from "../client.js"; import { markFileAsSkippedByPath, markFileAsFailedTemplate } from "../sqlTemplates.js"; import { extractFromJava } from "./extractFromJava.js"; import { extractFromJS } from "./extractFromJs.js"; import { extractFromTS } from "./extractFromTs.js"; import { extractFromXML } from "./extractFromXML.js"; import { detectFileType } from "../../fileRules/detectFileType.js"; import { log } from "../../utils/log.js"; import { CODE_ALLOWED_EXTENSIONS } from "../../fileRules/codeAllowedExtensions.js"; export async function extractFunctionsFromFile(filePath, content, fileId) { const type = detectFileType(filePath).trim().toLowerCase(); const db = getDbForRepo(); if (!CODE_ALLOWED_EXTENSIONS.includes(type)) { log(`⚠️ File type not allowed for code extraction: ${type}. Skipping ${filePath}`); db.prepare(markFileAsSkippedByPath).run({ path: filePath }); return false; } try { let success = false; switch (type) { case 'js': case 'javascript': log(`📄 Extracting JS code from ${filePath}`); success = await extractFromJS(filePath, content, fileId); break; case 'ts': case 'typescript': log(`📘 Extracting TS code from ${filePath}`); success = await extractFromTS(filePath, content, fileId); break; case 'java': log(`📘 Extracting Java code from ${filePath}`); await extractFromJava(filePath, content, fileId); return false; case 'xml': log(`⚠️ XML extraction not implemented for ${filePath}`); await extractFromXML(filePath, content, fileId); return false; } return success; } catch (error) { log(`❌ Failed to extract from ${filePath}: ${error instanceof Error ? error.message : error}`); db.prepare(markFileAsFailedTemplate).run({ id: fileId }); return false; } }