This commit is contained in:
znetsixe
2025-06-10 12:45:35 +02:00
parent bc9e3cda90
commit 26ed170932

View File

@@ -6,28 +6,27 @@
*/ */
// Core helper modules // Core helper modules
export * as menuUtils from './src/helper/menuUtils.js'; const menuUtils = require('./src/helper/menuUtils.js');
export * as logger from './src/helper/logger.js'; const logger = require('./src/helper/logger.js');
export * as validation from './src/helper/validationUtils.js'; const validation = require('./src/helper/validationUtils.js');
// Domain-specific modules // Domain-specific modules
export * as measurements from './src/measurements/index.js'; const measurements = require('./src/measurements/index.js');
export * as nrmse from './src/nrmse/index.js'; const nrmse = require('./src/nrmse/index.js');
export * as state from './src/state/index.js'; const state = require('./src/state/index.js');
// Configuration loader with error handling // Configuration loader with error handling
async function loadConfig(path) { function loadConfig(path) {
try { try {
const module = await import(path, { assert: { type: 'json' } }); return require(path);
return module.default;
} catch (error) { } catch (error) {
console.warn(`Failed to load config: ${path}`, error); console.warn(`Failed to load config: ${path}`, error);
return null; return null;
} }
} }
// Lazy-loaded configurations // Configurations
export const configs = { const configs = {
get projectSettings() { get projectSettings() {
return loadConfig('./configs/projectSettings.json'); return loadConfig('./configs/projectSettings.json');
}, },
@@ -37,24 +36,35 @@ export const configs = {
}; };
// Dynamic loaders with validation // Dynamic loaders with validation
export async function loadHelper(name) { function loadHelper(name) {
if (!name || typeof name !== 'string') { if (!name || typeof name !== 'string') {
throw new Error('Helper name must be a non-empty string'); throw new Error('Helper name must be a non-empty string');
} }
try { try {
return await import(`./src/helper/${name}.js`); return require(`./src/helper/${name}.js`);
} catch (error) { } catch (error) {
throw new Error(`Failed to load helper "${name}": ${error.message}`); throw new Error(`Failed to load helper "${name}": ${error.message}`);
} }
} }
export async function loadAssetDatasets() { function loadAssetDatasets() {
try { try {
return await import('./datasets/assetData/suppliers.json', { return require('./datasets/assetData/suppliers.json');
assert: { type: 'json' }
});
} catch (error) { } catch (error) {
throw new Error(`Failed to load asset datasets: ${error.message}`); throw new Error(`Failed to load asset datasets: ${error.message}`);
} }
} }
// Export everything
module.exports = {
menuUtils,
logger,
validation,
measurements,
nrmse,
state,
configs,
loadHelper,
loadAssetDatasets
};