diff --git a/src/fs/glob.ts b/src/fs/glob.ts index 682c836..2cfb446 100644 --- a/src/fs/glob.ts +++ b/src/fs/glob.ts @@ -65,9 +65,9 @@ export const ignoreFunc = ( * @param {Patterns} pattern - The pattern object containing the included and excluded file patterns. * @return A promise that resolves to an array of file paths. */ -export function getFiles(args: Args, pattern: Patterns) { - // Execute the glob search with the built patterns - return new Glob(pattern.include, { +export async function getFiles(args: Args, pattern: Patterns): Promise { + // 1. Create the Glob instance + const g = new Glob(pattern.include, { ignore: { ignored: (p: Path) => ignoreFunc(p, pattern.exclude), }, @@ -75,4 +75,7 @@ export function getFiles(args: Args, pattern: Patterns) { cwd: args.paths.cwd, root: args.paths.root ? path.resolve(args.paths.root) : undefined, }); + + // 2. Return the walk() promise, which resolves to an array of all file paths + return g.walk(); } diff --git a/src/parser/exec.ts b/src/parser/exec.ts index c56bd88..338e231 100644 --- a/src/parser/exec.ts +++ b/src/parser/exec.ts @@ -45,9 +45,9 @@ export async function exec(args: Args): Promise { * Extract the strings from the files */ const patterns = getPatterns(args); - const files = await processFiles(patterns, args); + const files = await processFiles(patterns, args, progressBar); - progressBar.update(2, { + progressBar.start(files.length, 0, { filename: `Found ${files.length} files... `, }); diff --git a/src/parser/process.ts b/src/parser/process.ts index bfa6308..fc7fcf0 100644 --- a/src/parser/process.ts +++ b/src/parser/process.ts @@ -24,17 +24,17 @@ export async function processFiles( const tasks: Promise[] = []; let processedFilesCount = 0; - const files = getFiles(args, patterns); + const files = await getFiles(args, patterns); if (progressBar) { - progressBar.setTotal(Object.values(files).length); + progressBar.setTotal(files.length); progressBar.update(0, { - filename: `Found ${Object.values(files).length} files`, + filename: `Found ${files.length} files`, }); } - // loop through the files and parse them - for await (const file of files) { + // Loop through the array + for (const file of files) { processedFilesCount++; const filename = path.basename(file); const ext = path.extname(file).replace(/^./, ""); @@ -56,8 +56,9 @@ export async function processFiles( } if (progressBar) { - progressBar.update(processedFilesCount, { filename: filename }); - progressBar.render(); + progressBar.update(processedFilesCount, { + filename: `${path.basename(file)} (Valid: ${tasks.length})` + }); } } diff --git a/src/parser/taskRunner.ts b/src/parser/taskRunner.ts index d3ce770..9c4d202 100644 --- a/src/parser/taskRunner.ts +++ b/src/parser/taskRunner.ts @@ -19,7 +19,13 @@ export async function taskRunner( progressBar: SingleBar, ) { const messages: string[] = []; - await Promise.allSettled(tasks) + // Create a new array of promises that update the bar when they finish. + const tasksWithProgress = tasks.map((task) => + task.finally(() => { + progressBar.increment(); + }) + ); + await Promise.allSettled(tasksWithProgress) .then((strings) => { /** * Return the strings that are not rejected (they are fulfilled)