@param {string} gitignore @returns {string[]}
(gitignore)
| 12 | @param {string} gitignore |
| 13 | @returns {string[]} */ |
| 14 | function gitignore_to_glob_patterns(gitignore) { |
| 15 | |
| 16 | const patterns = [] |
| 17 | |
| 18 | for (let pattern of gitignore.split('\n')) { |
| 19 | |
| 20 | pattern = pattern.trim() |
| 21 | |
| 22 | if (pattern === '' || pattern.startsWith('#')) { |
| 23 | continue |
| 24 | } |
| 25 | |
| 26 | let negated = false |
| 27 | if (pattern[0] === '!') { |
| 28 | negated = true |
| 29 | pattern = pattern.slice(1) |
| 30 | } |
| 31 | |
| 32 | if (pattern[0] === '/') { |
| 33 | pattern = pattern.slice(1) |
| 34 | } else if (!pattern.startsWith('**/')) { |
| 35 | pattern = '**/'+pattern |
| 36 | } |
| 37 | |
| 38 | if (negated) { |
| 39 | pattern = '!'+pattern |
| 40 | } |
| 41 | |
| 42 | if (pattern.indexOf('.') > 0) { |
| 43 | patterns.push(pattern) |
| 44 | } else { |
| 45 | patterns.push(pattern) |
| 46 | if (pattern.endsWith('/')) { |
| 47 | patterns.push(pattern+'**/*') |
| 48 | } else { |
| 49 | patterns.push(pattern+'/**/*') |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return patterns |
| 55 | } |
| 56 | |
| 57 | const git_ignored_paths = gitignore_to_glob_patterns(fs.readFileSync('.gitignore', 'utf-8')) |
| 58 |
no outgoing calls
no test coverage detected
searching dependent graphs…