CONFIG_FILE => CONFIG_PATH

d97aa0a270c1282490bfc2b8bf10add67969d1c8

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +6 -6Ignore whitespace
src/util.js+6 -6
@@ -23,7 +23,7 @@ import { serverDirectory } from './server-directory.js';
23 * Parsed config object.23 * Parsed config object.
24 */24 */
25let CACHED_CONFIG = null;25let CACHED_CONFIG = null;
26let CONFIG_FILE = null;26let CONFIG_PATH = null;
2727
28/**28/**
29 * Converts a configuration key to an environment variable key.29 * Converts a configuration key to an environment variable key.
@@ -38,10 +38,10 @@ export const keyToEnv = (key) => 'SILLYTAVERN_' + String(key).toUpperCase().repl
38 * @param {string} configFilePath Path to the config file38 * @param {string} configFilePath Path to the config file
39 */39 */
40export function setConfigFilePath(configFilePath) {40export function setConfigFilePath(configFilePath) {
41 if (CONFIG_FILE !== null) {41 if (CONFIG_PATH !== null) {
42 console.error(color.red('Config file path already set. Please restart the server to change the config file path.'));42 console.error(color.red('Config file path already set. Please restart the server to change the config file path.'));
43 }43 }
44 CONFIG_FILE = path.resolve(configFilePath);44 CONFIG_PATH = path.resolve(configFilePath);
45}45}
4646
47/**47/**
@@ -49,7 +49,7 @@ export function setConfigFilePath(configFilePath) {
49 * @returns {object} Config object49 * @returns {object} Config object
50 */50 */
51export function getConfig() {51export function getConfig() {
52 if (CONFIG_FILE === null) {52 if (CONFIG_PATH === null) {
53 console.trace();53 console.trace();
54 console.error(color.red('No config file path set. Please set the config file path using setConfigFilePath().'));54 console.error(color.red('No config file path set. Please set the config file path using setConfigFilePath().'));
55 process.exit(1);55 process.exit(1);
@@ -57,14 +57,14 @@ export function getConfig() {
57 if (CACHED_CONFIG) {57 if (CACHED_CONFIG) {
58 return CACHED_CONFIG;58 return CACHED_CONFIG;
59 }59 }
60 if (!fs.existsSync(CONFIG_FILE)) {60 if (!fs.existsSync(CONFIG_PATH)) {
61 console.error(color.red('No config file found. Please create a config.yaml file. The default config file can be found in the /default folder.'));61 console.error(color.red('No config file found. Please create a config.yaml file. The default config file can be found in the /default folder.'));
62 console.error(color.red('The program will now exit.'));62 console.error(color.red('The program will now exit.'));
63 process.exit(1);63 process.exit(1);
64 }64 }
6565
66 try {66 try {
67 const config = yaml.parse(fs.readFileSync(CONFIG_FILE, 'utf8'));67 const config = yaml.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
68 CACHED_CONFIG = config;68 CACHED_CONFIG = config;
69 return config;69 return config;
70 } catch (error) {70 } catch (error) {