update
This commit is contained in:
@ -119,9 +119,23 @@ export class CorpusLoader {
|
||||
|
||||
for (const cat of categoriesToSearch) {
|
||||
const categoryFiles = await this.loadCategory(cat);
|
||||
const matchingFiles = categoryFiles.filter(file =>
|
||||
path.basename(file.path).match(pattern.replace('*', '.*'))
|
||||
);
|
||||
const matchingFiles = categoryFiles.filter(file => {
|
||||
// Convert glob pattern to regex pattern
|
||||
const regexPattern = pattern
|
||||
.replace(/\*\*/g, '@@DOUBLESTAR@@') // Temporarily replace **
|
||||
.replace(/\*/g, '[^/]*') // Replace * with "any character except /"
|
||||
.replace(/@@DOUBLESTAR@@/g, '.*') // Replace ** with "any character"
|
||||
.replace(/\//g, '\\/') // Escape forward slashes
|
||||
.replace(/\./g, '\\.'); // Escape dots
|
||||
|
||||
try {
|
||||
const regex = new RegExp(regexPattern);
|
||||
return regex.test(file.path);
|
||||
} catch (e) {
|
||||
// If regex fails, try simple includes match
|
||||
return file.path.includes(pattern.replace(/\*/g, ''));
|
||||
}
|
||||
});
|
||||
files.push(...matchingFiles);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user