* Recursively apply callback to files in a directory (and sub-directories) that match the * provided regular expression
(rootPath: string, startPath: string, filter: RegExp, excludeDirectoryFilter: RegExp | null, callback: Function)
| 12 | * provided regular expression |
| 13 | */ |
| 14 | function fromDir(rootPath: string, startPath: string, filter: RegExp, excludeDirectoryFilter: RegExp | null, callback: Function) { |
| 15 | if (!existsSync(startPath)) { |
| 16 | throw new Error(`No Directory Found: ${startPath}`); |
| 17 | } |
| 18 | |
| 19 | const files = readdirSync(startPath); |
| 20 | for (let i = 0; i < files.length; i++) { |
| 21 | const filename = joinPath(startPath, files[i]); |
| 22 | const stat = lstatSync(filename); |
| 23 | |
| 24 | if (stat.isDirectory()) { |
| 25 | if (excludeDirectoryFilter) { |
| 26 | if (!excludeDirectoryFilter.test(filename)) { |
| 27 | fromDir(rootPath, filename, filter, excludeDirectoryFilter, callback); |
| 28 | } |
| 29 | } else { |
| 30 | fromDir(rootPath, filename, filter, excludeDirectoryFilter, callback); |
| 31 | } |
| 32 | } else if (filter.test(filename)) { |
| 33 | callback(filename, rootPath); |
| 34 | } |
| 35 | } |
| 36 | } |