From 9bef51a0272d7c1e6c5234b30ef09383a3f3aae6 Mon Sep 17 00:00:00 2001 From: Danny Morabito Date: Mon, 24 Feb 2025 23:00:23 +0100 Subject: [PATCH] handle macos more gracefully --- utils/files.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/utils/files.ts b/utils/files.ts index 858a0d5..a51b6f5 100644 --- a/utils/files.ts +++ b/utils/files.ts @@ -1,18 +1,28 @@ import { exists } from "jsr:@std/fs"; /** - * Return the path to Eve's configuration directory. + * Return the path to Eve's configuration directory and ensures its existence. * - * The configuration directory is resolved in the following order: - * 1. The value of the `XDG_CONFIG_HOME` environment variable. - * 2. The value of the `HOME` environment variable, with `.config` appended. + * On macOS, the directory is located at "$HOME/Library/Application Support/eve/arx/Eve". + * On other systems, it defaults to "$XDG_CONFIG_HOME/arx/Eve" or + * "$HOME/.config/arx/Eve" if XDG_CONFIG_HOME is not set. * - * If the resolved path does not exist, create it. + * If the directory does not exist, it is created automatically. + * + * @returns A promise that resolves to the path of the configuration directory. */ + export async function getEveConfigHome(): Promise { - const xdgConfigHome = Deno.env.get("XDG_CONFIG_HOME") ?? - `${Deno.env.get("HOME")}/.config`; - const storagePath = `${xdgConfigHome}/arx/Eve`; + let storagePath: string; + if (Deno.build.os === "darwin") { + storagePath = `${ + Deno.env.get("HOME") + }/Library/Application Support/eve/arx/Eve`; + } else { + const xdgConfigHome = Deno.env.get("XDG_CONFIG_HOME") ?? + `${Deno.env.get("HOME")}/.config`; + storagePath = `${xdgConfigHome}/arx/Eve`; + } if (!(await exists(storagePath))) { await Deno.mkdir(storagePath, { recursive: true }); }