31 lines
1 KiB
TypeScript
31 lines
1 KiB
TypeScript
import { exists } from "jsr:@std/fs";
|
|
|
|
/**
|
|
* Return the path to Eve's configuration directory.
|
|
*
|
|
* 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.
|
|
*
|
|
* If the resolved path does not exist, create it.
|
|
*/
|
|
export async function getEveConfigHome(): Promise<string> {
|
|
const xdgConfigHome = Deno.env.get("XDG_CONFIG_HOME") ??
|
|
`${Deno.env.get("HOME")}/.config`;
|
|
const storagePath = `${xdgConfigHome}/arx/Eve`;
|
|
if (!(await exists(storagePath))) {
|
|
await Deno.mkdir(storagePath, { recursive: true });
|
|
}
|
|
return storagePath;
|
|
}
|
|
|
|
/**
|
|
* Return the path to the file in Eve's configuration directory.
|
|
*
|
|
* @param file The name of the file to return the path for.
|
|
* @returns The path to the file in Eve's configuration directory.
|
|
*/
|
|
export async function getEveFilePath(file: string): Promise<string> {
|
|
const storagePath = await getEveConfigHome();
|
|
return `${storagePath}/${file}`;
|
|
}
|