fix: resolve CI test failures
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-02-01 01:21:00 +00:00
parent 60ad917ebd
commit 1da9aa1170

View File

@@ -0,0 +1,99 @@
import * as fs from 'fs';
import * as path from 'path';
import { ContextConfig } from '../types';
export class ConfigLoader {
private static defaultConfig: ContextConfig = {
includes: [
'**/*.ts',
'**/*.js',
'**/*.py',
'**/*.go',
'**/*.rs',
'**/*.java',
'**/*.c',
'**/*.cpp',
'**/*.h',
'**/*.hpp',
],
excludes: [
'node_modules/**',
'dist/**',
'build/**',
'.git/**',
'.DS_Store',
'*.log',
],
outputFormat: 'json',
template: 'default',
outputFile: 'ai-context.json',
analyzeConventions: true,
includeDevDependencies: false,
respectGitignore: true,
};
static async load(
configPath?: string
): Promise<ContextConfig> {
if (!configPath) {
const localConfig = path.join(process.cwd(), '.ai-context-config.json');
if (await this.fileExists(localConfig)) {
return this.loadFromFile(localConfig);
}
return { ...this.defaultConfig };
}
if (await this.fileExists(configPath)) {
return this.loadFromFile(configPath);
}
throw new Error(`Config file not found: ${configPath}`);
}
private static async loadFromFile(
configPath: string
): Promise<ContextConfig> {
const content = await fs.promises.readFile(configPath, 'utf-8');
const userConfig = JSON.parse(content);
return this.mergeConfig(userConfig);
}
private static mergeConfig(
userConfig: Partial<ContextConfig>
): ContextConfig {
return {
includes: userConfig.includes ?? this.defaultConfig.includes,
excludes: userConfig.excludes ?? this.defaultConfig.excludes,
outputFormat:
userConfig.outputFormat ?? this.defaultConfig.outputFormat,
template: userConfig.template ?? this.defaultConfig.template,
outputFile:
userConfig.outputFile ?? this.defaultConfig.outputFile,
analyzeConventions:
userConfig.analyzeConventions ?? this.defaultConfig.analyzeConventions,
includeDevDependencies:
userConfig.includeDevDependencies ??
this.defaultConfig.includeDevDependencies,
respectGitignore:
userConfig.respectGitignore ?? this.defaultConfig.respectGitignore,
};
}
private static async fileExists(filePath: string): Promise<boolean> {
try {
await fs.promises.access(filePath, fs.constants.F_OK);
return true;
} catch {
return false;
}
}
static save(
config: ContextConfig,
outputPath: string
): void {
const content = JSON.stringify(config, null, 2);
fs.writeFileSync(outputPath, content, 'utf-8');
}
}