Skip to content

Commit

Permalink
Merge pull request #70 from openimis/release/22.10
Browse files Browse the repository at this point in the history
Release/22.10
  • Loading branch information
delcroip authored Nov 11, 2022
2 parents 89a5f3a + c004ae9 commit 0811c13
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 140 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Another important point is NOT TO HAVE in backend db table user_Core (managed by
This issue is related to the link between userCore and tblUser tables.</td></tr></table>

- clone this repo (creates the `openimis-fe_js` directory)
- install node
- install node (node V16.x)
- install yarn
- within `openimis-fe_js` directory
- generate the openIMIS modules dependencies and locales (from openimis.json config): `yarn load-config` or `yarn load-config openimis.json`
Expand Down Expand Up @@ -267,3 +267,45 @@ Note: This image only provides the openimis frontend server. The full openIMIS d
}
```
- 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).


## Handling errors while running openIMIS app - the most common ones

### Handling error with ` no content display` after running frontend
Based on error reported on that [ticket](https://openimis.atlassian.net/browse/OSD-176)

Description of error:
* after `yarn start` the page loads but no content is display
* sometimes it just keeps spinning the loader
* web console doesn't show any errors

How to solve this?
* double check if you use proper versions of backend/frontend modules (assembly and core ones)
* make sure you have the latest version of dockerized database

Conclusions:
* The reason of this error is usually using not up-to-date assembly and core modules (both backend and frontend ones)


### Handling error with `400 error` after running frontend
Based on error reported on that [ticket](https://openimis.atlassian.net/browse/OSD-181)

Description of error:
* modular openIMIS deployed on server
* backend is set on port 8000, frontend is set on port 3000
* backend works fine, no errors
* it is not possible to reach both login and home page due to 400 error
* web console doesn't show any errors

How to solve this?
* double check if you use proper versions of backend/frontend modules (assembly and core ones)
* make sure you added env variables on backend side (site root/sire url)
* double check value for `proxy` key in package.json (IMPORTANT: be careful with this setting on production environment)

Conclusions:
* The reason of this error is usually not setting up env variables on backend side and wrong value for `proxy` key


### How to report another issues?
If you face another issues not described in that section you could use our [ticketing site](https://openimis.atlassian.net/servicedesk/customer/portal/1).
Here you can report any bugs/problems you faced during setting up openIMIS app.
167 changes: 95 additions & 72 deletions modules-config.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,108 @@
const fs = require('fs');
const fs = require("fs");
const pkg = require("./package.json");

function processLocales(config) {
var locales = fs.createWriteStream('./src/locales.js');
let localeByLang = config['locales'].reduce(
(lcs, lc) => {
lc.languages.forEach((lg) => lcs[lg] = lc.intl);
return lcs
},
{}
);
let filesByLang = config['locales'].reduce(
(fls, lc) => {
lc.languages.forEach((lg) => fls[lg] = lc.fileNames);
return fls
},
{}
);
locales.write(`export const locales = ${JSON.stringify(config['locales'].map((lc) => lc.intl))}`);
locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`);
locales.write(`/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */`);
locales.write(`\nexport default ${JSON.stringify(localeByLang)}`);
var locales = fs.createWriteStream("./src/locales.js");
let localeByLang = config["locales"].reduce((lcs, lc) => {
lc.languages.forEach((lg) => (lcs[lg] = lc.intl));
return lcs;
}, {});
let filesByLang = config["locales"].reduce((fls, lc) => {
lc.languages.forEach((lg) => (fls[lg] = lc.fileNames));
return fls;
}, {});
locales.write(`export const locales = ${JSON.stringify(config["locales"].map((lc) => lc.intl))}`);
locales.write(`\nexport const fileNamesByLang = ${JSON.stringify(filesByLang)}`);
locales.write(`/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */`);
locales.write(`\nexport default ${JSON.stringify(localeByLang)}`);
}

function getModuleLogicalName(module) {
return module.logicalName || module.npm.match(/([^/]*)\/([^@]*).*/)[2];
function getConfig() {
// Try to get the configuration from the args
if (process.argv[2]) {
console.log(` load configuration from '${process.argv[2]}'`);
return JSON.parse(fs.readFileSync(process.argv[2], "utf-8"));
} else if (process.env.OPENIMIS_CONF_JSON) {
console.log(` load configuration from env`);
return JSON.parse(process.env.OPENIMIS_CONF_JSON);
} else if (fs.existsSync("./openimis.json")) {
console.log(` load configuration from ./openimis.json`);
return JSON.parse(fs.readFileSync("./openimis.json", "utf-8"));
} else {
throw new Error(
"No configuration file found. Please provide a configuration in the CLI or in the OPENIMIS_CONF_JSON environment variable",
);
}
}

function processModules(config, packageConfig) {
var srcModules = fs.createWriteStream('./src/modules.js');
config['modules'].forEach((module) => {
let lib = module.npm.substring(0, module.npm.lastIndexOf('@'));
let version = module.npm.substring( module.npm.lastIndexOf('@')+1);
srcModules.write(`import { ${module.name} } from '${lib}';\n`);
packageConfig.dependencies[lib] = version;
});
srcModules.write("\nexport const versions = [\n\t");
srcModules.write(config["modules"].map((module) => `"${module.npm}"`).join(",\n\t"));
srcModules.write("\n];\nexport const modules = (cfg) => [\n\t");
srcModules.write(
config["modules"]
.map((module) => `${module.name}((cfg && cfg["${getModuleLogicalName(module)}"]) || {})`)
.join(",\n\t")
);
srcModules.write("\n];");
srcModules.end();
return packageConfig;
function processModules(modules) {
const stream = fs.createWriteStream("./src/modules.js");

}
stream.write(`
export const packages = [
${modules.map(({ moduleName }) => `"${moduleName}"`).join(",\n ")}
];\n
`);

function applyConfig(config, packageConfig) {
processLocales(config);
packageConfig = processModules(config, packageConfig);
stream.write(`
export function loadModules (cfg = {}) {
return [
${modules
.map(
({ name, logicalName, moduleName }) =>
`require("${moduleName}").${name ?? "default"}(cfg["${logicalName}"] || {})`,
)
.join(",\n ")}
];\n
}
// Configuration load
`);

function cleanDeps(packageConfig){
for (const key in packageConfig.dependencies) {
if (key.startsWith('@openimis')) delete packageConfig.dependencies[key];
}
return packageConfig;
stream.end();
}

fs.readFile('package.json', 'utf8', function read(err, data) {
if (err) throw err;
let packageConfig = cleanDeps(JSON.parse(data));
try {
if(!process.env.OPENIMIS_CONF_JSON)throw 'OPENIMIS_CONF_JSON not set !';
JSON.parse(process.env.OPENIMIS_CONF_JSON);
applyConfig(JSON.parse(process.env.OPENIMIS_CONF_JSON), packageConfig);
} catch (e) {
function main() {
/*
Load openIMIS configuration. Configuration is taken from args if provided or from the environment variable
*/

// Remove @openimis dependencies from package.json
console.log("Remove @openimis dependencies from package.json");
for (const key in pkg.dependencies) {
if (key.startsWith("@openimis/")) {
// This only covers modules made from the openIMIS organization
console.log(` removed ${key}`);
delete pkg.dependencies[key];
}
}

// Get openIMIS configuration from args
console.log("Load configuration");
const config = getConfig();

console.log("Process Locales");
processLocales(config);

console.log("Process Modules");
const modules = [];
for (const module of config.modules) {
const { npm, name, logicalName } = module;
// Find version number
const moduleName = npm.substring(0, npm.lastIndexOf("@"));
if (npm.lastIndexOf("@") <= 0) {
throw new Error(` Module ${moduleName} has no version set.`);
}
const version = npm.substring(npm.lastIndexOf("@") + 1);
console.log(` added "${moduleName}": ${version}`);
pkg.dependencies[moduleName] = version;
modules.push({
moduleName,
version,
name,
npm,
logicalName: logicalName || npm.match(/([^/]*)\/([^@]*).*/)[2],
});
}
processModules(modules);
}


var configFile = process.argv[2];
if (configFile === null || configFile === '' | configFile === undefined){
configFile = './openimis.json';
}
console.log("Using file %s, Env variable OPENIMIS_CONF_JSON not valid: %s", configFile, process.env.OPENIMIS_CONF_JSON)
fs.readFile(configFile, 'utf8', function read(err, data) {
if (err) throw err;
config = JSON.parse(data);
applyConfig(config, packageConfig);
});
}
});
main();
Loading

0 comments on commit 0811c13

Please sign in to comment.