mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
Add task to check configuration file syntax.
This commit is contained in:
parent
2c0ca78265
commit
f89f704a69
@ -49,6 +49,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Korean Translation.
|
- Korean Translation.
|
||||||
- Added console warning on startup when deprecated config options are used
|
- Added console warning on startup when deprecated config options are used
|
||||||
- Added `DAYAFTERTOMORROW`, `UPDATE_NOTIFICATION`, `UPDATE_NOTIFICATION_MODULE`, `UPDATE_INFO` to Norwegian translations (`nn` and `nb`).
|
- Added `DAYAFTERTOMORROW`, `UPDATE_NOTIFICATION`, `UPDATE_NOTIFICATION_MODULE`, `UPDATE_INFO` to Norwegian translations (`nn` and `nb`).
|
||||||
|
- Add task to check configuration file
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Update .gitignore to not ignore default modules folder.
|
- Update .gitignore to not ignore default modules folder.
|
||||||
|
@ -104,6 +104,11 @@ Type `git status` to see your changes, if there are any, you can reset them with
|
|||||||
1. Duplicate `config/config.js.sample` to `config/config.js`. **Note:** If you used the installer script. This step is already done for you.
|
1. Duplicate `config/config.js.sample` to `config/config.js`. **Note:** If you used the installer script. This step is already done for you.
|
||||||
2. Modify your required settings.
|
2. Modify your required settings.
|
||||||
|
|
||||||
|
Note: You'll can check your configuration running the follow command:
|
||||||
|
```bash
|
||||||
|
npm run config:check
|
||||||
|
```
|
||||||
|
|
||||||
The following properties can be configured:
|
The following properties can be configured:
|
||||||
|
|
||||||
| **Option** | **Description** |
|
| **Option** | **Description** |
|
||||||
|
@ -11,7 +11,8 @@ var colors = require("colors/safe");
|
|||||||
var Utils = {
|
var Utils = {
|
||||||
colors: {
|
colors: {
|
||||||
warn: colors.yellow,
|
warn: colors.yellow,
|
||||||
error: colors.red
|
error: colors.red,
|
||||||
|
info: colors.blue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,9 +6,10 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "sh run-start.sh",
|
"start": "sh run-start.sh",
|
||||||
"postinstall": "sh installers/postinstall/postinstall.sh",
|
"postinstall": "sh installers/postinstall/postinstall.sh",
|
||||||
"test": "./node_modules/mocha/bin/mocha tests --recursive",
|
"test": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests --recursive",
|
||||||
"test:unit": "./node_modules/mocha/bin/mocha tests/unit --recursive",
|
"test:unit": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests/unit --recursive",
|
||||||
"test:e2e": "./node_modules/mocha/bin/mocha tests/e2e --recursive"
|
"test:e2e": "NODE_ENV=test ./node_modules/mocha/bin/mocha tests/e2e --recursive",
|
||||||
|
"config:check": "node tests/configs/check_config.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -38,6 +39,7 @@
|
|||||||
"grunt-markdownlint": "^1.0.13",
|
"grunt-markdownlint": "^1.0.13",
|
||||||
"grunt-stylelint": "latest",
|
"grunt-stylelint": "latest",
|
||||||
"grunt-yamllint": "latest",
|
"grunt-yamllint": "latest",
|
||||||
|
"jshint": "^2.9.4",
|
||||||
"mocha": "^3.2.0",
|
"mocha": "^3.2.0",
|
||||||
"spectron": "^3.4.1",
|
"spectron": "^3.4.1",
|
||||||
"stylelint-config-standard": "latest",
|
"stylelint-config-standard": "latest",
|
||||||
|
66
tests/configs/check_config.js
Normal file
66
tests/configs/check_config.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* Magic Mirror
|
||||||
|
*
|
||||||
|
* Checker configuration file
|
||||||
|
*
|
||||||
|
* By Rodrigo Ramírez Norambuena
|
||||||
|
* https://rodrigoramirez.com
|
||||||
|
*
|
||||||
|
* MIT Licensed.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
var v = require("jshint");
|
||||||
|
var path = require("path");
|
||||||
|
var fs = require("fs");
|
||||||
|
var Utils = require(__dirname + "/../../js/utils.js");
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV == "test") {return 0};
|
||||||
|
|
||||||
|
/* getConfigFile()
|
||||||
|
* Return string with path of configuration file
|
||||||
|
* Check if set by enviroment variable MM_CONFIG_FILE
|
||||||
|
*/
|
||||||
|
function getConfigFile() {
|
||||||
|
// FIXME: This function should be in core. Do you want refactor me ;) ?, be good!
|
||||||
|
rootPath = path.resolve(__dirname + "/../../");
|
||||||
|
var configFileName = path.resolve(rootPath + "/config/config.js");
|
||||||
|
if (process.env.MM_CONFIG_FILE) {
|
||||||
|
configFileName = path.resolve(process.env.MM_CONFIG_FILE);
|
||||||
|
}
|
||||||
|
return configFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
var configFileName = getConfigFile();
|
||||||
|
// Check if file is present
|
||||||
|
if (fs.existsSync(configFileName) === false) {
|
||||||
|
console.error(Utils.colors.error("File not found: "), configFileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// check permision
|
||||||
|
try {
|
||||||
|
fs.accessSync(configFileName, fs.F_OK);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(Utils.colors.error(e));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate syntax of the configuration file.
|
||||||
|
// In case the there errors show messages and
|
||||||
|
// return
|
||||||
|
console.info(Utils.colors.info("Checking file... ", configFileName));
|
||||||
|
// I'm not sure if all ever is utf-8
|
||||||
|
fs.readFile(configFileName, "utf-8", function(err, data) {
|
||||||
|
if (err) {throw err;}
|
||||||
|
v.JSHINT(data); // Parser by jshint
|
||||||
|
|
||||||
|
if (v.JSHINT.errors.length == 0) {
|
||||||
|
console.log("Your configuration file don't containt syntax error :)");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
errors = v.JSHINT.data().errors;
|
||||||
|
for (idx in errors) {
|
||||||
|
error = errors[idx];
|
||||||
|
console.log("Line", error.line, "col", error.character, error.reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user