Skip to content

Commit 0811c13

Browse files
authored
Merge pull request #70 from openimis/release/22.10
Release/22.10
2 parents 89a5f3a + c004ae9 commit 0811c13

File tree

4 files changed

+201
-140
lines changed

4 files changed

+201
-140
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Another important point is NOT TO HAVE in backend db table user_Core (managed by
4040
This issue is related to the link between userCore and tblUser tables.</td></tr></table>
4141

4242
- clone this repo (creates the `openimis-fe_js` directory)
43-
- install node
43+
- install node (node V16.x)
4444
- install yarn
4545
- within `openimis-fe_js` directory
4646
- generate the openIMIS modules dependencies and locales (from openimis.json config): `yarn load-config` or `yarn load-config openimis.json`
@@ -267,3 +267,45 @@ Note: This image only provides the openimis frontend server. The full openIMIS d
267267
}
268268
```
269269
- this approach overwrites default `en` language translations into `en-gm` (Gambian English) translations without adding new language on database level and without changing 'locales' in 'openimis.json' and 'locales.js' file both on assembly frontend module (openimis-fe_js).
270+
271+
272+
## Handling errors while running openIMIS app - the most common ones
273+
274+
### Handling error with ` no content display` after running frontend
275+
Based on error reported on that [ticket](https://openimis.atlassian.net/browse/OSD-176)
276+
277+
Description of error:
278+
* after `yarn start` the page loads but no content is display
279+
* sometimes it just keeps spinning the loader
280+
* web console doesn't show any errors
281+
282+
How to solve this?
283+
* double check if you use proper versions of backend/frontend modules (assembly and core ones)
284+
* make sure you have the latest version of dockerized database
285+
286+
Conclusions:
287+
* The reason of this error is usually using not up-to-date assembly and core modules (both backend and frontend ones)
288+
289+
290+
### Handling error with `400 error` after running frontend
291+
Based on error reported on that [ticket](https://openimis.atlassian.net/browse/OSD-181)
292+
293+
Description of error:
294+
* modular openIMIS deployed on server
295+
* backend is set on port 8000, frontend is set on port 3000
296+
* backend works fine, no errors
297+
* it is not possible to reach both login and home page due to 400 error
298+
* web console doesn't show any errors
299+
300+
How to solve this?
301+
* double check if you use proper versions of backend/frontend modules (assembly and core ones)
302+
* make sure you added env variables on backend side (site root/sire url)
303+
* double check value for `proxy` key in package.json (IMPORTANT: be careful with this setting on production environment)
304+
305+
Conclusions:
306+
* The reason of this error is usually not setting up env variables on backend side and wrong value for `proxy` key
307+
308+
309+
### How to report another issues?
310+
If you face another issues not described in that section you could use our [ticketing site](https://openimis.atlassian.net/servicedesk/customer/portal/1).
311+
Here you can report any bugs/problems you faced during setting up openIMIS app.

modules-config.js

Lines changed: 95 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,108 @@
1-
const fs = require('fs');
1+
const fs = require("fs");
2+
const pkg = require("./package.json");
23

34
function processLocales(config) {
4-
var locales = fs.createWriteStream('./src/locales.js');
5-
let localeByLang = config['locales'].reduce(
6-
(lcs, lc) => {
7-
lc.languages.forEach((lg) => lcs[lg] = lc.intl);
8-
return lcs
9-
},
10-
{}
11-
);
12-
let filesByLang = config['locales'].reduce(
13-
(fls, lc) => {
14-
lc.languages.forEach((lg) => fls[lg] = lc.fileNames);
15-
return fls
16-
},
17-
{}
18-
);
19-
locales.write(`export const locales = ${JSON.stringify(config['locales'].map((lc) => lc.intl))}`);
20-
locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`);
21-
locales.write(`/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */`);
22-
locales.write(`\nexport default ${JSON.stringify(localeByLang)}`);
5+
var locales = fs.createWriteStream("./src/locales.js");
6+
let localeByLang = config["locales"].reduce((lcs, lc) => {
7+
lc.languages.forEach((lg) => (lcs[lg] = lc.intl));
8+
return lcs;
9+
}, {});
10+
let filesByLang = config["locales"].reduce((fls, lc) => {
11+
lc.languages.forEach((lg) => (fls[lg] = lc.fileNames));
12+
return fls;
13+
}, {});
14+
locales.write(`export const locales = ${JSON.stringify(config["locales"].map((lc) => lc.intl))}`);
15+
locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`);
16+
locales.write(`/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */`);
17+
locales.write(`\nexport default ${JSON.stringify(localeByLang)}`);
2318
}
2419

25-
function getModuleLogicalName(module) {
26-
return module.logicalName || module.npm.match(/([^/]*)\/([^@]*).*/)[2];
20+
function getConfig() {
21+
// Try to get the configuration from the args
22+
if (process.argv[2]) {
23+
console.log(` load configuration from '${process.argv[2]}'`);
24+
return JSON.parse(fs.readFileSync(process.argv[2], "utf-8"));
25+
} else if (process.env.OPENIMIS_CONF_JSON) {
26+
console.log(` load configuration from env`);
27+
return JSON.parse(process.env.OPENIMIS_CONF_JSON);
28+
} else if (fs.existsSync("./openimis.json")) {
29+
console.log(` load configuration from ./openimis.json`);
30+
return JSON.parse(fs.readFileSync("./openimis.json", "utf-8"));
31+
} else {
32+
throw new Error(
33+
"No configuration file found. Please provide a configuration in the CLI or in the OPENIMIS_CONF_JSON environment variable",
34+
);
35+
}
2736
}
2837

29-
function processModules(config, packageConfig) {
30-
var srcModules = fs.createWriteStream('./src/modules.js');
31-
config['modules'].forEach((module) => {
32-
let lib = module.npm.substring(0, module.npm.lastIndexOf('@'));
33-
let version = module.npm.substring( module.npm.lastIndexOf('@')+1);
34-
srcModules.write(`import { ${module.name} } from '${lib}';\n`);
35-
packageConfig.dependencies[lib] = version;
36-
});
37-
srcModules.write("\nexport const versions = [\n\t");
38-
srcModules.write(config["modules"].map((module) => `"${module.npm}"`).join(",\n\t"));
39-
srcModules.write("\n];\nexport const modules = (cfg) => [\n\t");
40-
srcModules.write(
41-
config["modules"]
42-
.map((module) => `${module.name}((cfg && cfg["${getModuleLogicalName(module)}"]) || {})`)
43-
.join(",\n\t")
44-
);
45-
srcModules.write("\n];");
46-
srcModules.end();
47-
return packageConfig;
38+
function processModules(modules) {
39+
const stream = fs.createWriteStream("./src/modules.js");
4840

49-
}
41+
stream.write(`
42+
export const packages = [
43+
${modules.map(({ moduleName }) => `"${moduleName}"`).join(",\n ")}
44+
];\n
45+
`);
5046

51-
function applyConfig(config, packageConfig) {
52-
processLocales(config);
53-
packageConfig = processModules(config, packageConfig);
47+
stream.write(`
48+
export function loadModules (cfg = {}) {
49+
return [
50+
${modules
51+
.map(
52+
({ name, logicalName, moduleName }) =>
53+
`require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})`,
54+
)
55+
.join(",\n ")}
56+
];\n
5457
}
55-
// Configuration load
58+
`);
5659

57-
function cleanDeps(packageConfig){
58-
for (const key in packageConfig.dependencies) {
59-
if (key.startsWith('@openimis')) delete packageConfig.dependencies[key];
60-
}
61-
return packageConfig;
60+
stream.end();
6261
}
6362

64-
fs.readFile('package.json', 'utf8', function read(err, data) {
65-
if (err) throw err;
66-
let packageConfig = cleanDeps(JSON.parse(data));
67-
try {
68-
if(!process.env.OPENIMIS_CONF_JSON)throw 'OPENIMIS_CONF_JSON not set !';
69-
JSON.parse(process.env.OPENIMIS_CONF_JSON);
70-
applyConfig(JSON.parse(process.env.OPENIMIS_CONF_JSON), packageConfig);
71-
} catch (e) {
63+
function main() {
64+
/*
65+
Load openIMIS configuration. Configuration is taken from args if provided or from the environment variable
66+
*/
67+
68+
// Remove @openimis dependencies from package.json
69+
console.log("Remove @openimis dependencies from package.json");
70+
for (const key in pkg.dependencies) {
71+
if (key.startsWith("@openimis/")) {
72+
// This only covers modules made from the openIMIS organization
73+
console.log(` removed ${key}`);
74+
delete pkg.dependencies[key];
75+
}
76+
}
77+
78+
// Get openIMIS configuration from args
79+
console.log("Load configuration");
80+
const config = getConfig();
81+
82+
console.log("Process Locales");
83+
processLocales(config);
84+
85+
console.log("Process Modules");
86+
const modules = [];
87+
for (const module of config.modules) {
88+
const { npm, name, logicalName } = module;
89+
// Find version number
90+
const moduleName = npm.substring(0, npm.lastIndexOf("@"));
91+
if (npm.lastIndexOf("@") <= 0) {
92+
throw new Error(` Module ${moduleName} has no version set.`);
93+
}
94+
const version = npm.substring(npm.lastIndexOf("@") + 1);
95+
console.log(` added "${moduleName}": ${version}`);
96+
pkg.dependencies[moduleName] = version;
97+
modules.push({
98+
moduleName,
99+
version,
100+
name,
101+
npm,
102+
logicalName: logicalName || npm.match(/([^/]*)\/([^@]*).*/)[2],
103+
});
104+
}
105+
processModules(modules);
106+
}
72107

73-
74-
var configFile = process.argv[2];
75-
if (configFile === null || configFile === '' | configFile === undefined){
76-
configFile = './openimis.json';
77-
}
78-
console.log("Using file %s, Env variable OPENIMIS_CONF_JSON not valid: %s", configFile, process.env.OPENIMIS_CONF_JSON)
79-
fs.readFile(configFile, 'utf8', function read(err, data) {
80-
if (err) throw err;
81-
config = JSON.parse(data);
82-
applyConfig(config, packageConfig);
83-
});
84-
}
85-
});
108+
main();

0 commit comments

Comments
 (0)