hyper/app/config/paths.ts

97 lines
2.4 KiB
TypeScript
Raw Normal View History

// This module exports paths, names, and other metadata that is referenced
2019-11-28 05:17:01 -09:00
import {statSync} from 'fs';
2023-07-25 09:30:19 -08:00
import {homedir} from 'os';
2019-11-28 05:17:01 -09:00
import {resolve, join} from 'path';
2023-07-25 09:30:19 -08:00
import {app} from 'electron';
2019-11-28 05:17:01 -09:00
import isDev from 'electron-is-dev';
2022-12-25 20:01:04 -09:00
const cfgFile = 'hyper.json';
const defaultCfgFile = 'config-default.json';
const schemaFile = 'schema.json';
const homeDirectory = homedir();
2019-05-05 20:00:50 -08:00
// If the user defines XDG_CONFIG_HOME they definitely want their config there,
// otherwise use the home directory in linux/mac and userdata in windows
2022-12-25 20:01:04 -09:00
let cfgDir = process.env.XDG_CONFIG_HOME
? join(process.env.XDG_CONFIG_HOME, 'Hyper')
: process.platform === 'win32'
? app.getPath('userData')
: join(homeDirectory, '.config', 'Hyper');
const legacyCfgPath = join(
2019-05-05 20:00:50 -08:00
process.env.XDG_CONFIG_HOME !== undefined
? join(process.env.XDG_CONFIG_HOME, 'hyper')
: process.platform == 'win32'
? app.getPath('userData')
2022-12-25 20:01:04 -09:00
: homedir(),
'.hyper.js'
);
2022-12-25 20:01:04 -09:00
let cfgPath = join(cfgDir, cfgFile);
const schemaPath = resolve(__dirname, schemaFile);
const devDir = resolve(__dirname, '../..');
const devCfg = join(devDir, cfgFile);
const defaultCfg = resolve(__dirname, defaultCfgFile);
if (isDev) {
// if a local config file exists, use it
try {
statSync(devCfg);
cfgPath = devCfg;
cfgDir = devDir;
console.log('using config file:', cfgPath);
} catch (err) {
// ignore
}
}
2022-12-25 20:01:04 -09:00
const plugins = resolve(cfgDir, 'plugins');
const plugs = {
base: plugins,
local: resolve(plugins, 'local'),
cache: resolve(plugins, 'cache')
};
const yarn = resolve(__dirname, '../../bin/yarn-standalone.js');
const cliScriptPath = resolve(__dirname, '../../bin/hyper');
const cliLinkPath = '/usr/local/bin/hyper';
const icon = resolve(__dirname, '../static/icon96x96.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;
}
};
2019-11-28 05:17:01 -09:00
export {
cfgDir,
cfgPath,
legacyCfgPath,
cfgFile,
defaultCfg,
icon,
defaultPlatformKeyPath,
plugs,
yarn,
cliScriptPath,
cliLinkPath,
2022-12-25 20:01:04 -09:00
homeDirectory,
schemaFile,
schemaPath
};