hyper/app/config/paths.js

69 lines
1.6 KiB
JavaScript
Raw Normal View History

// This module exports paths, names, and other metadata that is referenced
const {homedir} = require('os');
const {statSync} = require('fs');
const {resolve, join} = require('path');
const isDev = require('electron-is-dev');
const cfgFile = '.hyper.js';
const defaultCfgFile = 'config-default.js';
const homeDir = homedir();
let cfgPath = join(homeDir, cfgFile);
let cfgDir = homeDir;
const devDir = resolve(__dirname, '../..');
const devCfg = join(devDir, cfgFile);
const defaultCfg = resolve(__dirname, defaultCfgFile);
const plugins = resolve(cfgDir, '.hyper_plugins');
const plugs = {
base: plugins,
local: resolve(plugins, 'local'),
cache: resolve(plugins, 'cache')
};
const yarn = resolve(__dirname, '../../bin/yarn-standalone.js');
2017-05-26 06:09:39 -08:00
const icon = resolve(__dirname, '../static/icon.png');
const keymapPath = resolve(__dirname, '../keymaps');
const darwinKeys = join(keymapPath, 'darwin.json');
const win32Keys = join(keymapPath, 'win32.json');
const linuxKeys = join(keymapPath, 'linux.json');
const defaultPlatformKeyPath = () => {
switch (process.platform) {
case 'darwin':
return darwinKeys;
case 'win32':
return win32Keys;
case 'linux':
return linuxKeys;
default:
return darwinKeys;
}
};
if (isDev) {
// if a local config file exists, use it
try {
statSync(devCfg);
cfgPath = devCfg;
cfgDir = devDir;
//eslint-disable-next-line no-console
console.log('using config file:', cfgPath);
} catch (err) {
// ignore
}
}
module.exports = {
cfgDir,
cfgPath,
cfgFile,
defaultCfg,
icon,
defaultPlatformKeyPath,
plugs,
yarn
};