-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalRun.js
More file actions
90 lines (74 loc) · 3.06 KB
/
localRun.js
File metadata and controls
90 lines (74 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require('dotenv').config();
const { getDbAdapter } = require('./src/db');
const { scanRepository } = require('./src/scanners');
const path = require("path");
const fs = require("fs");
async function localRun() {
try {
// Отримуємо налаштування з .env
const mode = process.env.MODE || 'full';
const dbType = process.env.DB_TYPE || 'chromadb';
let version = "unknown";
try {
const fs = require('fs');
const path = require('path');
const packageJsonPath = path.resolve(__dirname, './package.json');
if (fs.existsSync(packageJsonPath)) {
const packageData = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
version = packageData.version || "unknown";
}
} catch (versionError) {
console.error('Error getting version:', versionError.message);
}
console.log(`Vector code map generator v${version}`);
// OpenAI налаштування
const openaiApiKey = process.env.OPENAI_API_KEY;
if (!openaiApiKey) throw new Error('OPENAI_API_KEY not set');
const openaiModel = process.env.OPENAI_MODEL || 'text-embedding-3-small';
// Налаштування для фільтрації файлів
const fileExtensions = (process.env.FILE_EXTENSIONS || '.js,.ts,.jsx,.tsx,.html,.css,.md,.txt').split(',');
const excludePatterns = (process.env.EXCLUDE_PATTERNS || 'node_modules/**,dist/**,.git/**').split(',');
// Підключаємося до векторної бази даних
let dbAdapter;
if (dbType === 'chromadb') {
const chromaHost = process.env.CHROMA_HOST;
if (!chromaHost) throw new Error('CHROMA_HOST not set');
const chromaPort = process.env.CHROMA_PORT || '8000';
const chromaCollection = process.env.CHROMA_COLLECTION;
if (!chromaCollection) throw new Error('CHROMA_COLLECTION not set');
// Налаштування авторизації для ChromaDB
const authEnabled = process.env.CHROMA_AUTH_ENABLED === 'true';
const authConfig = {};
if (authEnabled) {
authConfig.enabled = true;
authConfig.type = process.env.CHROMA_AUTH_TYPE || 'basic';
authConfig.credentials = process.env.CHROMA_AUTH_CREDENTIALS;
authConfig.ssl = process.env.CHROMA_SSL_ENABLED === 'true';
}
dbAdapter = await getDbAdapter('chromadb', {
host: chromaHost,
port: chromaPort,
collection: chromaCollection,
auth: authConfig
});
} else {
throw new Error(`Unsupported database type: ${dbType}`);
}
// Запускаємо сканування репозиторію
const repoPath = '.';
console.log('We start scanning the repository...');
await scanRepository({
repoPath,
dbAdapter,
mode,
fileExtensions,
excludePatterns,
openaiModel
});
console.log(`Vector code map generation completed in mode: ${mode}`);
} catch (error) {
console.error(`Помилка: ${error.message}`);
process.exit(1);
}
}
localRun();