import fs from 'fs/promises'; import path from 'path'; import { FileMapOptions, objectLoader } from "@azerothian/object-loader"; export async function exists(path: string): Promise { try { await fs.access(path, fs.constants.R_OK); return true; } catch (err) { return false; } } export async function readYAMLFile(path: string): Promise { try { return objectLoader(path, undefined, fileMapConfig); } catch (err) { console.error(err); } return null; } export async function readJSONFile(path: string): Promise { try { return objectLoader(path, undefined, fileMapConfig); } catch (err) { console.error(err); } return null; } export async function importFile( cwd: string, targetPath: string, ): Promise { const filePath = path.resolve(cwd, targetPath); return objectLoader(filePath, cwd, fileMapConfig); } const fileMapConfig: FileMapOptions = { fieldKey: "ref", customKeys: { "$env": (node) => { return process.env[node["$env"]] ?? ""; } } }