Fix circular dependency in Helper+log

Fixes #2568
This commit is contained in:
Pavel Djundik 2018-06-19 10:09:38 +03:00
parent 36aef26ce9
commit 08682d2448
4 changed files with 9 additions and 10 deletions

View file

@ -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";

View file

@ -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");
},
};

View file

@ -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) {

View file

@ -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"));
});
});