Parallelize reading files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
d36f62ea2b
commit
a624f664ef
1 changed files with 11 additions and 9 deletions
20
src/index.ts
20
src/index.ts
|
@ -129,15 +129,17 @@ interface Reports {
|
|||
let reports: Reports = {};
|
||||
async function recurseDirectory(reports: Reports, path: string) {
|
||||
const dir = await readdir(path, { withFileTypes: true });
|
||||
for (const file of dir) {
|
||||
const filePath = join(path, file.name);
|
||||
if (file.isDirectory()) await recurseDirectory(reports, filePath);
|
||||
else {
|
||||
if (!file.name.endsWith(".html")) continue;
|
||||
const content = await readFile(filePath, "utf-8");
|
||||
reports[filePath] = await processFile(content);
|
||||
}
|
||||
}
|
||||
return await Promise.all(
|
||||
dir.map(async (file) => {
|
||||
const filePath = join(path, file.name);
|
||||
if (file.isDirectory()) await recurseDirectory(reports, filePath);
|
||||
else {
|
||||
if (!file.name.endsWith(".html")) return;
|
||||
const content = await readFile(filePath, "utf-8");
|
||||
reports[filePath] = await processFile(content);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
await recurseDirectory(reports, dirPath);
|
||||
const totalThings = Object.values(reports)
|
||||
|
|
Loading…
Reference in a new issue