From ac3ce74343b4af4cd4be75affe716632e2816e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 21 Aug 2017 02:03:40 -0400 Subject: [PATCH] Read default LOUNGE_HOME from .lounge_home file --- src/command-line/index.js | 9 +-------- src/command-line/utils.js | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/command-line/index.js b/src/command-line/index.js index 48825be1..01cfc619 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -23,14 +23,7 @@ if (program.home) { let home = program.home || process.env.LOUNGE_HOME; if (!home) { - const distConfig = path.resolve(path.join( - __dirname, - "..", - "..", - ".lounge_home" - )); - - home = fs.readFileSync(distConfig, "utf-8").trim(); + home = Utils.defaultLoungeHome(); } Helper.setHome(home); diff --git a/src/command-line/utils.js b/src/command-line/utils.js index 1b2cd454..8f5676af 100644 --- a/src/command-line/utils.js +++ b/src/command-line/utils.js @@ -1,6 +1,10 @@ "use strict"; const colors = require("colors/safe"); +const fs = require("fs"); +const path = require("path"); + +let loungeHome; class Utils { static extraHelp() { @@ -9,10 +13,26 @@ class Utils { "", " Environment variable:", "", - ` LOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green("~/.lounge")}.`, + ` LOUNGE_HOME Path for all configuration files and folders. Defaults to ${colors.green(Utils.defaultLoungeHome())}.`, "", ].forEach((e) => console.log(e)); } + + static defaultLoungeHome() { + if (loungeHome) { + return loungeHome; + } + const distConfig = path.resolve(path.join( + __dirname, + "..", + "..", + ".lounge_home" + )); + + loungeHome = fs.readFileSync(distConfig, "utf-8").trim(); + + return loungeHome; + } } module.exports = Utils;