UNPKG

@yuxilabs/gptp-core

Version:

Core validation, formatting and execution logic for the GPTP file format.

34 lines (33 loc) 930 B
// src/engine/profile/index.ts import path from 'path'; import * as fs from 'fs/promises'; import { loadEnvVars } from '@/utils/env'; /** * Loads a .gptp profile by name from `.gptp/profiles/{name}.json`. * Loads environment variables into process.env if defined. */ export async function loadProfile(name = 'default') { const profilePath = path.resolve('.gptp', 'profiles', `${name}.json`); let raw; try { raw = await fs.readFile(profilePath, 'utf-8'); } catch (err) { throw new Error(`Unable to load profile "${name}": ${err.message}`); } let parsed; try { parsed = JSON.parse(raw); } catch (err) { throw new Error(`Profile "${name}" contains invalid JSON`); } const profile = parsed; if (profile.env) { loadEnvVars(profile.env); } return { ...profile, name, // Ensure the passed-in name always wins }; }