UNPKG

@builder.io/dev-tools

Version:

Builder.io Visual CMS Devtools

78 lines (77 loc) 3.21 kB
export interface FileOverride { /** * Path where the file should be written. * - Absolute paths: "/app/.env", "/etc/config/app.conf" * - Tilde expansion: "~/.config/app.json" (expands to home directory) * - Relative paths: "./file.txt", "config.json" (resolved against working directory) */ path: string; /** * Content to write to the file. */ content: string; } export interface SentryLike { captureException: (error: unknown) => void; } export interface ApplyFileOverridesResult { success: boolean; appliedFiles: string[]; failedFiles: Array<{ path: string; error: string; }>; } /** * Expand tilde (~) in file path to home directory * @param filePath - The file path that may contain tilde * @returns Expanded path with home directory */ export declare function expandTildePath(filePath: string): string; /** * Resolve a file path to an absolute path. * Handles tilde expansion, relative paths, and absolute paths. * @param filePath - The file path to resolve * @param workingDirectory - Optional working directory for resolving relative paths * @returns Resolved absolute path */ export declare function resolveFilePath(filePath: string, workingDirectory?: string): string; /** * Validate that a file path can be resolved to an absolute path * Supports tilde (~) expansion and relative paths (when workingDirectory is provided) * @param filePath - The file path to validate * @param workingDirectory - Optional working directory for resolving relative paths * @returns true if valid, false otherwise */ export declare function isValidFilePath(filePath: string, workingDirectory?: string): boolean; /** * Apply multiple file overrides to the filesystem. * This function will: * 1. Validate each file path * 2. Resolve relative paths against working directory * 3. Create directories as needed * 4. Write files with the provided content * 5. Return detailed results for success/failure of each file * * @param overrides - Array of file overrides to apply * @param workingDirectory - Optional working directory for resolving relative paths * @param sentry - Optional Sentry instance for error logging * @returns Object with overall success status and details for each file */ export declare function applyFileOverrides(overrides: FileOverride[], workingDirectory?: string, sentry?: SentryLike): ApplyFileOverridesResult; /** * Read a file and return its content * Supports tilde (~) expansion and relative paths. * @param filePath - The path to the file to read * @param workingDirectory - Optional working directory for resolving relative paths * @returns The file content or null if it cannot be read */ export declare function readFileOverride(filePath: string, workingDirectory?: string): string | null; /** * Check if a file exists at the given path * Supports tilde (~) expansion and relative paths. * @param filePath - The path to check * @param workingDirectory - Optional working directory for resolving relative paths * @returns true if the file exists, false otherwise */ export declare function fileOverrideExists(filePath: string, workingDirectory?: string): boolean;