Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local config file in dev. Fix #903 #904

Merged
merged 8 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ node_modules

# logs
npm-debug.log

# optional dev config file and plugins directory
.hyper.js
.hyper_plugins

25 changes: 23 additions & 2 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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;
};
Expand Down
5 changes: 2 additions & 3 deletions app/plugins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const {exec} = require('child_process');
const {homedir} = require('os');
const {resolve, basename} = require('path');
const {writeFileSync} = require('fs');

Expand All @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const path = resolve(config.getConfigDir(), '.hyper_plugins')
const localPath = resolve(path, 'local')

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oups

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it was like this before, but when you're already at it 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes better :)

const localPath = resolve(path, 'local');
const availableExtensions = new Set([
'onApp', 'onWindow', 'onRendererWindow', 'onUnload', 'middleware',
'reduceUI', 'reduceSessions', 'reduceTermGroups',
Expand Down