From dcec9f3c37b45bee6059c5ee3549c9e1c006e0ad Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 9 May 2016 19:19:16 +0300 Subject: [PATCH] Fix overriding home folder --- src/command-line/index.js | 5 ++--- src/helper.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/command-line/index.js b/src/command-line/index.js index ac8909d3..d81988bb 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -12,9 +12,8 @@ program.option(""); program.option(" --home " , "home path"); var argv = program.parseOptions(process.argv); -if (program.home) { - Helper.HOME = path.resolve(program.home); -} + +Helper.setHome(program.home); if (!fs.existsSync(Helper.CONFIG_PATH)) { mkdirp.sync(Helper.HOME, {mode: "0700"}); diff --git a/src/helper.js b/src/helper.js index d391c761..ac323d90 100644 --- a/src/helper.js +++ b/src/helper.js @@ -1,17 +1,21 @@ var path = require("path"); var os = require("os"); -var HOME = expandHome("~/.lounge"); - -module.exports = { - HOME: HOME, - CONFIG_PATH: path.join(HOME, "config.js"), - USERS_PATH: path.join(HOME, "users"), +var Helper = { expandHome: expandHome, getConfig: getConfig, getUserConfigPath: getUserConfigPath, + setHome: setHome, }; +module.exports = Helper; + +function setHome(homePath) { + this.HOME = expandHome(homePath || "~/.lounge"); + this.CONFIG_PATH = path.join(this.HOME, "config.js"); + this.USERS_PATH = path.join(this.HOME, "users"); +} + function getUserConfigPath(name) { return path.join(this.USERS_PATH, name + ".json"); }