Skip to content

Commit

Permalink
fix multi pattern file filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
yielder committed Jul 31, 2024
1 parent 195c8e4 commit dc6a9dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"description": "CoPa: Copy File Sources For Prompting",
"type": "commonjs",
"main": "./dist/copa.js",
"bin": {
"copa": "./dist/copa.js"
},
"bin": "./dist/copa.js",
"scripts": {
"build": "tsc",
"start": "node dist/copa.js"
Expand All @@ -23,7 +21,7 @@
"axios": "^1.7.2",
"clipboardy": "^4.0.0",
"commander": "^12.1.0",
"dom-to-semantic-markdown": "1.1.1",
"dom-to-semantic-markdown": "1.1.2",
"glob": "^11.0.0",
"jsdom": "^24.1.1",
"simple-git": "^3.25.0",
Expand Down
11 changes: 6 additions & 5 deletions src/copa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ async function copyFilesToClipboard(directory: string, options: Options): Promis

if (excludePatterns.length > 0) {
files = files.filter(file => !excludePatterns.some(pattern =>
glob.hasMagic(pattern)
? glob.sync(pattern, {cwd: directory}).includes(file)
: !file.endsWith(pattern)));
file.endsWith(pattern) ||
glob.hasMagic(pattern)
? glob.sync(pattern, {cwd: directory}).includes(file)
: false));
}
} else {
const globPattern = path.join(directory, '**/*');
files = await glob(globPattern, { nodir: true, ignore: excludePatterns });
files = await glob(globPattern, {nodir: true, ignore: excludePatterns});
}
} catch (error) {
console.error('Error listing files:', error);
Expand Down Expand Up @@ -132,7 +133,7 @@ program
if (options.file) {
readSingleFile(options.file);
} else if (directory) {
copyFilesToClipboard(directory, options);
copyFilesToClipboard(directory, options);
} else {
console.error('Error: Please provide either a directory or use the --file option.');
process.exit(1);
Expand Down

0 comments on commit dc6a9dc

Please sign in to comment.