-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.ts
More file actions
47 lines (42 loc) · 1.29 KB
/
Copy pathredis.ts
File metadata and controls
47 lines (42 loc) · 1.29 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
import * as fs from 'fs';
import * as path from 'path';
import type { IndexerPlugin } from '../plugin-api';
import type { IndexerResult } from '../../types';
const PATTERNS = [
/redis/i,
/\.redis\.(ya?ml|json|conf)$/i,
/application\.(ya?ml|properties)$/i,
];
function isRedisFile(filePath: string): boolean {
const rel = filePath.replace(/\\/g, '/');
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 redisIndexer: IndexerPlugin = {
name: 'redis',
discover(root: string): string[] {
return walk(root, SKIP, isRedisFile);
},
indexFile(): IndexerResult {
return { assetsAdded: 0, relationsAdded: 0, skipped: true };
},
};