Skip to content

Commit b428797

Browse files
committed
feat: Add file utility functions and string utility functions
1 parent 1a112d6 commit b428797

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as fs from 'fs/promises';
2+
import * as path from 'path';
3+
4+
export async function getContextFiles(directoryPath: string): Promise<string[]> {
5+
const files = await fs.readdir(directoryPath);
6+
return files.filter(file =>
7+
file.endsWith('.context.md') ||
8+
file.endsWith('.context.yaml') ||
9+
file.endsWith('.context.json')
10+
);
11+
}
12+
13+
export async function lintFileIfExists(filePath: string, lintFunction: (content: string) => void): Promise<void> {
14+
try {
15+
const content = await fs.readFile(filePath, 'utf-8');
16+
lintFunction(content);
17+
} catch (error) {
18+
if (error instanceof Error && 'code' in error && error.code !== 'ENOENT') {
19+
console.error(`Error reading file ${filePath}: ${error}`);
20+
}
21+
}
22+
}
23+
24+
export async function fileExists(filePath: string): Promise<boolean> {
25+
try {
26+
await fs.access(filePath);
27+
return true;
28+
} catch {
29+
return false;
30+
}
31+
}
32+
33+
export function printHeader(packageVersion: string, directoryPath: string): void {
34+
console.log(`
35+
========================================================
36+
AI Context Convention Linter (v${packageVersion})
37+
========================================================
38+
`);
39+
console.log(`Linting directory: ${directoryPath}\n`);
40+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function kebabToCamelCase(str: string, cache: Map<string, string>): string {
2+
if (cache.has(str)) {
3+
return cache.get(str)!;
4+
}
5+
const result = str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
6+
cache.set(str, result);
7+
return result;
8+
}

0 commit comments

Comments
 (0)