2017-08-21 05:49:32 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const colors = require("colors/safe");
|
2017-08-21 06:03:40 +00:00
|
|
|
const fs = require("fs");
|
2017-12-08 04:00:27 +00:00
|
|
|
const Helper = require("../helper");
|
2017-08-21 06:03:40 +00:00
|
|
|
const path = require("path");
|
|
|
|
|
2017-11-19 18:21:37 +00:00
|
|
|
let home;
|
2017-08-21 05:49:32 +00:00
|
|
|
|
|
|
|
class Utils {
|
|
|
|
static extraHelp() {
|
|
|
|
[
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
" Environment variable:",
|
|
|
|
"",
|
2017-12-08 04:00:27 +00:00
|
|
|
` THELOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(Helper.expandHome(Utils.defaultHome()))}.`,
|
2017-08-21 05:49:32 +00:00
|
|
|
"",
|
2017-12-09 07:11:05 +00:00
|
|
|
].forEach((e) => log.raw(e));
|
2017-08-21 05:49:32 +00:00
|
|
|
}
|
2017-08-21 06:03:40 +00:00
|
|
|
|
2017-11-19 18:21:37 +00:00
|
|
|
static defaultHome() {
|
|
|
|
if (home) {
|
|
|
|
return home;
|
2017-08-21 06:03:40 +00:00
|
|
|
}
|
2017-11-19 18:21:37 +00:00
|
|
|
|
2017-12-01 06:33:04 +00:00
|
|
|
let distConfig;
|
2017-11-19 18:21:37 +00:00
|
|
|
|
|
|
|
// TODO: Remove this section when releasing The Lounge v3
|
|
|
|
const deprecatedDistConfig = path.resolve(path.join(
|
2017-08-21 06:03:40 +00:00
|
|
|
__dirname,
|
|
|
|
"..",
|
|
|
|
"..",
|
|
|
|
".lounge_home"
|
|
|
|
));
|
2017-11-19 18:21:37 +00:00
|
|
|
if (fs.existsSync(deprecatedDistConfig)) {
|
|
|
|
log.warn(`${colors.green(".lounge_home")} is ${colors.bold("deprecated")} and will be ignored as of The Lounge v3.`);
|
2017-12-01 06:33:04 +00:00
|
|
|
log.warn(`Use ${colors.green(".thelounge_home")} instead.`);
|
|
|
|
|
|
|
|
distConfig = deprecatedDistConfig;
|
|
|
|
} else {
|
|
|
|
distConfig = path.resolve(path.join(
|
|
|
|
__dirname,
|
|
|
|
"..",
|
|
|
|
"..",
|
|
|
|
".thelounge_home"
|
|
|
|
));
|
2017-11-19 18:21:37 +00:00
|
|
|
}
|
2017-08-21 06:03:40 +00:00
|
|
|
|
2017-11-19 18:21:37 +00:00
|
|
|
home = fs.readFileSync(distConfig, "utf-8").trim();
|
2017-08-21 06:03:40 +00:00
|
|
|
|
2017-11-19 18:21:37 +00:00
|
|
|
return home;
|
2017-08-21 06:03:40 +00:00
|
|
|
}
|
2017-08-21 05:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Utils;
|