thelounge/src/helper.js

31 lines
803 B
JavaScript
Raw Normal View History

var fs = require("fs");
var path = require("path");
var Helper = module.exports = {
2014-09-13 19:10:32 +02:00
getConfig: function () {
var filename = process.env.SHOUT_CONFIG;
if(!filename || !fs.existsSync(filename)) {
filename = this.resolveHomePath("config.js");
if(!fs.existsSync(filename)) {
filename = path.resolve(__dirname, "..", "config");
}
}
return require(filename);
2014-09-13 19:10:32 +02:00
},
2014-09-13 19:10:32 +02:00
getHomeDirectory: function () {
return (
(process.env.SHOUT_CONFIG && fs.existsSync(process.env.SHOUT_CONFIG) && this.getConfig().home)
2014-09-13 19:10:32 +02:00
|| process.env.SHOUT_HOME
|| path.resolve(process.env.HOME, ".shout")
);
},
2014-09-13 19:10:32 +02:00
resolveHomePath: function () {
var fragments = [ Helper.HOME ].concat([].slice.apply(arguments));
return path.resolve.apply(path, fragments);
}
};
Helper.HOME = Helper.getHomeDirectory()