UNPKG

@tsed/config

Version:
23 lines (22 loc) 639 B
import { existsSync, watch } from "node:fs"; import { logger } from "@tsed/di"; import JsYaml from "js-yaml"; export class YamlConfigSource { async getAll() { const { path, ...opts } = this.options; // Check if the file exists if (!existsSync(path)) { logger().warn(`Configuration file not found: ${path}`); return {}; } // Read the file return (await JsYaml.load(path, opts)); } watch(onChange) { const { path } = this.options; const watcher = watch(path, onChange); return () => { watcher.close(); }; } }