adpa-enterprise-framework-automation
Version:
Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe
195 lines (193 loc) • 5.48 kB
JavaScript
/**
* Configuration File Support
* Loads and manages configuration from .rga.config.js files
*/
// 1. Node.js built-ins
import { existsSync } from 'fs';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { pathToFileURL } from 'url';
class ConfigManager {
config = {};
configPath = null;
/**
* Load configuration from files
*/
async loadConfig(searchPaths = [process.cwd()]) {
for (const searchPath of searchPaths) {
const configFiles = [
'.rga.config.js',
'.rga.config.json',
'rga.config.js',
'rga.config.json'
];
for (const configFile of configFiles) {
const configPath = join(searchPath, configFile);
if (existsSync(configPath)) {
try {
await this.loadConfigFile(configPath);
this.configPath = configPath;
return this.config;
}
catch (error) {
console.warn(`⚠️ Failed to load config from ${configPath}:`, error instanceof Error ? error.message : error);
}
}
}
}
return this.config;
}
/**
* Load a specific config file
*/
async loadConfigFile(filePath) {
if (filePath.endsWith('.json')) {
await this.loadJsonConfig(filePath);
}
else if (filePath.endsWith('.js')) {
await this.loadJsConfig(filePath);
}
}
/**
* Load JSON configuration
*/
async loadJsonConfig(filePath) {
const content = await readFile(filePath, 'utf8');
this.config = JSON.parse(content);
}
/**
* Load JavaScript configuration
*/
async loadJsConfig(filePath) {
const fileUrl = pathToFileURL(filePath).href;
const configModule = await import(fileUrl);
this.config = configModule.default || configModule;
}
/**
* Get current configuration
*/
getConfig() {
return this.config;
}
/**
* Get configuration path
*/
getConfigPath() {
return this.configPath;
}
/**
* Get default value with config override
*/
getDefault(key, fallback) {
return this.config.defaults?.[key] ?? fallback;
}
/**
* Get AI configuration
*/
getAiConfig() {
return this.config.ai || {};
}
/**
* Get integration configuration
*/
getIntegrationConfig() {
return this.config.integrations || {};
}
/**
* Get aliases
*/
getAliases() {
return this.config.aliases || {};
}
/**
* Get advanced settings
*/
getAdvancedConfig() {
return this.config.advanced || {};
}
/**
* Check if performance monitoring is enabled
*/
isPerformanceMonitoringEnabled() {
return this.config.advanced?.enablePerformanceMonitoring ?? false;
}
/**
* Get log level
*/
getLogLevel() {
return this.config.advanced?.logLevel ?? 'info';
}
/**
* Merge with command line options
*/
mergeWithCliOptions(cliOptions) {
const defaults = this.config.defaults || {};
return {
...defaults,
...cliOptions
};
}
/**
* Generate example config file
*/
generateExampleConfig() {
const exampleConfig = {
defaults: {
output: 'generated-documents',
format: 'markdown',
retries: 3,
retryBackoff: 1000,
retryMaxDelay: 25000,
quiet: false
},
ai: {
provider: 'azure-openai',
timeout: 60000,
maxTokens: 4000
},
integrations: {
confluence: {
spaceKey: 'PROJECT',
parentPageTitle: 'Documentation',
labelPrefix: 'auto-generated'
},
sharepoint: {
siteUrl: 'https://company.sharepoint.com/sites/project',
libraryName: 'Documents',
folderPath: 'Generated Documentation'
},
git: {
autoCommit: true,
commitMessage: 'docs: auto-generated documentation updates',
autoPush: false
}
},
aliases: {
'gen': ['generate'],
'docs': ['generate-all'],
'quick': ['generate-core-analysis']
},
advanced: {
enablePerformanceMonitoring: true,
logLevel: 'info',
cacheEnabled: true,
maxConcurrentOperations: 3
}
};
return `// RGA Configuration File
// Save as .rga.config.js in your project root
export default ${JSON.stringify(exampleConfig, null, 2)};
// Alternative CommonJS syntax:
// module.exports = ${JSON.stringify(exampleConfig, null, 2)};
`;
}
}
// Global config manager instance
export const configManager = new ConfigManager();
/**
* Initialize configuration
*/
export async function initializeConfig() {
return await configManager.loadConfig();
}
//# sourceMappingURL=configFile.js.map