mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Move config check into js folder, cleanup var usage
This commit is contained in:
parent
172d668416
commit
c7c6dc4e67
@ -11,11 +11,13 @@
|
|||||||
|
|
||||||
const Linter = require("eslint").Linter;
|
const Linter = require("eslint").Linter;
|
||||||
const linter = new Linter();
|
const linter = new Linter();
|
||||||
const config = require(__dirname + "/../../.eslintrc.json");
|
|
||||||
|
|
||||||
var path = require("path");
|
const path = require("path");
|
||||||
var fs = require("fs");
|
const fs = require("fs");
|
||||||
var Utils = require(__dirname + "/../../js/utils.js");
|
|
||||||
|
const rootPath = path.resolve(__dirname + "/../");
|
||||||
|
const config = require(rootPath + "/.eslintrc.json");
|
||||||
|
const Utils = require(rootPath + "/js/utils.js");
|
||||||
|
|
||||||
/* getConfigFile()
|
/* getConfigFile()
|
||||||
* Return string with path of configuration file
|
* Return string with path of configuration file
|
||||||
@ -23,8 +25,7 @@ var Utils = require(__dirname + "/../../js/utils.js");
|
|||||||
*/
|
*/
|
||||||
function getConfigFile() {
|
function getConfigFile() {
|
||||||
// FIXME: This function should be in core. Do you want refactor me ;) ?, be good!
|
// FIXME: This function should be in core. Do you want refactor me ;) ?, be good!
|
||||||
rootPath = path.resolve(__dirname + "/../../");
|
let configFileName = path.resolve(rootPath + "/config/config.js");
|
||||||
var configFileName = path.resolve(rootPath + "/config/config.js");
|
|
||||||
if (process.env.MM_CONFIG_FILE) {
|
if (process.env.MM_CONFIG_FILE) {
|
||||||
configFileName = path.resolve(process.env.MM_CONFIG_FILE);
|
configFileName = path.resolve(process.env.MM_CONFIG_FILE);
|
||||||
}
|
}
|
||||||
@ -32,7 +33,7 @@ function getConfigFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkConfigFile() {
|
function checkConfigFile() {
|
||||||
var configFileName = getConfigFile();
|
const configFileName = getConfigFile();
|
||||||
// Check if file is present
|
// Check if file is present
|
||||||
if (fs.existsSync(configFileName) === false) {
|
if (fs.existsSync(configFileName) === false) {
|
||||||
console.error(Utils.colors.error("File not found: "), configFileName);
|
console.error(Utils.colors.error("File not found: "), configFileName);
|
||||||
@ -49,7 +50,7 @@ function checkConfigFile() {
|
|||||||
// Validate syntax of the configuration file.
|
// Validate syntax of the configuration file.
|
||||||
// In case the there errors show messages and
|
// In case the there errors show messages and
|
||||||
// return
|
// return
|
||||||
console.info(Utils.colors.info("Checking file... ", configFileName));
|
console.info(Utils.colors.info("Checking file... "), configFileName);
|
||||||
// I'm not sure if all ever is utf-8
|
// I'm not sure if all ever is utf-8
|
||||||
fs.readFile(configFileName, "utf-8", function (err, data) {
|
fs.readFile(configFileName, "utf-8", function (err, data) {
|
||||||
if (err) { throw err; }
|
if (err) { throw err; }
|
||||||
@ -58,15 +59,11 @@ function checkConfigFile() {
|
|||||||
console.log("Your configuration file doesn't contain syntax errors :)");
|
console.log("Your configuration file doesn't contain syntax errors :)");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
errors = messages;
|
messages.forEach(error => {
|
||||||
for (var idx in errors) {
|
|
||||||
error = errors[idx];
|
|
||||||
console.log("Line", error.line, "col", error.column, error.message);
|
console.log("Line", error.line, "col", error.column, error.message);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== "test") {
|
|
||||||
checkConfigFile();
|
checkConfigFile();
|
||||||
}
|
|
@ -15,7 +15,7 @@
|
|||||||
"test:lint": "npm run test:js && npm run test:style",
|
"test:lint": "npm run test:js && npm run test:style",
|
||||||
"test:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json",
|
"test:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json",
|
||||||
"test:style": "stylelint css/main.css modules/default/**/*.css --config .stylelintrc.json",
|
"test:style": "stylelint css/main.css modules/default/**/*.css --config .stylelintrc.json",
|
||||||
"config:check": "node tests/configs/check_config.js",
|
"config:check": "node js/check_config.js",
|
||||||
"lint": "npm run lint:js && npm run lint:json && npm run lint:markdown && npm run lint:style && npm run lint:yaml",
|
"lint": "npm run lint:js && npm run lint:json && npm run lint:markdown && npm run lint:style && npm run lint:yaml",
|
||||||
"lint:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json --fix",
|
"lint:js": "eslint *.js js/**/*.js modules/default/**/*.js clientonly/*.js serveronly/*.js translations/*.js vendor/*.js tests/**/*.js config/* --config .eslintrc.json --fix",
|
||||||
"lint:json": "jsonlint -q package.json .eslintrc.json .markdownlintrc.json .stylelintrc.json modules/default/*/translations/*.json translations/*.json vendor/package.json",
|
"lint:json": "jsonlint -q package.json .eslintrc.json .markdownlintrc.json .stylelintrc.json modules/default/*/translations/*.json translations/*.json vendor/package.json",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user