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A,CAAO,QAAU,EAAA,EAAA,CAAG,UAAU,IAAI,CAAA;AACpD,IAAO,OAAA,IAAA;AAAA,GACD,CAAA,MAAA;AACN,IAAO,OAAA,KAAA;AAAA;AAEX;AAOO,SAAS,iBAAiB,QAA0B,EAAA;AACzD,EAAM,MAAA,GAAA,GAAM,IAAK,CAAA,OAAA,CAAQ,QAAQ,CAAA;AACjC,EAAA,OAAO,GAAM,GAAA,GAAA,CAAI,KAAM,CAAA,CAAC,CAAI,GAAA,EAAA;AAC9B","file":"common.mjs","sourcesContent":["/**\n * Common utilities\n * Helper functions used across the codebase\n */\n\nimport * as fs from 'fs';\nimport * as path from 'path';\n\n/**\n * Ensure a directory exists\n * @param dirPath Directory path to ensure exists\n * @returns Promise that resolves when the directory exists\n */\nexport async function ensureDirectoryExists(dirPath: string): Promise<void> {\n  try {\n    await fs.promises.mkdir(dirPath, {recursive: true});\n  } catch (err: any) {\n    // Ignore if directory already exists\n    if (err.code !== 'EEXIST') {\n      throw err;\n    }\n  }\n}\n\n/**\n * Normalize a path to use forward slashes\n * @param filePath Path to normalize\n * @returns Normalized path\n */\nexport function normalizePath(filePath: string): string {\n  return filePath.replace(/\\\\/g, '/');\n}\n\n/**\n * Format a file size in a human-readable format\n * @param bytes Size in bytes\n * @param decimals Number of decimal places\n * @returns Formatted size string\n */\nexport function formatFileSize(bytes: number, decimals = 2): string {\n  if (bytes === 0) return '0 Bytes';\n\n  const k = 1024;\n  const dm = decimals < 0 ? 0 : decimals;\n  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n  const i = Math.floor(Math.log(bytes) / Math.log(k));\n\n  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];\n}\n\n/**\n * Check if a path is a subdirectory of another path\n * @param parent Parent directory path\n * @param child Child path to check\n * @returns True if child is a subdirectory of parent\n */\nexport function isSubdirectory(parent: string, child: string): boolean {\n  const normalizedParent = normalizePath(path.resolve(parent));\n  const normalizedChild = normalizePath(path.resolve(child));\n  const relativePath = path.relative(normalizedParent, normalizedChild);\n  return !!relativePath && !relativePath.startsWith('..') && !path.isAbsolute(relativePath);\n}\n\n/**\n * Safely copy a file from source to destination using streams\n * @param source Source file path\n * @param destination Destination file path\n * @param overwrite Whether to overwrite if destination exists\n * @returns Promise that resolves when the copy is complete\n */\nexport async function copyFileWithStreams(source: string, destination: string, overwrite = false): Promise<void> {\n  try {\n    // Ensure destination directory exists\n    const destinationDir = path.dirname(destination);\n    await ensureDirectoryExists(destinationDir);\n\n    // Check if destination exists and overwrite is false\n    if (!overwrite && fs.existsSync(destination)) {\n      throw new Error(`Target file already exists: ${destination}`);\n    }\n\n    // Implement actual file copy logic\n    return new Promise((resolve, reject) => {\n      const readStream = fs.createReadStream(source);\n      const writeStream = fs.createWriteStream(destination);\n\n      readStream.on('error', err => {\n        reject(new Error(`Failed to read ${source}: ${err.message}`));\n      });\n\n      writeStream.on('error', err => {\n        reject(new Error(`Failed to write to ${destination}: ${err.message}`));\n      });\n\n      writeStream.on('finish', () => {\n        resolve();\n      });\n\n      readStream.pipe(writeStream);\n    });\n  } catch (error: any) {\n    // Throw original error directly, avoid nested error messages\n    if (\n      error.message.includes('Target file already exists') ||\n      error.message.includes('Failed to read') ||\n      error.message.includes('Failed to write to')\n    ) {\n      throw error;\n    }\n    throw new Error(`Failed to copy ${source} to ${destination}: ${error.message}`);\n  }\n}\n\n/**\n * Calculate total size of files\n * @param filePaths Array of file paths\n * @returns Promise resolving to total size in bytes\n */\nexport async function calculateTotalSize(filePaths: string[]): Promise<number> {\n  let totalSize = 0;\n\n  for (const filePath of filePaths) {\n    try {\n      const stats = await fs.promises.stat(filePath);\n      // Check if stats object has isFile method, if not but has size property, use size directly\n      if (typeof stats.isFile === 'function' && stats.isFile()) {\n        totalSize += stats.size;\n      } else if (stats.size !== undefined) {\n        // If no isFile method but has size property, use size directly\n        totalSize += stats.size;\n      }\n    } catch (error) {\n      console.warn(`Could not get size of ${filePath}:`, error);\n    }\n  }\n\n  return totalSize;\n}\n\n/**\n * Check if a file exists and is accessible\n * @param filePath Path to check\n * @returns Promise resolving to boolean indicating if file exists and is accessible\n */\nexport async function fileExists(filePath: string): Promise<boolean> {\n  try {\n    await fs.promises.access(filePath, fs.constants.F_OK);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Get file extension from path\n * @param filePath File path\n * @returns File extension (without the dot) or empty string if no extension\n */\nexport function getFileExtension(filePath: string): string {\n  const ext = path.extname(filePath);\n  return ext ? ext.slice(1) : '';\n}\n"]}