import * as fs from 'fs-extra'; import * as path from 'path'; import { globby } from 'globby'; export class FileUtils { static async findFiles( directory: string, patterns: string[], exclude?: string[] ): Promise { return await globby(patterns, { cwd: directory, absolute: true, ignore: exclude || [], }); } static async readFilesSafe(filePath: string): Promise { try { return await fs.readFile(filePath, 'utf8'); } catch (error) { console.error(`Failed to read file ${filePath}:`, error); return null; } } static async ensureDirectoryExists(dirPath: string): Promise { await fs.ensureDir(dirPath); } static async copyDirectory(src: string, dest: string): Promise { await fs.copy(src, dest); } static async removeDirectory(dirPath: string): Promise { await fs.remove(dirPath); } static getFileExtension(filePath: string): string { return path.extname(filePath).toLowerCase(); } static getFileName(filePath: string, includeExtension: boolean = true): string { if (includeExtension) { return path.basename(filePath); } return path.basename(filePath, path.extname(filePath)); } static getRelativePath(from: string, to: string): string { return path.relative(from, to); } static async getFileSize(filePath: string): Promise { const stats = await fs.stat(filePath); return stats.size; } static async isDirectory(path: string): Promise { try { const stats = await fs.stat(path); return stats.isDirectory(); } catch { return false; } } static async isFile(path: string): Promise { try { const stats = await fs.stat(path); return stats.isFile(); } catch { return false; } } }