-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopic.ts
More file actions
53 lines (48 loc) · 1.42 KB
/
Copy pathtopic.ts
File metadata and controls
53 lines (48 loc) · 1.42 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
import * as fs from 'fs';
import * as path from 'path';
import type { IndexerPlugin } from '../plugin-api';
import type { IndexerResult } from '../../types';
const PATTERNS = [
/kafka/i,
/rabbitmq/i,
/mq/i,
/topic/i,
/event/i,
/messaging/i,
];
function isTopicFile(filePath: string): boolean {
const rel = filePath.replace(/\\/g, '/');
if (!/\.(ya?ml|json|properties|toml|env)$/i.test(filePath)) {
if (!/\.(java|kt|cs|py|go|ts|js)$/i.test(filePath)) return false;
}
return PATTERNS.some((p) => p.test(rel));
}
function walk(root: string, skip: Set<string>, match: (p: string) => boolean): string[] {
const found: string[] = [];
function visit(dir: string): void {
let entries: fs.Dirent[];
try {
entries = fs.readdirSync(dir, { withFileTypes: true });
} catch {
return;
}
for (const entry of entries) {
if (skip.has(entry.name)) continue;
const full = path.join(dir, entry.name);
if (entry.isDirectory()) visit(full);
else if (entry.isFile() && match(full)) found.push(full);
}
}
visit(root);
return found;
}
const SKIP = new Set(['node_modules', '.git', 'dist', 'build', '.codegraphplus', 'vendor']);
export const topicIndexer: IndexerPlugin = {
name: 'topic',
discover(root: string): string[] {
return walk(root, SKIP, isTopicFile);
},
indexFile(): IndexerResult {
return { assetsAdded: 0, relationsAdded: 0, skipped: true };
},
};