import { promises as fsPromise } from 'fs'; import fs from 'fs'; import path from 'path'; export class FileManager { static async readFile(path: string): Promise { try { return await fsPromise.readFile(path, 'utf8'); } catch (err) { throw err; } } static async writeFile(path: string, contents: string): Promise { try { await fsPromise.writeFile(path, contents, 'utf8'); } catch (err) { throw err; } } static async copyFile(path1: string, path2: string): Promise { try { const fileContents = await FileManager.readFile(path1); await FileManager.writeFile(path2, fileContents); } catch (err) { throw err; } } static async dirExists(path: string): Promise { try { await fsPromise.access(path); return true; } catch { return false; } } // Asynchronous function to copy a folder and its contents static async copyFolderAsync(src: string, dest: string): Promise { await fs.mkdirSync(dest, { recursive: true }); const files = await fs.readdirSync(src); for (const file of files) { const srcPath = path.join(src, file); const destPath = path.join(dest, file); const stats = await fs.lstatSync(srcPath); if (stats.isDirectory()) { await this.copyFolderAsync(srcPath, destPath); } else { await fs.copyFileSync(srcPath, destPath); } } } }