User logger in checkconfig script

This commit is contained in:
Veeck
2020-05-18 09:53:34 +02:00
committed by rejas
parent 0cae954f80
commit 2334cbd78a

View File

@@ -17,6 +17,7 @@ const fs = require("fs");
const rootPath = path.resolve(__dirname + "/../"); const rootPath = path.resolve(__dirname + "/../");
const config = require(rootPath + "/.eslintrc.json"); const config = require(rootPath + "/.eslintrc.json");
const Logger = require(rootPath + "/js/logger.js");
const Utils = require(rootPath + "/js/utils.js"); const Utils = require(rootPath + "/js/utils.js");
/* getConfigFile() /* getConfigFile()
@@ -36,21 +37,20 @@ function checkConfigFile() {
const 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); Logger.error(Utils.colors.error("File not found: "), configFileName);
return; return;
} }
// check permission // check permission
try { try {
fs.accessSync(configFileName, fs.F_OK); fs.accessSync(configFileName, fs.F_OK);
} catch (e) { } catch (e) {
console.log(Utils.colors.error(e)); Logger.log(Utils.colors.error(e));
return; return;
} }
// Validate syntax of the configuration file. // Validate syntax of the configuration file.
// In case the there errors show messages and Logger.info(Utils.colors.info("Checking file... "), configFileName);
// return
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) { if (err) {
@@ -58,11 +58,12 @@ function checkConfigFile() {
} }
const messages = linter.verify(data, config); const messages = linter.verify(data, config);
if (messages.length === 0) { if (messages.length === 0) {
console.log("Your configuration file doesn't contain syntax errors :)"); Logger.log("Your configuration file doesn't contain syntax errors :)");
return true; return true;
} else { } else {
messages.forEach((error) => { // In case the there errors show messages and return
console.log("Line", error.line, "col", error.column, error.message); messages.forEach(error => {
Logger.log("Line", error.line, "col", error.column, error.message);
}); });
} }
}); });