import { cosmiconfig } from 'cosmiconfig' import { IConfigUtilOptions, ICosmicResult } from '../interfaces/index.js' /** * A utility class for interacting with the cosmiconfig library. The generic * type T is the type of the config object that is returned. * * @example * import { CosmicUtil } from '@4lch4/lt-commander' * * interface MyConfig { * alpha: string * beta: number * charlie: boolean * } * * const cosmicUtil = CosmicUtil.init() */ export class CosmicUtil { constructor(protected options: IConfigUtilOptions) {} async load(searchFrom?: string): Promise> { const res = await cosmiconfig(this.options.appName).search(searchFrom) return { config: res?.config as T, filepath: res?.filepath, isEmpty: res?.isEmpty } } }