Merge pull request #2569 from thelounge/xpaw/fix-2568

Fix circular dependency in Helper+log
This commit is contained in:
Pavel Djundik 2018-06-19 16:17:58 +03:00 committed by GitHub
commit b744ff6b1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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"));
});
});