MCPcopy Index your code
hub / github.com/code-pushup/cli / crawlFileSystem

Function crawlFileSystem

packages/utils/src/lib/file-system.ts:77–102  ·  view source on GitHub ↗
(
  options: CrawlFileSystemOptions<T>,
)

Source from the content-addressed store, hash-verified

75 fileTransform?: (filePath: string) => Promise<T> | T;
76};
77export async function crawlFileSystem<T = string>(
78 options: CrawlFileSystemOptions<T>,
79): Promise<T[]> {
80 const {
81 directory,
82 pattern,
83 fileTransform = (filePath: string) => filePath as T,
84 } = options;
85
86 const files = await readdir(directory);
87 const promises = files.map(async (file): Promise<T | T[]> => {
88 const filePath = path.join(directory, file);
89 const stats = await stat(filePath);
90
91 if (stats.isDirectory()) {
92 return crawlFileSystem({ directory: filePath, pattern, fileTransform });
93 }
94 if (stats.isFile() && (!pattern || new RegExp(pattern).test(file))) {
95 return fileTransform(filePath);
96 }
97 return [];
98 });
99
100 const resultsNestedArray = await Promise.all(promises);
101 return resultsNestedArray.flat() as T[];
102}
103
104export async function findNearestFile(
105 fileNames: string[],

Callers 6

runnerFunctionFunction · 0.90
fileSizeIssuesFunction · 0.90
resolveConfigFunction · 0.90
tsMigrationPluginFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected