( dir: string, fs: FileSystemAPI, filterFromRootPredicate: ((path: string) => boolean) | null, files: FileAndContent[] = [], )
| 39 | } |
| 40 | |
| 41 | export const checkFilesInDirectory = async ( |
| 42 | dir: string, |
| 43 | fs: FileSystemAPI, |
| 44 | filterFromRootPredicate: ((path: string) => boolean) | null, |
| 45 | files: FileAndContent[] = [], |
| 46 | ) => { |
| 47 | const entries = (await fs.readdir(dir, {withFileTypes: true})) ?? []; |
| 48 | |
| 49 | for (const entry of entries) { |
| 50 | const fullPath = normalizePath(`${dir}/${entry.name}`); |
| 51 | |
| 52 | if (filterFromRootPredicate && !filterFromRootPredicate?.(entry.name)) { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | if (entry.isFile()) { |
| 57 | const content = await fs.readFile(fullPath, 'utf-8'); |
| 58 | files.push({content, path: fullPath}); |
| 59 | } else if (entry.isDirectory()) { |
| 60 | await checkFilesInDirectory(fullPath, fs, null, files); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return files; |
| 65 | }; |
no test coverage detected
searching dependent graphs…