Skip to content

Commit 0c71863

Browse files
chabouppot
authored andcommitted
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
1 parent f139ca8 commit 0c71863

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ node_modules
66

77
# logs
88
npm-debug.log
9+
10+
# optional dev config file and plugins directory
11+
.hyper.js
12+
.hyper_plugins
13+

app/config.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {resolve} = require('path');
44
const vm = require('vm');
55

66
const {dialog} = require('electron');
7+
const isDev = require('electron-is-dev');
78
const gaze = require('gaze');
89
const Config = require('electron-config');
910
const notify = require('./notify');
@@ -16,8 +17,23 @@ const winCfg = new Config({
1617
}
1718
});
1819

19-
const path = resolve(homedir(), '.hyper.js');
20-
const pathLegacy = resolve(homedir(), '.hyperterm.js');
20+
let configDir = homedir();
21+
if (isDev) {
22+
// if a local config file exists, use it
23+
try {
24+
const devDir = resolve(__dirname, '..');
25+
const devConfig = resolve(devDir, '.hyper.js');
26+
statSync(devConfig);
27+
configDir = devDir;
28+
console.log('using config file:', devConfig);
29+
} catch (err) {
30+
// ignore
31+
}
32+
}
33+
34+
const path = resolve(configDir, '.hyper.js');
35+
const pathLegacy = resolve(configDir, '.hyperterm.js');
36+
2137
const watchers = [];
2238

2339
let cfg = {};
@@ -102,6 +118,11 @@ exports.init = function () {
102118
watch();
103119
};
104120

121+
exports.getConfigDir = function () {
122+
// expose config directory to load plugin from the right place
123+
return configDir;
124+
};
125+
105126
exports.getConfig = function () {
106127
return cfg.config;
107128
};

app/plugins.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const {exec} = require('child_process');
2-
const {homedir} = require('os');
32
const {resolve, basename} = require('path');
43
const {writeFileSync} = require('fs');
54

@@ -16,8 +15,8 @@ const notify = require('./notify');
1615
const cache = new Config();
1716

1817
// modules path
19-
const path = resolve(homedir(), '.hyper_plugins');
20-
const localPath = resolve(homedir(), '.hyper_plugins', 'local');
18+
const path = resolve(config.getConfigDir(), '.hyper_plugins');
19+
const localPath = resolve(path, 'local');
2120
const availableExtensions = new Set([
2221
'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware',
2322
'reduceUI', 'reduceSessions', 'reduceTermGroups',

0 commit comments

Comments
 (0)