refactor(config): parse config with json5
Using json5 for configurations allows the use of comments in the json5 file. That helps to maintain a well documented configuration file
MODIFY
angular.json
angular.json
"src/styles.scss",
"src/themes/default.scss",
"node_modules/swagger-ui/dist/swagger-ui.css",
- "node_modules/simplebar/dist/simplebar.css",
+ "node_modules/simplebar/dist/simplebar.min.css",
"node_modules/prismjs/themes/prism.css",
"node_modules/material-icons/iconfont/material-icons.css"
],
"scripts": [
"node_modules/marked/lib/marked.js",
- "node_modules/simplebar/dist/simplebar.js",
+ "node_modules/simplebar/dist/simplebar.min.js",
"node_modules/prismjs/prism.js"
]
},

MODIFY
package-lock.json
package-lock.json
"@ngx-translate/http-loader": "^6.0.0",
"@swimlane/ngx-charts": "^19.0.1",
"constant-case": "^3.0.4",
+ "json5": "^2.2.0",
"keycloak-angular": "^8.4.0",
"keycloak-js": "^15.0.2",
"material-icons": "^1.10.0",
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
- "dev": true,
"dependencies": {
"minimist": "^1.2.5"
},
"node_modules/minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
- "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
- "dev": true
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"node_modules/minipass": {
"version": "3.1.5",
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz",
"integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==",
- "dev": true,
"requires": {
"minimist": "^1.2.5"
}
"minimist": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
- "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==",
- "dev": true
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"minipass": {
"version": "3.1.5",

MODIFY
package.json
package.json
"@ngx-translate/http-loader": "^6.0.0",
"@swimlane/ngx-charts": "^19.0.1",
"constant-case": "^3.0.4",
+ "json5": "^2.2.0",
"keycloak-angular": "^8.4.0",
"keycloak-js": "^15.0.2",
"material-icons": "^1.10.0",

MODIFY
src/app/services/config/config.service.ts
src/app/services/config/config.service.ts
@@ -24,6 +24,7 @@ import {
ITerms
} from '../../interfaces/IConfig';
import { HttpClient } from '@angular/common/http';
+import * as JSON5 from 'json5';
@Injectable({
providedIn: 'root'
@@ -34,16 +35,17 @@ export class ConfigService {
constructor(private http: HttpClient) {}
async readAndEvaluateConfig(): Promise<IConfig> {
- this.config = <IConfig>(
- await this.http.get('assets/config.json').toPromise()
- );
-
+ const configAsJson5String = await this.http
+ .get('assets/config.json5', { responseType: 'text' })
+ .toPromise();
try {
- JSON.stringify(this.config);
+ this.config = JSON5.parse(configAsJson5String);
} catch (e) {
+ if (e instanceof SyntaxError) {
+ console.error(e.message + '\n' + configAsJson5String);
+ }
throw Error('Invalid Config File');
}
-
return this.config;
}

refactor(config): parse config with json5

Using json5 for configurations allows the use of comments in the json5 file. That helps to maintain a well documented configuration file