Skip to content

Commit fdc616d

Browse files
committed
Crawl accepts async function to tell if recusive dive in
1 parent 8dd49a3 commit fdc616d

File tree

1 file changed

+3
-31
lines changed

1 file changed

+3
-31
lines changed

src/bin/tools/crawl.ts

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,14 @@ import { join as pathJoin, relative as pathRelative } from "path";
33

44
async function crawlRec(params: {
55
dirPath: string;
6-
getDoCrawlInDir: (prams: { dirPath: string }) => boolean;
6+
getDoCrawlInDir: (prams: { dirPath: string }) => boolean | Promise<boolean>;
77
}) {
88
const { dirPath, getDoCrawlInDir } = params;
99

1010
const filePaths: string[] = [];
1111

1212
const recursiveCallResults: string[][] = [];
1313

14-
/*
15-
for (const fileOrDirectoryBasename of await readdir(dirPath)) {
16-
17-
const fileOrDirectoryPath = pathJoin(dirPath, fileOrDirectoryBasename);
18-
19-
if ((await lstat(fileOrDirectoryPath)).isDirectory()) {
20-
const dirPath = fileOrDirectoryPath;
21-
22-
if (!getDoCrawlInDir({ dirPath })) {
23-
continue;
24-
}
25-
26-
recursiveCallResults.push(
27-
await crawlRec({
28-
dirPath,
29-
getDoCrawlInDir
30-
})
31-
continue;
32-
);
33-
}
34-
35-
const filePath = fileOrDirectoryPath;
36-
37-
filePaths.push(filePath);
38-
39-
}
40-
*/
41-
4214
await Promise.all(
4315
(
4416
await readdir(dirPath)
@@ -48,7 +20,7 @@ async function crawlRec(params: {
4820
if ((await lstat(fileOrDirectoryPath)).isDirectory()) {
4921
const dirPath = fileOrDirectoryPath;
5022

51-
if (!getDoCrawlInDir({ dirPath })) {
23+
if (!(await getDoCrawlInDir({ dirPath }))) {
5224
return;
5325
}
5426

@@ -74,7 +46,7 @@ async function crawlRec(params: {
7446
/** List all files in a given directory return paths relative to the dirPath */
7547
export async function crawl(params: {
7648
dirPath: string;
77-
getDoCrawlInDir?: (prams: { relativeDirPath: string }) => boolean;
49+
getDoCrawlInDir?: (prams: { relativeDirPath: string }) => boolean | Promise<boolean>;
7850
}) {
7951
const { dirPath: rootDirPath, getDoCrawlInDir = () => true } = params;
8052

0 commit comments

Comments
 (0)