Lint stuff

This commit is contained in:
Veeck 2020-05-25 18:57:15 +02:00 committed by rejas
parent 8c319903dd
commit 13073bc98d
8 changed files with 63 additions and 56 deletions

View File

@ -51,7 +51,7 @@ var App = function () {
*
* argument callback function - The callback function.
*/
var loadConfig = function(callback) {
var loadConfig = function (callback) {
Log.log("Loading config ...");
var defaults = require(__dirname + "/defaults.js");
@ -92,11 +92,7 @@ var App = function () {
}
});
if (usedDeprecated.length > 0) {
Log.warn(Utils.colors.warn(
"WARNING! Your config is using deprecated options: " +
usedDeprecated.join(", ") +
". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.")
);
Log.warn(Utils.colors.warn("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality."));
}
};
@ -153,7 +149,7 @@ var App = function () {
*
* argument module string - The name of the module (including subpath).
*/
var loadModules = function(modules, callback) {
var loadModules = function (modules, callback) {
Log.log("Loading module helpers ...");
var loadNextModule = function () {
@ -215,8 +211,8 @@ var App = function () {
}
}
loadModules(modules, function() {
var server = new Server(config, function(app, io) {
loadModules(modules, function () {
var server = new Server(config, function (app, io) {
Log.log("Server started ...");
for (var h in nodeHelpers) {
@ -258,7 +254,9 @@ var App = function () {
*/
process.on("SIGINT", () => {
Log.log("[SIGINT] Received. Shutting down server...");
setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds
setTimeout(() => {
process.exit(0);
}, 3000); // Force quit after 3 seconds
this.stop();
process.exit(0);
});
@ -267,7 +265,9 @@ var App = function () {
*/
process.on("SIGTERM", () => {
Log.log("[SIGTERM] Received. Shutting down server...");
setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds
setTimeout(() => {
process.exit(0);
}, 3000); // Force quit after 3 seconds
this.stop();
process.exit(0);
});

View File

@ -62,7 +62,7 @@ function checkConfigFile() {
return true;
} else {
// In case the there errors show messages and return
messages.forEach(error => {
messages.forEach((error) => {
Logger.log("Line", error.line, "col", error.column, error.message);
});
}

View File

@ -86,7 +86,7 @@ function createWindow() {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on("ready", function() {
app.on("ready", function () {
Log.log("Launching application.");
createWindow();
});

View File

@ -171,34 +171,42 @@ var Loader = (function () {
var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1);
switch (extension.toLowerCase()) {
case "js":
Log.log("Load script: " + fileName);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = fileName;
script.onload = function() {
if (typeof callback === "function") {callback();}
};
script.onerror = function() {
Log.error("Error on loading script:", fileName);
if (typeof callback === "function") {callback();}
};
case "js":
Log.log("Load script: " + fileName);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = fileName;
script.onload = function () {
if (typeof callback === "function") {
callback();
}
};
script.onerror = function () {
Log.error("Error on loading script:", fileName);
if (typeof callback === "function") {
callback();
}
};
document.getElementsByTagName("body")[0].appendChild(script);
break;
case "css":
Log.log("Load stylesheet: " + fileName);
var stylesheet = document.createElement("link");
stylesheet.rel = "stylesheet";
stylesheet.type = "text/css";
stylesheet.href = fileName;
stylesheet.onload = function() {
if (typeof callback === "function") {callback();}
};
stylesheet.onerror = function() {
Log.error("Error on loading stylesheet:", fileName);
if (typeof callback === "function") {callback();}
};
document.getElementsByTagName("body")[0].appendChild(script);
break;
case "css":
Log.log("Load stylesheet: " + fileName);
var stylesheet = document.createElement("link");
stylesheet.rel = "stylesheet";
stylesheet.type = "text/css";
stylesheet.href = fileName;
stylesheet.onload = function () {
if (typeof callback === "function") {
callback();
}
};
stylesheet.onerror = function () {
Log.error("Error on loading stylesheet:", fileName);
if (typeof callback === "function") {
callback();
}
};
document.getElementsByTagName("head")[0].appendChild(stylesheet);
break;

View File

@ -7,7 +7,7 @@
* MIT Licensed.
*/
(function (root, factory) {
if (typeof exports === 'object') {
if (typeof exports === "object") {
// add timestamps in front of log messages
require("console-stamp")(console, "yyyy-mm-dd HH:MM:ss.l");
@ -17,8 +17,7 @@
// Browser globals (root is window)
root.Log = factory(root.config);
}
}(this, function (config) {
})(this, function (config) {
let logLevel = {
info: Function.prototype.bind.call(console.info, console),
log: Function.prototype.bind.call(console.log, console),
@ -30,15 +29,15 @@
time: Function.prototype.bind.call(console.time, console),
timeEnd: Function.prototype.bind.call(console.timeEnd, console),
timeStamp: Function.prototype.bind.call(console.timeStamp, console)
}
};
if (config && config.logLevel) {
Object.keys(logLevel).forEach(function(key,index) {
Object.keys(logLevel).forEach(function (key, index) {
if (!config.logLevel.includes(key.toLocaleUpperCase())) {
logLevel[key] = function() {};
logLevel[key] = function () {};
}
});
}
return logLevel;
}));
});

View File

@ -9,16 +9,16 @@ const Log = require("./logger.js");
const express = require("express");
var NodeHelper = Class.extend({
init: function() {
init: function () {
Log.log("Initializing new module helper ...");
},
loaded: function(callback) {
loaded: function (callback) {
Log.log("Module helper loaded: " + this.name);
callback();
},
start: function() {
start: function () {
Log.log("Starting module helper: " + this.name);
},
@ -28,7 +28,7 @@ var NodeHelper = Class.extend({
* gracefully exit the module.
*
*/
stop: function() {
stop: function () {
Log.log("Stopping module helper: " + this.name);
},
@ -38,7 +38,7 @@ var NodeHelper = Class.extend({
* argument notification string - The identifier of the notification.
* argument payload mixed - The payload of the notification.
*/
socketNotificationReceived: function(notification, payload) {
socketNotificationReceived: function (notification, payload) {
Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload);
},

View File

@ -337,7 +337,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr
/* scheduleTimer()
* Schedule the timer for the next update.
*/
var scheduleTimer = function() {
var scheduleTimer = function () {
clearTimeout(reloadTimer);
reloadTimer = setTimeout(function () {
fetchCalendar();
@ -435,8 +435,8 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr
/* broadcastItems()
* Broadcast the existing events.
*/
this.broadcastEvents = function() {
console.info('Broadcasting ' + events.length + ' events.');
this.broadcastEvents = function () {
console.info("Broadcasting " + events.length + " events.");
eventsReceivedCallback(self);
};

View File

@ -1,7 +1,7 @@
const app = require("../js/app.js");
const Log = require("../js/logger.js");
app.start(function(config) {
app.start(function (config) {
var bindAddress = config.address ? config.address : "localhost";
var httpType = config.useHttps ? "https" : "http";
Log.log("\nReady to go! Please point your browser to: " + httpType + "://" + bindAddress + ":" + config.port);