Files
Hermes-ui/packages/server/src/services/hermes/hermes-profile.ts
T

72 lines
1.8 KiB
TypeScript
Raw Normal View History

import { join } from 'path'
import { readFileSync, existsSync } from 'fs'
import { detectHermesRootHome } from './hermes-path'
export function getHermesBaseDir(): string {
return detectHermesRootHome()
}
/**
* Get the active profile's home directory.
* default → ~/.hermes/
* other → ~/.hermes/profiles/{name}/
*/
export function getActiveProfileDir(): string {
const hermesBase = getHermesBaseDir()
const activeFile = join(hermesBase, 'active_profile')
try {
const name = readFileSync(activeFile, 'utf-8').trim()
if (name && name !== 'default') {
const dir = join(hermesBase, 'profiles', name)
if (existsSync(dir)) return dir
}
} catch { }
return hermesBase
}
/**
* Get the active profile's config.yaml path.
*/
export function getActiveConfigPath(): string {
return join(getActiveProfileDir(), 'config.yaml')
}
/**
* Get the active profile's auth.json path.
*/
export function getActiveAuthPath(): string {
return join(getActiveProfileDir(), 'auth.json')
}
/**
* Get the active profile's .env path.
*/
export function getActiveEnvPath(): string {
return join(getActiveProfileDir(), '.env')
}
/**
* Get the active profile name.
*/
export function getActiveProfileName(): string {
const activeFile = join(getHermesBaseDir(), 'active_profile')
try {
const name = readFileSync(activeFile, 'utf-8').trim()
return name || 'default'
} catch {
return 'default'
}
}
/**
* Get profile directory by name.
* default → ~/.hermes/
* other → ~/.hermes/profiles/{name}/
*/
export function getProfileDir(name: string): string {
const hermesBase = getHermesBaseDir()
if (!name || name === 'default') return hermesBase
const dir = join(hermesBase, 'profiles', name)
return existsSync(dir) ? dir : hermesBase
}