mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-30 13:09:34 +00:00
Review config_check.js (#3545)
Only details changes. No functional changes. - remove superfluous colors in Log.error - invert negative if - update ESLint env - use camel case variable name - optimize Log strings
This commit is contained in:
parent
c6e05c9fec
commit
06f6fbf49b
@ -12,9 +12,9 @@ _This release is scheduled to be released on 2024-10-01._
|
|||||||
### Added
|
### Added
|
||||||
|
|
||||||
- [core] Check config at every start of MagicMirror² (#3450)
|
- [core] Check config at every start of MagicMirror² (#3450)
|
||||||
- [core] Add spelling check (cspell): `npm run test:spelling` and handle spelling issues
|
- [core] Add spelling check (cspell): `npm run test:spelling` and handle spelling issues (#3544)
|
||||||
- [core] removed `config.paths.vendor` (could not work because `vendor` is hardcoded in `index.html`), renamed `config.paths.modules` to `config.foreignModulesDir`, added variable `MM_CUSTOMCSS_FILE` which - if set - overrides `config.customCss`, added variable `MM_MODULES_DIR` which - if set - overrides `config.foreignModulesDir`
|
- [core] removed `config.paths.vendor` (could not work because `vendor` is hardcoded in `index.html`), renamed `config.paths.modules` to `config.foreignModulesDir`, added variable `MM_CUSTOMCSS_FILE` which - if set - overrides `config.customCss`, added variable `MM_MODULES_DIR` which - if set - overrides `config.foreignModulesDir` (#3530)
|
||||||
- [core] elements are now removed from index.html when loading script or stylesheet files fails
|
- [core] elements are now removed from `index.html` when loading script or stylesheet files fails
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
@ -27,6 +27,7 @@ _This release is scheduled to be released on 2024-10-01._
|
|||||||
- [core] Updated dependencies including stylistic-eslint
|
- [core] Updated dependencies including stylistic-eslint
|
||||||
- [core] Updated SocketIO catch all to new API
|
- [core] Updated SocketIO catch all to new API
|
||||||
- [core] Allow custom modules positions by scanning index.html for the defined regions, instead of hard coded (PR #3518 fixes issue #3504)
|
- [core] Allow custom modules positions by scanning index.html for the defined regions, instead of hard coded (PR #3518 fixes issue #3504)
|
||||||
|
- [core] Detail optimizations in `config_check.js`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
"crazyscot",
|
"crazyscot",
|
||||||
"Creepin",
|
"Creepin",
|
||||||
"currentweather",
|
"currentweather",
|
||||||
|
"CUSTOMCSS",
|
||||||
"customregions",
|
"customregions",
|
||||||
"Cymraeg",
|
"Cymraeg",
|
||||||
"dariom",
|
"dariom",
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
const path = require("node:path");
|
const path = require("node:path");
|
||||||
const fs = require("node:fs");
|
const fs = require("node:fs");
|
||||||
|
const Ajv = require("ajv");
|
||||||
const colors = require("ansis");
|
const colors = require("ansis");
|
||||||
const { Linter } = require("eslint");
|
const { Linter } = require("eslint");
|
||||||
|
|
||||||
const linter = new Linter();
|
|
||||||
|
|
||||||
const Ajv = require("ajv");
|
|
||||||
|
|
||||||
const ajv = new Ajv();
|
|
||||||
|
|
||||||
const rootPath = path.resolve(`${__dirname}/../`);
|
const rootPath = path.resolve(`${__dirname}/../`);
|
||||||
const Log = require(`${rootPath}/js/logger.js`);
|
const Log = require(`${rootPath}/js/logger.js`);
|
||||||
const Utils = require(`${rootPath}/js/utils.js`);
|
const Utils = require(`${rootPath}/js/utils.js`);
|
||||||
|
|
||||||
|
const linter = new Linter();
|
||||||
|
const ajv = new Ajv();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string with path of configuration file.
|
* Returns a string with path of configuration file.
|
||||||
* Check if set by environment variable MM_CONFIG_FILE
|
* Check if set by environment variable MM_CONFIG_FILE
|
||||||
@ -38,28 +36,28 @@ function checkConfigFile () {
|
|||||||
// Check permission
|
// Check permission
|
||||||
try {
|
try {
|
||||||
fs.accessSync(configFileName, fs.F_OK);
|
fs.accessSync(configFileName, fs.F_OK);
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
Log.error(e);
|
Log.error(error);
|
||||||
throw new Error("No permission to access config file!");
|
throw new Error("No permission to access config file!");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate syntax of the configuration file.
|
// Validate syntax of the configuration file.
|
||||||
Log.info("Checking file... ", configFileName);
|
Log.info(`Checking config file ${configFileName} ...`);
|
||||||
|
|
||||||
// I'm not sure if all ever is utf-8
|
// I'm not sure if all ever is utf-8
|
||||||
const configFile = fs.readFileSync(configFileName, "utf-8");
|
const configFile = fs.readFileSync(configFileName, "utf-8");
|
||||||
|
|
||||||
// Explicitly tell linter that he might encounter es6 syntax ("let config = {...}")
|
// Explicitly tell linter that he might encounter es2024 syntax ("let config = {...}")
|
||||||
const errors = linter.verify(configFile, {
|
const errors = linter.verify(configFile, {
|
||||||
env: {
|
env: {
|
||||||
es6: true
|
es2024: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (errors.length === 0) {
|
if (errors.length === 0) {
|
||||||
Log.info(colors.green("Your configuration file doesn't contain syntax errors :)"));
|
Log.info(colors.green("Your configuration file doesn't contain syntax errors :)"));
|
||||||
} else {
|
} else {
|
||||||
Log.error(colors.red("Your configuration file contains syntax errors :("));
|
Log.error("Your configuration file contains syntax errors :(");
|
||||||
|
|
||||||
for (const error of errors) {
|
for (const error of errors) {
|
||||||
Log.error(`Line ${error.line} column ${error.column}: ${error.message}`);
|
Log.error(`Line ${error.line} column ${error.column}: ${error.message}`);
|
||||||
@ -69,7 +67,7 @@ function checkConfigFile () {
|
|||||||
|
|
||||||
Log.info("Checking modules structure configuration ...");
|
Log.info("Checking modules structure configuration ...");
|
||||||
|
|
||||||
const position_list = Utils.getModulePositions();
|
const positionList = Utils.getModulePositions();
|
||||||
|
|
||||||
// Make Ajv schema configuration of modules config
|
// Make Ajv schema configuration of modules config
|
||||||
// only scan "module" and "position"
|
// only scan "module" and "position"
|
||||||
@ -86,7 +84,7 @@ function checkConfigFile () {
|
|||||||
},
|
},
|
||||||
position: {
|
position: {
|
||||||
type: "string",
|
type: "string",
|
||||||
enum: position_list
|
enum: positionList
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
required: ["module"]
|
required: ["module"]
|
||||||
@ -95,25 +93,25 @@ function checkConfigFile () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// scan all modules
|
// Scan all modules
|
||||||
const validate = ajv.compile(schema);
|
const validate = ajv.compile(schema);
|
||||||
const data = require(configFileName);
|
const data = require(configFileName);
|
||||||
|
|
||||||
const valid = validate(data);
|
const valid = validate(data);
|
||||||
if (!valid) {
|
if (valid) {
|
||||||
let module = validate.errors[0].instancePath.split("/")[2];
|
Log.info(colors.green("Your modules structure configuration doesn't contain errors :)"));
|
||||||
let position = validate.errors[0].instancePath.split("/")[3];
|
} else {
|
||||||
|
const module = validate.errors[0].instancePath.split("/")[2];
|
||||||
|
const position = validate.errors[0].instancePath.split("/")[3];
|
||||||
|
|
||||||
Log.error(colors.red("This module configuration contains errors:"));
|
Log.error("This module configuration contains errors:");
|
||||||
Log.error(`\n${JSON.stringify(data.modules[module], null, 2)}`);
|
Log.error(`\n${JSON.stringify(data.modules[module], null, 2)}`);
|
||||||
if (position) {
|
if (position) {
|
||||||
Log.error(colors.red(`${position}: ${validate.errors[0].message}`));
|
Log.error(`${position}: ${validate.errors[0].message}`);
|
||||||
Log.error(`\n${JSON.stringify(validate.errors[0].params.allowedValues, null, 2).slice(1, -1)}`);
|
Log.error(`\n${JSON.stringify(validate.errors[0].params.allowedValues, null, 2).slice(1, -1)}`);
|
||||||
} else {
|
} else {
|
||||||
Log.error(colors.red(validate.errors[0].message));
|
Log.error(validate.errors[0].message);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Log.info(colors.green("Your modules structure configuration doesn't contain errors :)"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user