1 | const APIBuilder = require("./apiBuilder");
|
2 | var pm = require("picomatch");
|
3 | var globCache = {};
|
4 |
|
5 | function Builder() {
|
6 | this.maxDepth = Infinity;
|
7 | this.suppressErrors = true;
|
8 | this.filters = [];
|
9 | }
|
10 |
|
11 | Builder.prototype.crawl = function(path) {
|
12 | return new APIBuilder(path, this);
|
13 | };
|
14 |
|
15 | Builder.prototype.crawlWithOptions = function(path, options) {
|
16 | if (!options.maxDepth) options.maxDepth = Infinity;
|
17 | options.groupVar = options.group;
|
18 | options.onlyCountsVar = options.onlyCounts;
|
19 | options.excludeFn = options.exclude;
|
20 | options.filters = options.filters || [];
|
21 | return new APIBuilder(path, options);
|
22 | };
|
23 |
|
24 | Builder.prototype.withBasePath = function() {
|
25 | this.includeBasePath = true;
|
26 | return this;
|
27 | };
|
28 |
|
29 | Builder.prototype.withDirs = function() {
|
30 | this.includeDirs = true;
|
31 | return this;
|
32 | };
|
33 |
|
34 | Builder.prototype.withMaxDepth = function(depth) {
|
35 | this.maxDepth = depth;
|
36 | return this;
|
37 | };
|
38 |
|
39 | Builder.prototype.withFullPaths = function() {
|
40 | this.resolvePaths = true;
|
41 | this.includeBasePath = true;
|
42 | return this;
|
43 | };
|
44 |
|
45 | Builder.prototype.withErrors = function() {
|
46 | this.suppressErrors = false;
|
47 | return this;
|
48 | };
|
49 |
|
50 | Builder.prototype.group = function() {
|
51 | this.groupVar = true;
|
52 | return this;
|
53 | };
|
54 |
|
55 | Builder.prototype.normalize = function() {
|
56 | this.normalizePath = true;
|
57 | return this;
|
58 | };
|
59 |
|
60 | Builder.prototype.filter = function(filterFn) {
|
61 | this.filters.push(filterFn);
|
62 | return this;
|
63 | };
|
64 |
|
65 | Builder.prototype.glob = function(...patterns) {
|
66 |
|
67 | if (!pm) {
|
68 | throw new Error(
|
69 | `Please install picomatch: "npm i picomatch" to use glob matching.`
|
70 | );
|
71 | }
|
72 | var isMatch = globCache[patterns.join()];
|
73 | if (!isMatch) {
|
74 | isMatch = pm(patterns, { dot: true });
|
75 | globCache[patterns.join()] = isMatch;
|
76 | }
|
77 | this.filters.push((path) => isMatch(path));
|
78 | return this;
|
79 | };
|
80 |
|
81 | Builder.prototype.exclude = function(excludeFn) {
|
82 | this.excludeFn = excludeFn;
|
83 | return this;
|
84 | };
|
85 |
|
86 | Builder.prototype.onlyCounts = function() {
|
87 | this.onlyCountsVar = true;
|
88 | return this;
|
89 | };
|
90 |
|
91 | module.exports = Builder;
|