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 net = require("net");
const bcrypt = require("bcryptjs"); const bcrypt = require("bcryptjs");
const colors = require("chalk"); const colors = require("chalk");
const moment = require("moment");
let homePath; let homePath;
let configPath; let configPath;
@ -32,7 +31,6 @@ const Helper = {
setHome, setHome,
getVersion, getVersion,
getGitCommit, getGitCommit,
getHumanDate,
ip2hex, ip2hex,
mergeConfig, mergeConfig,
getDefaultNick, getDefaultNick,
@ -208,10 +206,6 @@ function passwordCompare(password, expected) {
return bcrypt.compare(password, expected); return bcrypt.compare(password, expected);
} }
function getHumanDate() {
return moment().format("YYYY-MM-DD HH:mm:ss");
}
function getDefaultNick() { function getDefaultNick() {
if (!this.config.defaults.nick) { if (!this.config.defaults.nick) {
return "thelounge"; return "thelounge";

View File

@ -2,10 +2,10 @@
const colors = require("chalk"); const colors = require("chalk");
const read = require("read"); const read = require("read");
const Helper = require("./helper"); const moment = require("moment");
function timestamp() { function timestamp() {
return colors.dim(Helper.getHumanDate()); return colors.dim(module.exports.getHumanDate());
} }
module.exports = { module.exports = {
@ -31,4 +31,8 @@ module.exports = {
options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" "); options.prompt = [timestamp(), colors.cyan("[PROMPT]"), options.text].join(" ");
read(options, callback); read(options, callback);
}, },
getHumanDate() {
return moment().format("YYYY-MM-DD HH:mm:ss");
},
}; };

View File

@ -41,7 +41,7 @@ class TextFileMessageStorage {
return; return;
} }
let line = `[${Helper.getHumanDate()}] `; let line = `[${log.getHumanDate()}] `;
// message types from src/models/msg.js // message types from src/models/msg.js
switch (msg.type) { switch (msg.type) {

View File

@ -4,6 +4,7 @@ const expect = require("chai").expect;
const os = require("os"); const os = require("os");
const moment = require("moment"); const moment = require("moment");
const Helper = require("../../src/helper"); const Helper = require("../../src/helper");
const log = require("../../src/log");
describe("Helper", function() { describe("Helper", function() {
describe("#expandHome", function() { describe("#expandHome", function() {
@ -55,6 +56,6 @@ describe("Helper", function() {
}); });
describe("#getHumanDate()", 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"));
}); });
}); });