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
This commit is contained in:
chabou 2017-01-05 02:05:19 +01:00 committed by Philippe Potvin
parent f139ca80a5
commit 0c71863560
3 changed files with 30 additions and 5 deletions

5
.gitignore vendored
View file

@ -6,3 +6,8 @@ node_modules
# logs
npm-debug.log
# optional dev config file and plugins directory
.hyper.js
.hyper_plugins

View file

@ -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;
};

View file

@ -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',