Files
pulsenode/lib/config/interpolate.ts
T
valknar 80c2362ac2 feat: scaffold PulseNode dashboard (M1)
Next.js 16 + TypeScript + Tailwind v4 app with a YAML-driven config
system: schema validation (zod), .env interpolation, and a widget
registry rendering bookmark/search/group widgets. CSS custom
properties (--pn-*) drive theming and are overridable from
config.yml's theme.variables. Config load errors surface as a
readable error page instead of crashing the app.

Hot reload, docker/system/http collectors, and the WebSocket push
layer land in later milestones per the approved plan.
2026-08-17 13:49:55 +02:00

14 lines
518 B
TypeScript

const VAR_PATTERN = /\$\{([A-Za-z_][A-Za-z0-9_]*)(:-([^}]*))?\}/g;
export function interpolateEnv(
raw: string,
env: Record<string, string | undefined>
): string {
return raw.replace(VAR_PATTERN, (_match, name: string, hasDefault: string | undefined, fallback: string | undefined) => {
const value = env[name];
if (value !== undefined) return value;
if (hasDefault !== undefined) return fallback ?? "";
throw new Error(`Missing environment variable "${name}" referenced in config.yml`);
});
}