2014-10-04 23:22:23 +00:00
|
|
|
var path = require("path");
|
2016-04-27 08:13:25 +00:00
|
|
|
var os = require("os");
|
2014-10-04 23:22:23 +00:00
|
|
|
|
2016-05-08 06:21:31 +00:00
|
|
|
var HOME = expandHome("~/.lounge");
|
|
|
|
|
2014-10-03 23:33:44 +00:00
|
|
|
module.exports = {
|
2016-05-08 06:21:31 +00:00
|
|
|
HOME: HOME,
|
|
|
|
CONFIG_PATH: path.join(HOME, "config.js"),
|
|
|
|
USERS_PATH: path.join(HOME, "users"),
|
2016-04-27 08:13:25 +00:00
|
|
|
expandHome: expandHome,
|
2016-05-08 06:21:31 +00:00
|
|
|
getConfig: getConfig,
|
|
|
|
getUserConfigPath: getUserConfigPath,
|
2014-09-13 12:23:17 +00:00
|
|
|
};
|
|
|
|
|
2016-05-08 06:21:31 +00:00
|
|
|
function getUserConfigPath(name) {
|
|
|
|
return path.join(this.USERS_PATH, name + ".json");
|
|
|
|
}
|
|
|
|
|
2014-10-03 23:33:44 +00:00
|
|
|
function getConfig() {
|
2016-05-08 06:21:31 +00:00
|
|
|
return require(this.CONFIG_PATH);
|
2015-09-30 22:39:57 +00:00
|
|
|
}
|
2016-04-27 08:13:25 +00:00
|
|
|
|
2016-05-08 06:21:31 +00:00
|
|
|
function expandHome(shortenedPath) {
|
2016-04-27 08:13:25 +00:00
|
|
|
var home;
|
|
|
|
|
|
|
|
if (os.homedir) {
|
|
|
|
home = os.homedir();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!home) {
|
|
|
|
home = process.env.HOME || "";
|
|
|
|
}
|
|
|
|
|
|
|
|
home = home.replace("$", "$$$$");
|
|
|
|
|
2016-05-08 06:21:31 +00:00
|
|
|
return path.resolve(shortenedPath.replace(/^~($|\/|\\)/, home + "$1"));
|
2016-04-27 08:13:25 +00:00
|
|
|
}
|