Skip to content

Commit

Permalink
const renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ppot committed May 28, 2017
1 parent 68f00ed commit 49a1585
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions app/config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const gaze = require('gaze');
const notify = require('./notify');
const _import = require('./config/import');
const {confPath, confDir} = require('./config/paths');
const _openConfig = require('./config/open');
const win = require('./config/windows');
const {cfgPath, cfgDir} = require('./config/paths');

const watchers = [];
// watch for changes on config every 2s on windows
// https://github.com/zeit/hyper/pull/1772
const watchConfig = process.platform === 'win32' ? {interval: 2000} : {};
const watchCfg = process.platform === 'win32' ? {interval: 2000} : {};
let cfg = {};

const _watch = function () {
gaze(confPath, watchConfig, function (err) {
gaze(cfgPath, watchCfg, function (err) {
if (err) {
throw err;
}
Expand All @@ -36,7 +36,7 @@ exports.subscribe = function (fn) {

exports.getConfigDir = function () {
// expose config directory to load plugin from the right place
return confDir;
return cfgDir;
};

exports.getConfig = function () {
Expand Down
12 changes: 6 additions & 6 deletions app/config/import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {writeFileSync, readFileSync} = require('fs');
const {defaultConfig, confPath} = require('./paths');
const {defaultCfg, cfgPath} = require('./paths');
const _init = require('./init');
const _keymaps = require('./keymaps');

Expand All @@ -16,13 +16,13 @@ const _write = function (path, data) {

const _importConf = function () {
try {
const defaultConf = readFileSync(defaultConfig, 'utf8');
const _defaultCfg = readFileSync(defaultCfg, 'utf8');
try {
const conf = readFileSync(confPath, 'utf8');
return {userConf: conf, defaultConf};
const _cfgPath = readFileSync(cfgPath, 'utf8');
return {userCfg: _cfgPath, defaultCfg: _defaultCfg};
} catch (err) {
_write(confPath, defaultConf);
return {userConf: {}, defaultConf};
_write(cfgPath, defaultCfg);
return {userCfg: {}, defaultCfg: _defaultCfg};
}
} catch (err) {
console.log(err);
Expand Down
6 changes: 3 additions & 3 deletions app/config/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ const _extractDefault = function (cfg) {

// init config
const _init = function (cfg) {
const script = _syntaxValidation(cfg.userConf);
const script = _syntaxValidation(cfg.userCfg);
if (script) {
const _cfg = _extract(script);
if (!_cfg.config) {
_cfg.plugins = _cfg.plugins || [];
_cfg.localPlugins = _cfg.localPlugins || [];
_cfg.keymaps = _cfg.keymaps || {};
notify('Error reading configuration: `config` key is missing');
return _extractDefault(cfg.defaultConf);
return _extractDefault(cfg.defaultCfg);
}
return _cfg;
}
return _extractDefault(cfg.defaultConf);
return _extractDefault(cfg.defaultCfg);
};

module.exports = _init;
8 changes: 4 additions & 4 deletions app/config/open.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {shell} = require('electron');
const {confPath} = require('./paths');
const {cfgPath} = require('./paths');

module.exports = () => Promise.resolve(shell.openItem(confPath));
module.exports = () => Promise.resolve(shell.openItem(cfgPath));

if (process.platform === 'win32') {
const exec = require('child_process').exec;
Expand All @@ -28,6 +28,6 @@ if (process.platform === 'win32') {
});

module.exports = () => canOpenNative()
.then(() => shell.openItem(confPath))
.catch(() => openNotepad(confPath));
.then(() => shell.openItem(cfgPath))
.catch(() => openNotepad(cfgPath));
}
22 changes: 11 additions & 11 deletions app/config/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const {statSync} = require('fs');
const {resolve, join} = require('path');
const isDev = require('electron-is-dev');

const conf = '.hyper.js';
const defaultConf = 'config-default.js';
const cfgFile = '.hyper.js';
const defaultCfgFile = 'config-default.js';
const homeDir = homedir();

let confPath = join(homeDir, conf);
let confDir = homeDir;
let cfgPath = join(homeDir, cfgFile);
let cfgDir = homeDir;

const devDir = resolve(__dirname, '../..');
const devConfig = join(devDir, conf);
const defaultConfig = resolve(__dirname, defaultConf);
const devCfg = join(devDir, cfgFile);
const defaultCfg = resolve(__dirname, defaultCfgFile);

const icon = resolve(__dirname, '../static/icon.png');

Expand All @@ -34,15 +34,15 @@ const defaultPlatformKeyPath = () => {
if (isDev) {
// if a local config file exists, use it
try {
statSync(devConfig);
confPath = devConfig;
confDir = devDir;
console.log('using config file:', confPath);
statSync(devCfg);
cfgPath = devCfg;
cfgDir = devDir;
console.log('using config file:', cfgPath);
} catch (err) {
// ignore
}
}

module.exports = {
confDir, confPath, conf, defaultConfig, icon, defaultPlatformKeyPath
cfgDir, cfgPath, cfgFile, defaultCfg, icon, defaultPlatformKeyPath
};

0 comments on commit 49a1585

Please sign in to comment.