import { promises as fsPromises, createReadStream } from 'fs'; import path from 'path'; import { FileObject } from './types'; export async function getFilesWithReadStreams(rootPath: string): Promise { try { const files = await getAllFiles(rootPath); return files.map(file => { const relativePath = path.relative(rootPath, file); return { path: relativePath, content: createReadStream(file) }; }); } catch (error) { console.error('Error reading files:', error); return []; } } export async function getAllFiles(dirPath: string, arrayOfFiles: string[] = []): Promise { const files = await fsPromises.readdir(dirPath, { withFileTypes: true }); for (const file of files) { const fullPath = path.join(dirPath, file.name); if (file.isDirectory()) { await getAllFiles(fullPath, arrayOfFiles); } else { arrayOfFiles.push(fullPath); } } return arrayOfFiles; }