From 08682d2448b316ec46ef78420b1e317ca3db7fe9 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 19 Jun 2018 10:09:38 +0300 Subject: [PATCH] Fix circular dependency in Helper+log Fixes #2568 --- src/helper.js | 6 ------ src/log.js | 8 ++++++-- src/plugins/messageStorage/text.js | 2 +- test/src/helperTest.js | 3 ++- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/helper.js b/src/helper.js index 919b9ead..7fb2a9d7 100644 --- a/src/helper.js +++ b/src/helper.js @@ -9,7 +9,6 @@ const fs = require("fs"); const net = require("net"); const bcrypt = require("bcryptjs"); const colors = require("chalk"); -const moment = require("moment"); let homePath; let configPath; @@ -32,7 +31,6 @@ const Helper = { setHome, getVersion, getGitCommit, - getHumanDate, ip2hex, mergeConfig, getDefaultNick, @@ -208,10 +206,6 @@ function passwordCompare(password, expected) { return bcrypt.compare(password, expected); } -function getHumanDate() { - return moment().format("YYYY-MM-DD HH:mm:ss"); -} - function getDefaultNick() { if (!this.config.defaults.nick) { return "thelounge"; diff --git a/src/log.js b/src/log.js index 9011623d..3c58b85b 100644 --- a/src/log.js +++ b/src/log.js @@ -2,10 +2,10 @@ const colors = require("chalk"); const read = require("read"); -const Helper = require("./helper"); +const moment = require("moment"); function timestamp() { - return colors.dim(Helper.getHumanDate()); + return colors.dim(module.exports.getHumanDate()); } module.exports = { @@ -31,4 +31,8 @@ module.exports = { options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" "); read(options, callback); }, + + getHumanDate() { + return moment().format("YYYY-MM-DD HH:mm:ss"); + }, }; diff --git a/src/plugins/messageStorage/text.js b/src/plugins/messageStorage/text.js index ce1e63a4..212ad752 100644 --- a/src/plugins/messageStorage/text.js +++ b/src/plugins/messageStorage/text.js @@ -41,7 +41,7 @@ class TextFileMessageStorage { return; } - let line = `[${Helper.getHumanDate()}] `; + let line = `[${log.getHumanDate()}] `; // message types from src/models/msg.js switch (msg.type) { diff --git a/test/src/helperTest.js b/test/src/helperTest.js index 54ae3264..93574639 100644 --- a/test/src/helperTest.js +++ b/test/src/helperTest.js @@ -4,6 +4,7 @@ const expect = require("chai").expect; const os = require("os"); const moment = require("moment"); const Helper = require("../../src/helper"); +const log = require("../../src/log"); describe("Helper", function() { describe("#expandHome", function() { @@ -55,6 +56,6 @@ describe("Helper", function() { }); describe("#getHumanDate()", function() { - expect(Helper.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss")); + expect(log.getHumanDate()).to.equal(moment().format("YYYY-MM-DD HH:mm:ss")); }); });