UNPKG

@notjustcoders/ioc-arise

Version:

Arise type-safe IoC containers from your code. Zero overhead, zero coupling.

58 lines 2.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigManager = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const index_js_1 = require("../errors/index.js"); class ConfigManager { constructor(sourceDir) { this.config = {}; // Config file should be in the same directory as the source this.configPath = (0, path_1.resolve)(sourceDir, ConfigManager.CONFIG_FILE_NAME); this.loadConfig(); } loadConfig() { if ((0, fs_1.existsSync)(this.configPath)) { try { const configContent = (0, fs_1.readFileSync)(this.configPath, 'utf-8'); this.config = JSON.parse(configContent); } catch (error) { if (error instanceof SyntaxError) { const parseError = index_js_1.ErrorFactory.configParseError(this.configPath, error.message); console.warn(`⚠️ Warning: ${index_js_1.ErrorUtils.formatForConsole(parseError)}`); } else { const readError = index_js_1.ErrorFactory.fileReadError(this.configPath, error instanceof Error ? error.message : String(error)); console.warn(`⚠️ Warning: ${index_js_1.ErrorUtils.formatForConsole(readError)}`); } console.warn(' Using default configuration.'); this.config = {}; } } } getConfig() { return { ...this.config }; } mergeWithCliOptions(cliOptions) { // CLI options take precedence over config file return { source: cliOptions.source || this.config.source || 'src', output: cliOptions.output || this.config.output || 'container.gen.ts', interface: cliOptions.interface || this.config.interface, exclude: cliOptions.exclude || this.config.exclude, checkCycles: cliOptions.checkCycles || this.config.checkCycles || false, verbose: cliOptions.verbose || this.config.verbose || false, modules: cliOptions.modules || this.config.modules }; } hasConfigFile() { return (0, fs_1.existsSync)(this.configPath); } getConfigPath() { return this.configPath; } } exports.ConfigManager = ConfigManager; ConfigManager.CONFIG_FILE_NAME = 'ioc.config.json'; //# sourceMappingURL=configManager.js.map