switched all console logs to logger
This commit is contained in:
parent
3877902ff4
commit
a3f2f199b4
14 changed files with 125 additions and 122 deletions
|
|
@ -1,85 +1,87 @@
|
|||
import { ConfigManager, createAppConfig } from '@stock-bot/config';
|
||||
import { stockAppSchema, type StockAppConfig } from './schemas';
|
||||
import * as path from 'path';
|
||||
|
||||
let configInstance: ConfigManager<StockAppConfig> | null = null;
|
||||
|
||||
/**
|
||||
* Initialize the stock application configuration
|
||||
* @param serviceName - Optional service name to override port configuration
|
||||
*/
|
||||
export function initializeStockConfig(serviceName?: 'dataIngestion' | 'dataPipeline' | 'webApi'): StockAppConfig {
|
||||
try {
|
||||
if (!configInstance) {
|
||||
configInstance = createAppConfig(stockAppSchema, {
|
||||
configPath: path.join(__dirname, '../config'),
|
||||
});
|
||||
}
|
||||
|
||||
const config = configInstance.initialize(stockAppSchema);
|
||||
|
||||
// If a service name is provided, override the service port
|
||||
if (serviceName && config.services?.[serviceName]) {
|
||||
const kebabName = serviceName.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
||||
return {
|
||||
...config,
|
||||
service: {
|
||||
...config.service,
|
||||
port: config.services[serviceName].port,
|
||||
name: serviceName, // Keep original for backward compatibility
|
||||
serviceName: kebabName // Standard kebab-case name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (error: any) {
|
||||
console.error('Failed to initialize stock configuration:', error.message);
|
||||
if (error.errors) {
|
||||
console.error('Validation errors:', JSON.stringify(error.errors, null, 2));
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current stock configuration
|
||||
*/
|
||||
export function getStockConfig(): StockAppConfig {
|
||||
if (!configInstance) {
|
||||
// Auto-initialize if not already done
|
||||
return initializeStockConfig();
|
||||
}
|
||||
return configInstance.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for a specific service
|
||||
*/
|
||||
export function getServiceConfig(service: 'dataIngestion' | 'dataPipeline' | 'webApi') {
|
||||
const config = getStockConfig();
|
||||
return config.services?.[service];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for a specific provider
|
||||
*/
|
||||
export function getProviderConfig(provider: 'eod' | 'ib' | 'qm' | 'yahoo') {
|
||||
const config = getStockConfig();
|
||||
return config.providers[provider];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a feature is enabled
|
||||
*/
|
||||
export function isFeatureEnabled(feature: keyof StockAppConfig['features']): boolean {
|
||||
const config = getStockConfig();
|
||||
return config.features[feature];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset configuration (useful for testing)
|
||||
*/
|
||||
export function resetStockConfig(): void {
|
||||
configInstance = null;
|
||||
import { ConfigManager, createAppConfig } from '@stock-bot/config';
|
||||
import { stockAppSchema, type StockAppConfig } from './schemas';
|
||||
import * as path from 'path';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
||||
let configInstance: ConfigManager<StockAppConfig> | null = null;
|
||||
|
||||
/**
|
||||
* Initialize the stock application configuration
|
||||
* @param serviceName - Optional service name to override port configuration
|
||||
*/
|
||||
export function initializeStockConfig(serviceName?: 'dataIngestion' | 'dataPipeline' | 'webApi'): StockAppConfig {
|
||||
try {
|
||||
if (!configInstance) {
|
||||
configInstance = createAppConfig(stockAppSchema, {
|
||||
configPath: path.join(__dirname, '../config'),
|
||||
});
|
||||
}
|
||||
|
||||
const config = configInstance.initialize(stockAppSchema);
|
||||
|
||||
// If a service name is provided, override the service port
|
||||
if (serviceName && config.services?.[serviceName]) {
|
||||
const kebabName = serviceName.replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '');
|
||||
return {
|
||||
...config,
|
||||
service: {
|
||||
...config.service,
|
||||
port: config.services[serviceName].port,
|
||||
name: serviceName, // Keep original for backward compatibility
|
||||
serviceName: kebabName // Standard kebab-case name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
} catch (error: any) {
|
||||
const logger = getLogger('stock-config');
|
||||
logger.error('Failed to initialize stock configuration:', error.message);
|
||||
if (error.errors) {
|
||||
logger.error('Validation errors:', error.errors);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current stock configuration
|
||||
*/
|
||||
export function getStockConfig(): StockAppConfig {
|
||||
if (!configInstance) {
|
||||
// Auto-initialize if not already done
|
||||
return initializeStockConfig();
|
||||
}
|
||||
return configInstance.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for a specific service
|
||||
*/
|
||||
export function getServiceConfig(service: 'dataIngestion' | 'dataPipeline' | 'webApi') {
|
||||
const config = getStockConfig();
|
||||
return config.services?.[service];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration for a specific provider
|
||||
*/
|
||||
export function getProviderConfig(provider: 'eod' | 'ib' | 'qm' | 'yahoo') {
|
||||
const config = getStockConfig();
|
||||
return config.providers[provider];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a feature is enabled
|
||||
*/
|
||||
export function isFeatureEnabled(feature: keyof StockAppConfig['features']): boolean {
|
||||
const config = getStockConfig();
|
||||
return config.features[feature];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset configuration (useful for testing)
|
||||
*/
|
||||
export function resetStockConfig(): void {
|
||||
configInstance = null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue