thelounge/src/command-line/utils.js
Jérémie Astori b90c224a99
Define a raw logger to avoid using console.log, use it in extra help for environment variables, and add a test for this
This has multiple benefits:

- Respects the "Do not mock what you do not own" principle, instead we mock `log.raw` when necessary
- Lets us not re-assign `console.log`, which breaks as Mocha uses `console.log` as well
- Save and restore initial `log.raw` in test hooks (before/after), otherwise this would break Mocha/Chai
2017-12-11 23:48:51 -05:00

57 lines
1.1 KiB
JavaScript

"use strict";
const colors = require("colors/safe");
const fs = require("fs");
const Helper = require("../helper");
const path = require("path");
let home;
class Utils {
static extraHelp() {
[
"",
"",
" Environment variable:",
"",
` THELOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(Helper.expandHome(Utils.defaultHome()))}.`,
"",
].forEach((e) => log.raw(e));
}
static defaultHome() {
if (home) {
return home;
}
let distConfig;
// TODO: Remove this section when releasing The Lounge v3
const deprecatedDistConfig = path.resolve(path.join(
__dirname,
"..",
"..",
".lounge_home"
));
if (fs.existsSync(deprecatedDistConfig)) {
log.warn(`${colors.green(".lounge_home")} is ${colors.bold("deprecated")} and will be ignored as of The Lounge v3.`);
log.warn(`Use ${colors.green(".thelounge_home")} instead.`);
distConfig = deprecatedDistConfig;
} else {
distConfig = path.resolve(path.join(
__dirname,
"..",
"..",
".thelounge_home"
));
}
home = fs.readFileSync(distConfig, "utf-8").trim();
return home;
}
}
module.exports = Utils;