| 20 | } |
| 21 | |
| 22 | export function loadIgnoreRules(options: LoadIgnoreRulesOptions): Ignore { |
| 23 | const ignorer = new Ignore(); |
| 24 | if (options.useGitignore) { |
| 25 | const gitignorePath = path.join(options.projectRoot, '.gitignore'); |
| 26 | if (fs.existsSync(gitignorePath)) { |
| 27 | ignorer.add(fs.readFileSync(gitignorePath, 'utf8')); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | if (options.useAnusignore) { |
| 32 | // Check for .anusignore |
| 33 | const anusignorePath = path.join(options.projectRoot, '.anusignore'); |
| 34 | |
| 35 | if (fs.existsSync(anusignorePath)) { |
| 36 | ignorer.add(fs.readFileSync(anusignorePath, 'utf8')); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | const ignoreDirs = ['.git', ...options.ignoreDirs]; |
| 41 | ignorer.add( |
| 42 | ignoreDirs.map((dir) => { |
| 43 | if (dir.endsWith('/')) { |
| 44 | return dir; |
| 45 | } |
| 46 | return `${dir}/`; |
| 47 | }), |
| 48 | ); |
| 49 | |
| 50 | return ignorer; |
| 51 | } |
| 52 | |
| 53 | export class Ignore { |
| 54 | private readonly allPatterns: string[] = []; |