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