Deprecate LOUNGE_HOME env var in favor of THELOUNGE_HOME, .lounge_home file in favor of .thelounge_home

This is one more step towards uniformization of lounge/thelounge due with The Lounge v3.
This commit is contained in:
Jérémie Astori 2017-11-19 13:21:37 -05:00
parent 489bb8e395
commit 827f1dab96
No known key found for this signature in database
GPG key ID: B9A4F245CD67BDE8
5 changed files with 34 additions and 14 deletions

View file

@ -2,9 +2,9 @@
# npm-debug.log and node_modules/ are ignored by default. # npm-debug.log and node_modules/ are ignored by default.
# See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package # See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package
# Ignore all dot files except for .lounge_home # Ignore all dot files except for .thelounge_home
.* .*
!.lounge_home !.thelounge_home
# Ignore client folder as it's being built into public/ folder # Ignore client folder as it's being built into public/ folder
# except for the specified files which are used by the server # except for the specified files which are used by the server

View file

@ -76,7 +76,7 @@ module.exports = {
// which in result fixes mixed content warnings. // which in result fixes mixed content warnings.
// //
// If storage is enabled, The Lounge will fetch and store images and thumbnails // If storage is enabled, The Lounge will fetch and store images and thumbnails
// in the `${LOUNGE_HOME}/storage` folder. // in the `${THELOUNGE_HOME}/storage` folder.
// //
// Images are deleted when they are no longer referenced by any message (controlled by maxHistory), // Images are deleted when they are no longer referenced by any message (controlled by maxHistory),
// and the folder is cleaned up on every The Lounge restart. // and the folder is cleaned up on every The Lounge restart.

View file

@ -15,13 +15,13 @@ if (require("semver").lt(process.version, "6.0.0")) {
} }
program.version(Helper.getVersion(), "-v, --version") program.version(Helper.getVersion(), "-v, --version")
.option("--home <path>", `${colors.bold("[DEPRECATED]")} Use the ${colors.green("LOUNGE_HOME")} environment variable instead.`) .option("--home <path>", `${colors.bold("[DEPRECATED]")} Use the ${colors.green("THELOUNGE_HOME")} environment variable instead.`)
.on("--help", Utils.extraHelp) .on("--help", Utils.extraHelp)
.parseOptions(process.argv); .parseOptions(process.argv);
if (program.home) { if (program.home) {
log.warn(`${colors.green("--home")} is ${colors.bold("deprecated")} and will be removed in The Lounge v3.`); log.warn(`${colors.green("--home")} is ${colors.bold("deprecated")} and will be removed in The Lounge v3.`);
log.warn(`Use the ${colors.green("LOUNGE_HOME")} environment variable instead.`); log.warn(`Use the ${colors.green("THELOUNGE_HOME")} environment variable instead.`);
} }
// Check if the app was built before calling setHome as it wants to load manifest.json from the public folder // Check if the app was built before calling setHome as it wants to load manifest.json from the public folder
@ -36,10 +36,15 @@ if (!fs.existsSync(path.join(
process.exit(1); process.exit(1);
} }
let home = program.home || process.env.LOUNGE_HOME; if (process.env.LOUNGE_HOME) {
log.warn(`${colors.green("LOUNGE_HOME")} is ${colors.bold("deprecated")} and will be removed in The Lounge v3.`);
log.warn(`Use ${colors.green("THELOUNGE_HOME")} instead.`);
}
let home = process.env.THELOUNGE_HOME || program.home || process.env.LOUNGE_HOME;
if (!home) { if (!home) {
home = Utils.defaultLoungeHome(); home = Utils.defaultHome();
} }
Helper.setHome(home); Helper.setHome(home);

View file

@ -4,7 +4,7 @@ const colors = require("colors/safe");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
let loungeHome; let home;
class Utils { class Utils {
static extraHelp() { static extraHelp() {
@ -13,25 +13,40 @@ class Utils {
"", "",
" Environment variable:", " Environment variable:",
"", "",
` LOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(Utils.defaultLoungeHome())}.`, ` THELOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(Utils.defaultHome())}.`,
"", "",
].forEach((e) => console.log(e)); // eslint-disable-line no-console ].forEach((e) => console.log(e)); // eslint-disable-line no-console
} }
static defaultLoungeHome() { static defaultHome() {
if (loungeHome) { if (home) {
return loungeHome; return home;
} }
const distConfig = path.resolve(path.join( const distConfig = path.resolve(path.join(
__dirname,
"..",
"..",
".thelounge_home"
));
// TODO: Remove this section when releasing The Lounge v3
const deprecatedDistConfig = path.resolve(path.join(
__dirname, __dirname,
"..", "..",
"..", "..",
".lounge_home" ".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(`Renaming to ${colors.green(".thelounge_home")} instead.`);
loungeHome = fs.readFileSync(distConfig, "utf-8").trim(); fs.renameSync(deprecatedDistConfig, distConfig);
}
return loungeHome; home = fs.readFileSync(distConfig, "utf-8").trim();
return home;
} }
} }