-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
43 lines (33 loc) · 874 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
var findup = require('findup-sync');
var ignore = require('parse-gitignore');
var mm = require('micromatch');
var cwd = process.cwd();
function parseGitignore(opts) {
opts = opts || {};
var gitignoreFile = findup('.gitignore', {cwd: cwd});
var ignorePatterns = ignore(gitignoreFile);
var isMatch = function(fp) {
return mm.any(fp, ignorePatterns, opts);
};
return function gitignore(file) {
opts = this.setDefaults(this.pattern.options, opts);
if (opts.dot || opts.dotfiles || opts.dotdirs) {
if (file.isDotfile() || file.isDotdir()) {
return file;
}
}
if (opts.gitignore === false) {
return file;
}
if (isMatch(file.relative)) {
file.isIgnored = true;
file.exclude = true;
}
return file;
};
}
/**
* Expose `parseGitignore`
*/
module.exports = parseGitignore;