xchange-create
Version:
Create Xchange Project
20 lines (17 loc) • 526 B
text/typescript
import fs from "fs";
import path from "path";
export const findFilesRecursiveSync = (
baseDir: string,
criteriaFn: (path: string) => boolean = () => true
): string[] => {
const subPaths = fs.readdirSync(baseDir);
const files = subPaths.map((relativePath) => {
const fullPath = path.resolve(baseDir, relativePath);
return fs.lstatSync(fullPath).isDirectory()
? [...findFilesRecursiveSync(fullPath, criteriaFn)]
: criteriaFn(fullPath)
? [fullPath]
: [];
});
return files.flat();
};