Skip to content

Commit

Permalink
Corrected include in JSON config files
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Apr 6, 2024
1 parent 743a03d commit 089f813
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The icons may not be reused in other projects without the proper flaticon licens
### **WORK IN PROGRESS**
-->
## Changelog
### 6.17.0 (2024-04-06)
### **WORK IN PROGRESS**
* (bluefox) support of includes in JSONConfig files

### 6.16.0 (2024-03-26)
Expand Down
13 changes: 0 additions & 13 deletions packages/admin/io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@
"connectionType": "local",
"dataSource": "push",
"news": {
"6.17.0": {
"en": "support of includes in JSONConfig files",
"de": "unterstützung von Dateien in JSONConfig",
"ru": "поддержка включает в файлы JSONConfig",
"pt": "suporte de inclui em arquivos JSONConfig",
"nl": "ondersteuning van opnames in JSONConfig-bestanden",
"fr": "prise en charge d'inclusions dans les fichiers JSONConfig",
"it": "il supporto di include nei file JSONConfig",
"es": "soporte de incluye en archivos JSONConfig",
"pl": "obsługa zawiera w plikach JSONConfig",
"uk": "підтримка включає в себе файли JSONConfig",
"zh-cn": "支持包含在 JSONConfig 文件"
},
"6.16.0": {
"en": "added a new tab to the installation wizard which recommends common adapters\napplied newest adapter-react-v5 changes and types",
"de": "einen neuen tab zum installationsassistenten hinzugefügt, der häufige adapter empfiehlt\nangewendet neueste adapter-react-v5 änderungen und typen",
Expand Down
77 changes: 39 additions & 38 deletions packages/admin/src/package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
{
"name": "src-rx",
"private": true,
"homepage": ".",
"scripts": {
"start": "set DANGEROUSLY_DISABLE_HOST_CHECK=true&& craco start",
"old-start": "react-scripts start",
"lint": "eslint --fix --ext .js,.jsx,.tsx src",
"build": "craco build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"check-ts": "tsc --noEmit --checkJS false",
"tsc": "tsc --project tsconfig.build.json"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not op_mini all"
],
"dependencies": {
"@iobroker/json-config": "file:../../jsonConfig"
},
"proxy": "http://127.0.0.1:8081",
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
"name": "src-rx",
"private": true,
"homepage": ".",
"scripts": {
"start": "set DANGEROUSLY_DISABLE_HOST_CHECK=true&& craco start",
"old-start": "react-scripts start",
"lint": "eslint --fix --ext .js,.jsx,.tsx src",
"build": "craco build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"check-ts": "tsc --noEmit --checkJS false",
"tsc": "tsc --project tsconfig.build.json"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not op_mini all"
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
"dependencies": {
"@iobroker/json-config": "file:../../jsonConfig"
},
"proxy": "http://127.0.0.1:8081",
"plugins": [
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
],
"version": "6.17.0"
}
24 changes: 11 additions & 13 deletions packages/jsonConfig/src/JsonConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,24 @@ class JsonConfig extends Router<JsonConfigProps, JsonConfigState> {
/>;
}

async scanForInclude(json: Record<string, any>, filePaths: string[]): Promise<void> {
async scanForInclude(json: Record<string, any>, filePaths: string[]): Promise<Record<string, any>> {
if (typeof json['#include'] === 'string') {
// load file
const data = await this._getConfigFile(json['#include'], [...filePaths]);
delete json['#include'];
if (data) {
// merge data
json = { ...json, ...data };
}
delete json['#include'];
} else {
const keys = Object.keys(json);
for (let k = 0; k < keys.length; k++) {
if (typeof json[keys[k]] === 'object') {
await this.scanForInclude(json[keys[k]], filePaths);
}
return json;
}
const keys = Object.keys(json);
for (let k = 0; k < keys.length; k++) {
if (typeof json[keys[k]] === 'object') {
json[keys[k]] = await this.scanForInclude(json[keys[k]], filePaths);
}
}
return json;
}

async getConfigFile(fileName?: string): Promise<Schema> {
Expand Down Expand Up @@ -468,17 +469,14 @@ class JsonConfig extends Router<JsonConfigProps, JsonConfigState> {
}

try {
const json = JSON5.parse(content);
// detect #include attr
await this.scanForInclude(json, _filePaths);

return json;
return (await this.scanForInclude(JSON5.parse(content), _filePaths)) as Schema;
} catch (e) {
window.alert('[JsonConfig] Cannot parse json5 config!');
console.log(e);
}
} catch (e1) {
!this.state.schema && window.alert(`[JsonConfig] Cannot read file: ${e1}`);
!this.state.schema && window.alert(`[JsonConfig] Cannot read file "${fileName}: ${e1}`);
}
return null;
}
Expand Down

0 comments on commit 089f813

Please sign in to comment.