Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/fs/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ 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<string[]> {
// 1. Create the Glob instance
const g = new Glob(pattern.include, {
ignore: {
ignored: (p: Path) => ignoreFunc(p, pattern.exclude),
},
nodir: true,
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();
}
4 changes: 2 additions & 2 deletions src/parser/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export async function exec(args: Args): Promise<string> {
* 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... `,
});

Expand Down
15 changes: 8 additions & 7 deletions src/parser/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export async function processFiles(
const tasks: Promise<SetOfBlocks>[] = [];
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(/^./, "");
Expand All @@ -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})`
});
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/parser/taskRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down