UNPKG

gaunt-sloth-assistant

Version:

[![Tests and Lint](https://github.com/Galvanized-Pukeko/gaunt-sloth-assistant/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/Galvanized-Pukeko/gaunt-sloth-assistant/actions/workflows/unit-tests.yml) [![Integration Tests](https://github.co

61 lines 2.04 kB
import { existsSync, mkdirSync } from 'node:fs'; import { resolve } from 'node:path'; import { homedir } from 'node:os'; import { GSLOTH_DIR, GSLOTH_AUTH } from '#src/constants.js'; /** * Gets the global .gsloth directory path in the user's home directory * @returns The resolved path to the global .gsloth directory */ export function getGlobalGslothDir() { return resolve(homedir(), GSLOTH_DIR); } /** * Ensures the global .gsloth directory exists in the user's home directory * Creates it if it doesn't exist * @returns The resolved path to the global .gsloth directory */ export function ensureGlobalGslothDir() { const globalDir = getGlobalGslothDir(); if (!existsSync(globalDir)) { mkdirSync(globalDir, { recursive: true }); } return globalDir; } /** * Gets the global auth directory path * @returns The resolved path to the global auth directory */ export function getGlobalAuthDir() { const globalDir = getGlobalGslothDir(); return resolve(globalDir, GSLOTH_AUTH); } /** * Ensures the global auth directory exists * Creates it if it doesn't exist * @returns The resolved path to the global auth directory */ export function ensureGlobalAuthDir() { // First ensure parent directory exists ensureGlobalGslothDir(); const authDir = getGlobalAuthDir(); if (!existsSync(authDir)) { mkdirSync(authDir, { recursive: true }); } return authDir; } /** * Gets the path for a specific OAuth provider's storage file * @param serverUrl The server URL or identifier for the OAuth provider * @returns The resolved path where the OAuth data should be stored */ export function getOAuthStoragePath(serverUrl) { const authDir = ensureGlobalAuthDir(); // Create a safe filename from the server URL const safeFilename = serverUrl .replace(/https?:\/\//, '') .replace(/[^a-zA-Z0-9.-]/g, '_') .replace(/_+/g, '_') .toLowerCase(); return resolve(authDir, `${safeFilename}.json`); } //# sourceMappingURL=globalConfigUtils.js.map