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<string> { - 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 }); }