From e22059d7e0abe14e2b0b9d099f6e03135065f350 Mon Sep 17 00:00:00 2001 From: olewandowski1 Date: Thu, 21 Mar 2024 10:36:46 +0100 Subject: [PATCH] OP-1847: improve modules js generation --- modules-config.js | 24 +++++++++++++++--------- openimis-config.js | 24 +++++++++++++++--------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/modules-config.js b/modules-config.js index 18d9aa7..d067207 100644 --- a/modules-config.js +++ b/modules-config.js @@ -45,15 +45,21 @@ export const packages = [ `); stream.write(` -export function loadModules (cfg = {}) { - return [ - ${modules - .map( - ({ name, logicalName, moduleName }) => - `require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})`, - ) - .join(",\n ")} - ];\n +export function loadModules(cfg = {}) { + const loadedModules = []; +${modules +.map(({ name, logicalName, moduleName }) => { +return ` + try { + loadedModules.push(require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})); + } catch (error) { + alert(\`Failed to load module "${moduleName}". More details can be found in the developer console. Look for: \${error}\`); + console.error(error); + } +`; +}) +.join("")} + return loadedModules; } `); diff --git a/openimis-config.js b/openimis-config.js index 307a7c7..c170e49 100644 --- a/openimis-config.js +++ b/openimis-config.js @@ -45,15 +45,21 @@ export const packages = [ `); stream.write(` -export function loadModules (cfg = {}) { - return [ - ${modules - .map( - ({ name, logicalName, moduleName }) => - `require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})`, - ) - .join(",\n ")} - ];\n +export function loadModules(cfg = {}) { + const loadedModules = []; +${modules +.map(({ name, logicalName, moduleName }) => { +return ` + try { + loadedModules.push(require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})); + } catch (error) { + alert(\`Failed to load module "${moduleName}". More details can be found in the developer console. Look for: \${error}\`); + console.error(error); + } +`; +}) +.join("")} + return loadedModules; } `);