Skip to content

Commit b19ecd2

Browse files
committed
Refactor process and exec to improve async handling, enhance progress bar updates, and streamline file processing
1 parent 36dec93 commit b19ecd2

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/parser/exec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export async function exec(args: Args): Promise<string> {
4545
* Extract the strings from the files
4646
*/
4747
const patterns = getPatterns(args);
48-
const files = await processFiles(patterns, args);
48+
const files = await processFiles(patterns, args, progressBar);
4949

50-
progressBar.update(2, {
50+
progressBar.start(files.length, 0, {
5151
filename: `Found ${files.length} files... `,
5252
});
5353

src/parser/process.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ export async function processFiles(
2424
const tasks: Promise<SetOfBlocks>[] = [];
2525
let processedFilesCount = 0;
2626

27-
const files = getFiles(args, patterns);
27+
const files = await getFiles(args, patterns);
2828

2929
if (progressBar) {
30-
progressBar.setTotal(Object.values(files).length);
30+
progressBar.setTotal(files.length);
3131
progressBar.update(0, {
32-
filename: `Found ${Object.values(files).length} files`,
32+
filename: `Found ${files.length} files`,
3333
});
3434
}
3535

36-
// loop through the files and parse them
37-
for await (const file of files) {
36+
// Loop through the array
37+
for (const file of files) {
3838
processedFilesCount++;
3939
const filename = path.basename(file);
4040
const ext = path.extname(file).replace(/^./, "");
@@ -56,8 +56,9 @@ export async function processFiles(
5656
}
5757

5858
if (progressBar) {
59-
progressBar.update(processedFilesCount, { filename: filename });
60-
progressBar.render();
59+
progressBar.update(processedFilesCount, {
60+
filename: `${path.basename(file)} (Valid: ${tasks.length})`
61+
});
6162
}
6263
}
6364

0 commit comments

Comments
 (0)