Move config check into js folder, cleanup var usage

This commit is contained in:
Veeck 2020-04-01 21:07:50 +02:00
parent 172d668416
commit c7c6dc4e67
2 changed files with 13 additions and 16 deletions

View File

@ -11,11 +11,13 @@
const Linter = require("eslint").Linter;
const linter = new Linter();
const config = require(__dirname + "/../../.eslintrc.json");
var path = require("path");
var fs = require("fs");
var Utils = require(__dirname + "/../../js/utils.js");
const path = require("path");
const fs = require("fs");
const rootPath = path.resolve(__dirname + "/../");
const config = require(rootPath + "/.eslintrc.json");
const Utils = require(rootPath + "/js/utils.js");
/* getConfigFile()
* Return string with path of configuration file
@ -23,8 +25,7 @@ var Utils = require(__dirname + "/../../js/utils.js");
*/
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");
let configFileName = path.resolve(rootPath + "/config/config.js");
if (process.env.MM_CONFIG_FILE) {
configFileName = path.resolve(process.env.MM_CONFIG_FILE);
}
@ -32,7 +33,7 @@ function getConfigFile() {
}
function checkConfigFile() {
var configFileName = getConfigFile();
const configFileName = getConfigFile();
// Check if file is present
if (fs.existsSync(configFileName) === false) {
console.error(Utils.colors.error("File not found: "), configFileName);
@ -49,7 +50,7 @@ function checkConfigFile() {
// Validate syntax of the configuration file.
// In case the there errors show messages and
// 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
fs.readFile(configFileName, "utf-8", function (err, data) {
if (err) { throw err; }
@ -58,15 +59,11 @@ function checkConfigFile() {
console.log("Your configuration file doesn't contain syntax errors :)");
return true;
} else {
errors = messages;
for (var idx in errors) {
error = errors[idx];
messages.forEach(error => {
console.log("Line", error.line, "col", error.column, error.message);
}
});
}
});
}
if (process.env.NODE_ENV !== "test") {
checkConfigFile();
}

View File

@ -15,7 +15,7 @@
"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: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: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",