/** * .env file parser shared between the SDK (syncEnv) and the CLI (--sync stdin). * * Kept as a standalone exported function (not a class method) so both the * SDK's ApplicationsResource and the CLI's stdin sync handler can use the * same implementation without coupling to either. * * @module */ /** * Parses .env-style content into a Map. * * Handles: * - Comments (lines starting with `#`) * - Empty lines (skipped) * - Quoted values (`"value"` or `'value'`) * - Values containing `=` (only the first `=` is the separator) * - Lines without `=` (skipped — invalid) * * @param content - File contents in KEY=VALUE format * @returns Map of key → value (empty string for `KEY=` with no value) */ export function parseEnvContent(content: string): Map { const envVars = new Map(); for (const line of content.split("\n")) { const trimmed = line.trim(); // Skip comments and empty lines. if (!trimmed || trimmed.startsWith("#")) continue; const eq = trimmed.indexOf("="); // Skip invalid lines (no `=`). if (eq === -1) continue; const key = trimmed.slice(0, eq).trim(); let value = trimmed.slice(eq + 1).trim(); // Strip matching surrounding quotes. if ( (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")) ) { value = value.slice(1, -1); } if (key) envVars.set(key, value); } return envVars; }