handle macos more gracefully
This commit is contained in:
parent
1f95a4f0c8
commit
9bef51a027
1 changed files with 18 additions and 8 deletions
|
@ -1,18 +1,28 @@
|
||||||
import { exists } from "jsr:@std/fs";
|
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:
|
* On macOS, the directory is located at "$HOME/Library/Application Support/eve/arx/Eve".
|
||||||
* 1. The value of the `XDG_CONFIG_HOME` environment variable.
|
* On other systems, it defaults to "$XDG_CONFIG_HOME/arx/Eve" or
|
||||||
* 2. The value of the `HOME` environment variable, with `.config` appended.
|
* "$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> {
|
export async function getEveConfigHome(): Promise<string> {
|
||||||
const xdgConfigHome = Deno.env.get("XDG_CONFIG_HOME") ??
|
let storagePath: string;
|
||||||
`${Deno.env.get("HOME")}/.config`;
|
if (Deno.build.os === "darwin") {
|
||||||
const storagePath = `${xdgConfigHome}/arx/Eve`;
|
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))) {
|
if (!(await exists(storagePath))) {
|
||||||
await Deno.mkdir(storagePath, { recursive: true });
|
await Deno.mkdir(storagePath, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue