Skip to content

Commit

Permalink
OP-1847: improve modules js generation
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Mar 21, 2024
1 parent 620c2b5 commit e22059d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
24 changes: 15 additions & 9 deletions modules-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
`);

Expand Down
24 changes: 15 additions & 9 deletions openimis-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
`);

Expand Down

0 comments on commit e22059d

Please sign in to comment.