From 0c71863560e0fdb15848c27f74dc9ad41c5f4ec0 Mon Sep 17 00:00:00 2001 From: chabou Date: Thu, 5 Jan 2017 02:05:19 +0100 Subject: [PATCH] Use local config file in dev. Fix #903 (#904) * Use local config file in dev * Fix typo * Reuse path variable to compose localPath * Fix lint errors --- .gitignore | 5 +++++ app/config.js | 25 +++++++++++++++++++++++-- app/plugins.js | 5 ++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2e693124..fa4e7c02 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,8 @@ node_modules # logs npm-debug.log + +# optional dev config file and plugins directory +.hyper.js +.hyper_plugins + diff --git a/app/config.js b/app/config.js index 5f79ea00..d42d50f5 100644 --- a/app/config.js +++ b/app/config.js @@ -4,6 +4,7 @@ const {resolve} = require('path'); const vm = require('vm'); const {dialog} = require('electron'); +const isDev = require('electron-is-dev'); const gaze = require('gaze'); const Config = require('electron-config'); const notify = require('./notify'); @@ -16,8 +17,23 @@ const winCfg = new Config({ } }); -const path = resolve(homedir(), '.hyper.js'); -const pathLegacy = resolve(homedir(), '.hyperterm.js'); +let configDir = homedir(); +if (isDev) { + // if a local config file exists, use it + try { + const devDir = resolve(__dirname, '..'); + const devConfig = resolve(devDir, '.hyper.js'); + statSync(devConfig); + configDir = devDir; + console.log('using config file:', devConfig); + } catch (err) { + // ignore + } +} + +const path = resolve(configDir, '.hyper.js'); +const pathLegacy = resolve(configDir, '.hyperterm.js'); + const watchers = []; let cfg = {}; @@ -102,6 +118,11 @@ exports.init = function () { watch(); }; +exports.getConfigDir = function () { + // expose config directory to load plugin from the right place + return configDir; +}; + exports.getConfig = function () { return cfg.config; }; diff --git a/app/plugins.js b/app/plugins.js index b74d3cde..ef11dc6f 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -1,5 +1,4 @@ const {exec} = require('child_process'); -const {homedir} = require('os'); const {resolve, basename} = require('path'); const {writeFileSync} = require('fs'); @@ -16,8 +15,8 @@ const notify = require('./notify'); const cache = new Config(); // modules path -const path = resolve(homedir(), '.hyper_plugins'); -const localPath = resolve(homedir(), '.hyper_plugins', 'local'); +const path = resolve(config.getConfigDir(), '.hyper_plugins'); +const localPath = resolve(path, 'local'); const availableExtensions = new Set([ 'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware', 'reduceUI', 'reduceSessions', 'reduceTermGroups',