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