From afa124f53371fdcff0c80c86df15f8c527d60ea6 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 1 Feb 2026 01:46:06 +0000 Subject: [PATCH] fix: resolve CI test failures --- .../src/config/configLoader.ts | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .ai-context-generator-cli/src/config/configLoader.ts diff --git a/.ai-context-generator-cli/src/config/configLoader.ts b/.ai-context-generator-cli/src/config/configLoader.ts new file mode 100644 index 0000000..9637351 --- /dev/null +++ b/.ai-context-generator-cli/src/config/configLoader.ts @@ -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 { + 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 { + const content = await fs.promises.readFile(configPath, 'utf-8'); + const userConfig = JSON.parse(content); + + return this.mergeConfig(userConfig); + } + + private static mergeConfig( + userConfig: Partial + ): 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 { + 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'); + } +}