Fix crawl async

This commit is contained in:
Joseph Garrone 2024-11-17 23:05:41 +01:00
parent e78eafd1f1
commit c9abc6dc5c

View File

@ -6,19 +6,19 @@ import { assert, type Equals } from "tsafe/assert";
export async function crawlAsync(params: { export async function crawlAsync(params: {
dirPath: string; dirPath: string;
returnedPathsType: "absolute" | "relative to dirPath"; returnedPathsType: "absolute" | "relative to dirPath";
onFileFound: (filePath: string) => void; onFileFound: (filePath: string) => Promise<void>;
}) { }) {
const { dirPath, returnedPathsType, onFileFound } = params; const { dirPath, returnedPathsType, onFileFound } = params;
await crawlAsyncRec({ await crawlAsyncRec({
dirPath, dirPath,
onFileFound: ({ filePath }) => { onFileFound: async ({ filePath }) => {
switch (returnedPathsType) { switch (returnedPathsType) {
case "absolute": case "absolute":
onFileFound(filePath); await onFileFound(filePath);
return; return;
case "relative to dirPath": case "relative to dirPath":
onFileFound(pathRelative(dirPath, filePath)); await onFileFound(pathRelative(dirPath, filePath));
return; return;
} }
assert<Equals<typeof returnedPathsType, never>>(); assert<Equals<typeof returnedPathsType, never>>();
@ -28,7 +28,7 @@ export async function crawlAsync(params: {
async function crawlAsyncRec(params: { async function crawlAsyncRec(params: {
dirPath: string; dirPath: string;
onFileFound: (params: { filePath: string }) => void; onFileFound: (params: { filePath: string }) => Promise<void>;
}) { }) {
const { dirPath, onFileFound } = params; const { dirPath, onFileFound } = params;
@ -45,7 +45,7 @@ async function crawlAsyncRec(params: {
return; return;
} }
onFileFound({ filePath: fileOrDirPath }); await onFileFound({ filePath: fileOrDirPath });
}) })
); );
} }