standaardisation updates
This commit is contained in:
53
index.js
53
index.js
@@ -3,10 +3,11 @@
|
||||
* -----------------------------------------------------------
|
||||
* Central barrel file for re-exporting helpers and configurations.
|
||||
* Provides both namespace exports and dynamic loading capabilities.
|
||||
* now we can load modules like this:
|
||||
* const { menuUtils, outputUtils } = require('generalFunctions');
|
||||
*/
|
||||
|
||||
// Core helper modules
|
||||
const menuUtils = require('./src/helper/menuUtils.js');
|
||||
const outputUtils = require('./src/helper/outputUtils.js');
|
||||
const logger = require('./src/helper/logger.js');
|
||||
const validation = require('./src/helper/validationUtils.js');
|
||||
@@ -14,53 +15,16 @@ const configUtils = require('./src/helper/configUtils.js');
|
||||
|
||||
// Domain-specific modules
|
||||
const measurements = require('./src/measurements/index.js');
|
||||
const configManager = require('./src/configs/index.js');
|
||||
const nrmse = require('./src/nrmse/ErrorMetrics.js');
|
||||
const state = require('./src/state/state.js');
|
||||
const convert = require('./src/convert/index.js');
|
||||
const MenuManager = require('./src/menu/index.js');
|
||||
|
||||
// Configuration loader with error handling
|
||||
function loadConfig(path) {
|
||||
try {
|
||||
return require(path);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to load config: ${path}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Configurations
|
||||
const configs = {
|
||||
get projectSettings() {
|
||||
return loadConfig('./configs/projectSettings.json');
|
||||
},
|
||||
get measurementConfig() {
|
||||
return loadConfig('./configs/measurementConfig.json');
|
||||
}
|
||||
};
|
||||
|
||||
// Dynamic loaders with validation
|
||||
function loadHelper(name) {
|
||||
if (!name || typeof name !== 'string') {
|
||||
throw new Error('Helper name must be a non-empty string');
|
||||
}
|
||||
|
||||
try {
|
||||
return require(`./src/helper/${name}.js`);
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to load helper "${name}": ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function loadAssetDatasets() {
|
||||
try {
|
||||
return require('./datasets/assetData/suppliers.json');
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to load asset datasets: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Export everything
|
||||
module.exports = {
|
||||
menuUtils,
|
||||
configManager,
|
||||
outputUtils,
|
||||
configUtils,
|
||||
logger,
|
||||
@@ -68,7 +32,6 @@ module.exports = {
|
||||
measurements,
|
||||
nrmse,
|
||||
state,
|
||||
configs,
|
||||
loadHelper,
|
||||
loadAssetDatasets
|
||||
convert,
|
||||
MenuManager
|
||||
};
|
||||
Reference in New Issue
Block a user