thelounge/src/helper.js

47 lines
932 B
JavaScript
Raw Normal View History

2014-10-05 01:22:23 +02:00
var path = require("path");
var os = require("os");
2014-10-05 01:22:23 +02:00
2016-05-09 18:19:16 +02:00
var Helper = {
expandHome: expandHome,
getConfig: getConfig,
getUserConfigPath: getUserConfigPath,
2016-05-15 23:13:51 +02:00
getUserLogsPath: getUserLogsPath,
2016-05-09 18:19:16 +02:00
setHome: setHome,
};
2016-05-09 18:19:16 +02:00
module.exports = Helper;
function setHome(homePath) {
this.HOME = expandHome(homePath || "~/.lounge");
this.CONFIG_PATH = path.join(this.HOME, "config.js");
this.USERS_PATH = path.join(this.HOME, "users");
}
function getUserConfigPath(name) {
return path.join(this.USERS_PATH, name + ".json");
}
2016-05-15 23:13:51 +02:00
function getUserLogsPath(name, network) {
return path.join(this.HOME, "logs", name, network);
}
2014-10-04 01:33:44 +02:00
function getConfig() {
return require(this.CONFIG_PATH);
2015-10-01 00:39:57 +02:00
}
function expandHome(shortenedPath) {
var home;
if (os.homedir) {
home = os.homedir();
}
if (!home) {
home = process.env.HOME || "";
}
home = home.replace("$", "$$$$");
return path.resolve(shortenedPath.replace(/^~($|\/|\\)/, home + "$1"));
}