@@ -3,42 +3,14 @@ import { join as pathJoin, relative as pathRelative } from "path";
3
3
4
4
async function crawlRec ( params : {
5
5
dirPath : string ;
6
- getDoCrawlInDir : ( prams : { dirPath : string } ) => boolean ;
6
+ getDoCrawlInDir : ( prams : { dirPath : string } ) => boolean | Promise < boolean > ;
7
7
} ) {
8
8
const { dirPath, getDoCrawlInDir } = params ;
9
9
10
10
const filePaths : string [ ] = [ ] ;
11
11
12
12
const recursiveCallResults : string [ ] [ ] = [ ] ;
13
13
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
-
42
14
await Promise . all (
43
15
(
44
16
await readdir ( dirPath )
@@ -48,7 +20,7 @@ async function crawlRec(params: {
48
20
if ( ( await lstat ( fileOrDirectoryPath ) ) . isDirectory ( ) ) {
49
21
const dirPath = fileOrDirectoryPath ;
50
22
51
- if ( ! getDoCrawlInDir ( { dirPath } ) ) {
23
+ if ( ! ( await getDoCrawlInDir ( { dirPath } ) ) ) {
52
24
return ;
53
25
}
54
26
@@ -74,7 +46,7 @@ async function crawlRec(params: {
74
46
/** List all files in a given directory return paths relative to the dirPath */
75
47
export async function crawl ( params : {
76
48
dirPath : string ;
77
- getDoCrawlInDir ?: ( prams : { relativeDirPath : string } ) => boolean ;
49
+ getDoCrawlInDir ?: ( prams : { relativeDirPath : string } ) => boolean | Promise < boolean > ;
78
50
} ) {
79
51
const { dirPath : rootDirPath , getDoCrawlInDir = ( ) => true } = params ;
80
52
0 commit comments