final feature set
This commit is contained in:
44
src/utils/config-dir.ts
Normal file
44
src/utils/config-dir.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* XDG_CONFIG_HOME directory setup for PodTUI
|
||||
*
|
||||
* Handles config directory detection and creation following the XDG Base
|
||||
* Directory Specification. Falls back to ~/.config when XDG_CONFIG_HOME
|
||||
* is not set.
|
||||
*/
|
||||
|
||||
import { mkdir } from "fs/promises"
|
||||
import path from "path"
|
||||
|
||||
/** Application config directory name */
|
||||
const APP_DIR_NAME = "podtui"
|
||||
|
||||
/** Resolve the XDG_CONFIG_HOME directory, defaulting to ~/.config */
|
||||
export function getXdgConfigHome(): string {
|
||||
const xdg = process.env.XDG_CONFIG_HOME
|
||||
if (xdg) return xdg
|
||||
|
||||
const home = process.env.HOME ?? process.env.USERPROFILE ?? ""
|
||||
if (!home) throw new Error("Cannot determine home directory")
|
||||
|
||||
return path.join(home, ".config")
|
||||
}
|
||||
|
||||
/** Get the application-specific config directory path */
|
||||
export function getConfigDir(): string {
|
||||
return path.join(getXdgConfigHome(), APP_DIR_NAME)
|
||||
}
|
||||
|
||||
/** Get the path for a specific config file */
|
||||
export function getConfigFilePath(filename: string): string {
|
||||
return path.join(getConfigDir(), filename)
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the application config directory exists.
|
||||
* Creates it recursively if needed.
|
||||
*/
|
||||
export async function ensureConfigDir(): Promise<string> {
|
||||
const dir = getConfigDir()
|
||||
await mkdir(dir, { recursive: true })
|
||||
return dir
|
||||
}
|
||||
Reference in New Issue
Block a user