Skip to content

Commit

Permalink
Merge pull request #123 from openimis/feature/OP-1847
Browse files Browse the repository at this point in the history
OP-1847: improve modules js generation
  • Loading branch information
delcroip authored Mar 22, 2024
2 parents 620c2b5 + e22059d commit 2cccd38
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 2cccd38

Please sign in to comment.