UNPKG

@builder.io/dev-tools

Version:

Builder.io Visual CMS Devtools

90 lines (89 loc) 2.81 kB
/** * Options for capturing environment variables from a setup command */ export interface EnvCaptureOptions { /** The command to wrap with env capture */ command: string; } /** * Result of environment capture */ export interface EnvCaptureResult { /** The modified command that includes env capture */ command: string; /** Path to the temporary file where env will be captured */ envFilePath: string; /** * Function to get the captured environment variables. * This will read, parse, and cleanup the env file in one call. * Returns undefined if the env file couldn't be read. */ getCapturedEnv: () => Promise<Record<string, string> | undefined>; } /** * Wraps a command with environment variable capture at the end. * The environment is captured to a temporary file that can be parsed later. * * @param options - Configuration for env capture * @returns The modified command and a function to retrieve the captured env * * @example * ```typescript * const { command, getCapturedEnv } = wrapCommandWithEnvCapture({ * command: 'npm install', * }); * * // Execute command... * // Later, get the captured environment (reads, parses, and cleans up automatically): * const env = await getCapturedEnv(); * ``` */ export declare function wrapCommandWithEnvCapture(options: EnvCaptureOptions): EnvCaptureResult; /** * Parses an environment file into a key-value object. * Handles multi-line values and empty lines. * * @param filePath - Path to the environment file * @returns A promise that resolves to the parsed environment variables * * @example * ```typescript * const env = await parseEnvFile('/tmp/env.txt'); * console.log(env.PATH); // "/usr/bin:/bin" * ``` */ export declare function parseEnvFile(filePath: string): Promise<Record<string, string>>; /** * Parses environment variable content into a key-value object. * This is the core parsing logic extracted for easier testing. * * Environment format is: KEY=VALUE * Each line represents one variable. * * @param content - The raw content from an env file * @returns The parsed environment variables * * @example * ```typescript * const env = parseEnvContent('PATH=/usr/bin\nHOME=/home/user'); * // { PATH: '/usr/bin', HOME: '/home/user' } * ``` */ export declare function parseEnvContent(content: string): Record<string, string>; /** * Cleans up the environment capture file. * Call this after parsing to remove temporary files. * * @param filePath - Path to the environment file to clean up * * @example * ```typescript * try { * const env = await parseEnvFile(envFilePath); * // Use env... * } finally { * await cleanupEnvFile(envFilePath); * } * ``` */ export declare function cleanupEnvFile(filePath: string): Promise<void>;