From 6507c644ba838dffc34e2260794a44943d9d15aa Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Thu, 26 May 2022 19:35:07 +0200 Subject: [PATCH] https://github.com/ioBroker/ioBroker.admin/issues/1424 --- .gitignore | 1 + README.md | 3 +++ index.js | 26 ++++++++++++++------------ package.json | 3 ++- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index d805cca..175b8cd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /gulpfile.js nbproject /index.zip +/frontend/package-lock.json diff --git a/README.md b/README.md index e2c03ff..75b5b39 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ Branch (`master/main/dev`) is optional. --> ## Changelog +### **WORK IN PROGRESS** +* (bluefox) Added support of jsonConfig.json5 and jsonCustom.json5 + ### 2.0.5 (2022-05-22) * (bluefox) Made it possible to run with npx diff --git a/index.js b/index.js index be092ae..1126152 100644 --- a/index.js +++ b/index.js @@ -18,9 +18,10 @@ const stream = require('stream'); const Writable = stream.Writable; const sizeOf = require('image-size'); const axios = require('axios'); +const JSON5 = require('json5'); const compareVersions = require('compare-versions'); -const version = '1.4.0'; +const version = require('./package.json').version; const recommendedJsControllerVersion = '3.3.22'; const memStore = { }; @@ -1410,13 +1411,14 @@ function checkCode(context) { if (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') { readFiles.push('admin/jsonConfig.json'); - allowedLanguages.forEach(lang => { - readFiles.push(`admin/i18n/${lang}/translations.json`); - }); + readFiles.push('admin/jsonConfig.json5'); + allowedLanguages.forEach(lang => + readFiles.push(`admin/i18n/${lang}/translations.json`)); } if (context.ioPackageJson.common.supportCustoms || context.ioPackageJson.common.jsonCustom || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.custom === 'json')) { readFiles.push('admin/jsonCustom.json'); + readFiles.push('admin/jsonCustom.json5'); } } @@ -1504,14 +1506,14 @@ function checkCode(context) { } if (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.config === 'json') { - if (context['/admin/jsonConfig.json']) { + if (context['/admin/jsonConfig.json'] || context['/admin/jsonConfig.json5']) { try { - JSON.parse(context['/admin/jsonConfig.json']); + context['/admin/jsonConfig.json'] ? JSON.parse(context['/admin/jsonConfig.json']) : JSON5.parse(context['/admin/jsonConfig.json5']); } catch (e) { - context.errors.push('[E507] Cannot parse "admin/jsonConfig.json": ' + e); + context.errors.push(`[E507] Cannot parse "admin/jsonConfig.json${context['/admin/jsonConfig.json'] ? '' : '5'}": ${e}`); } } else { - context.errors.push(`[E508] "admin/jsonConfig.json" not found, but admin support is declared`); + context.errors.push(`[E508] "admin/jsonConfig.json${context['/admin/jsonConfig.json'] ? '' : '5'}" not found, but admin support is declared`); } allowedLanguages.forEach(lang => { @@ -1528,14 +1530,14 @@ function checkCode(context) { } if (context.ioPackageJson.common.supportCustoms || context.ioPackageJson.common.jsonCustom || (context.ioPackageJson.common.adminUI && context.ioPackageJson.common.adminUI.custom === 'json')) { - if (context['/admin/jsonCustom.json']) { + if (context['/admin/jsonCustom.json'] || context['/admin/jsonCustom.json5']) { try { - JSON.parse(context['/admin/jsonCustom.json']); + context['/admin/jsonCustom.json'] ? JSON.parse(context['/admin/jsonCustom.json']) : JSON5.parse(context['/admin/jsonCustom.json5']); } catch (e) { - context.errors.push('[E511] Cannot parse "admin/jsonCustom.json": ' + e); + context.errors.push(`[E511] Cannot parse "admin/jsonCustom.json${context['/admin/jsonCustom.json'] ? '' : '5'}": ${e}`); } } else { - context.errors.push(`[E512] "admin/jsonCustom.json" not found, but custom support is declared`); + context.errors.push(`[E512] "admin/jsonCustom.json${context['/admin/jsonCustom.json'] ? '' : '5'}" not found, but custom support is declared`); } } diff --git a/package.json b/package.json index fb9651c..8d3e035 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "axios": "^0.27.2", "compare-versions": "^4.1.3", "image-size": "^1.0.1", - "unzipper": "^0.10.11" + "unzipper": "^0.10.11", + "json5": "^2.2.1" }, "publishConfig": { "access": "public"