find-cli 1.6.3 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/bin/abbreviations.js +11 -1
- package/bin/action/find.js +8 -5
- package/bin/action/help.js +2 -0
- package/bin/configuration/version_1_4.js +1 -24
- package/bin/configuration/version_1_7.js +44 -0
- package/bin/configuration.js +30 -4
- package/bin/constants.js +2 -0
- package/bin/defaults.js +2 -0
- package/bin/descriptions.js +4 -2
- package/bin/main.js +4 -4
- package/bin/messages.js +4 -2
- package/bin/occurrence.js +2 -3
- package/bin/operation/find.js +33 -199
- package/bin/operation/previousRule.js +39 -0
- package/bin/operation/prompt/previousRule.js +52 -0
- package/bin/operation/prompt/rule.js +17 -5
- package/bin/operation/rule.js +2 -2
- package/bin/options.js +2 -0
- package/bin/rule/glob.js +27 -5
- package/bin/rule/regex.js +27 -5
- package/bin/rule/string.js +35 -15
- package/bin/utilities/find.js +203 -0
- package/bin/utilities/prompt.js +124 -2
- package/bin/utilities/string.js +0 -3
- package/bin/versions.js +4 -2
- package/package.json +2 -2
- package/bin/operation/readConfiguration.js +0 -27
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { selectPreviousRule } = require("../../utilities/prompt"),
|
|
4
|
+
{ retrievePreviousRules } = require("../../configuration"),
|
|
5
|
+
{ NO_PREVIOUS_RULES_MESSAGE } = require("../../messages");
|
|
6
|
+
|
|
7
|
+
function previousRulePromptOperation(proceed, abort, context) {
|
|
8
|
+
const { dryRun } = context;
|
|
9
|
+
|
|
10
|
+
if (dryRun) {
|
|
11
|
+
proceed();
|
|
12
|
+
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { previous } = context;
|
|
17
|
+
|
|
18
|
+
if (!previous) {
|
|
19
|
+
proceed();
|
|
20
|
+
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const previousRules = retrievePreviousRules(),
|
|
25
|
+
previousRulesLength = previousRules.length;
|
|
26
|
+
|
|
27
|
+
if (previousRulesLength === 0) {
|
|
28
|
+
console.log(NO_PREVIOUS_RULES_MESSAGE);
|
|
29
|
+
|
|
30
|
+
abort();
|
|
31
|
+
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
selectPreviousRule(previousRules, (previousRule) => {
|
|
36
|
+
if (previousRule === null) {
|
|
37
|
+
abort();
|
|
38
|
+
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const rule = previousRule; ///
|
|
43
|
+
|
|
44
|
+
Object.assign(context, {
|
|
45
|
+
rule
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
proceed();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = previousRulePromptOperation;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const { shellUtilities } = require("necessary");
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { EMPTY_STRING } = require("../../constants"),
|
|
6
|
+
{ validateGlobStringOrPattern } = require("../../utilities/validate"),
|
|
6
7
|
{ GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../../descriptions"),
|
|
7
8
|
{ ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
|
|
8
9
|
{ INVALID_GLOB_REGEX_OR_STRING_MESSAGE } = require("../../messages");
|
|
@@ -26,22 +27,33 @@ function rulePromptOperation(proceed, abort, context) {
|
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
const {
|
|
30
|
+
const { rule, anchored, directory } = context,
|
|
30
31
|
description = GLOB_STRING_OR_REGEX_DESCRIPTION,
|
|
31
32
|
errorMessage = INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
32
|
-
initialAnswer = path, ///
|
|
33
33
|
validationFunction = (answer) => {
|
|
34
|
-
|
|
34
|
+
let valid = false;
|
|
35
|
+
|
|
36
|
+
if (answer !== EMPTY_STRING) {
|
|
37
|
+
valid = validateGlobStringOrPattern(answer, anchored, directory);
|
|
38
|
+
}
|
|
35
39
|
|
|
36
40
|
return valid;
|
|
37
41
|
},
|
|
38
42
|
options = {
|
|
39
43
|
description,
|
|
40
44
|
errorMessage,
|
|
41
|
-
initialAnswer,
|
|
42
45
|
validationFunction
|
|
43
46
|
};
|
|
44
47
|
|
|
48
|
+
if (rule !== null) {
|
|
49
|
+
const ruleString = rule.asString(),
|
|
50
|
+
initialAnswer = ruleString; ///
|
|
51
|
+
|
|
52
|
+
Object.assign(options, {
|
|
53
|
+
initialAnswer
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
prompt(options, (answer) => {
|
|
46
58
|
const valid = (answer !== null);
|
|
47
59
|
|
package/bin/operation/rule.js
CHANGED
package/bin/options.js
CHANGED
|
@@ -8,6 +8,7 @@ const HELP_OPTION = "help",
|
|
|
8
8
|
VERSION_OPTION = "version",
|
|
9
9
|
QUIETLY_OPTION = "quietly",
|
|
10
10
|
DRY_RUN_OPTION = "dry-run",
|
|
11
|
+
PREVIOUS_OPTION = "previous",
|
|
11
12
|
INTERACTIVE_OPTION = "interactive";
|
|
12
13
|
|
|
13
14
|
module.exports = {
|
|
@@ -19,5 +20,6 @@ module.exports = {
|
|
|
19
20
|
VERSION_OPTION,
|
|
20
21
|
QUIETLY_OPTION,
|
|
21
22
|
DRY_RUN_OPTION,
|
|
23
|
+
PREVIOUS_OPTION,
|
|
22
24
|
INTERACTIVE_OPTION
|
|
23
25
|
};
|
package/bin/rule/glob.js
CHANGED
|
@@ -9,12 +9,17 @@ const { GLOB_TYPE } = require("../types"),
|
|
|
9
9
|
{ addAnchors, addTrailingForwardSlash, removeTrailingForwardSlash } = require("../utilities/string");
|
|
10
10
|
|
|
11
11
|
class GlobRule {
|
|
12
|
-
constructor(glob, pattern, regExp) {
|
|
12
|
+
constructor(type, glob, pattern, regExp) {
|
|
13
|
+
this.type = type;
|
|
13
14
|
this.glob = glob;
|
|
14
15
|
this.pattern = pattern;
|
|
15
16
|
this.regExp = regExp;
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
getType() {
|
|
20
|
+
return this.type;
|
|
21
|
+
}
|
|
22
|
+
|
|
18
23
|
getGlob() {
|
|
19
24
|
return this.glob;
|
|
20
25
|
}
|
|
@@ -28,7 +33,7 @@ class GlobRule {
|
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
toJSON() {
|
|
31
|
-
const type =
|
|
36
|
+
const type = this.type,
|
|
32
37
|
glob = this.glob,
|
|
33
38
|
pattern = this.pattern,
|
|
34
39
|
json = {
|
|
@@ -71,6 +76,22 @@ class GlobRule {
|
|
|
71
76
|
return matches;
|
|
72
77
|
}
|
|
73
78
|
|
|
79
|
+
isEqualTo(rule) {
|
|
80
|
+
let equalTo = false;
|
|
81
|
+
|
|
82
|
+
const ruleType = rule.getType();
|
|
83
|
+
|
|
84
|
+
if (ruleType === this.type) {
|
|
85
|
+
const ruleGlob = rule.getGlob();
|
|
86
|
+
|
|
87
|
+
if (ruleGlob === this.glob) {
|
|
88
|
+
equalTo = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return equalTo;
|
|
93
|
+
}
|
|
94
|
+
|
|
74
95
|
asString() {
|
|
75
96
|
const string = this.glob; ///
|
|
76
97
|
|
|
@@ -86,7 +107,7 @@ class GlobRule {
|
|
|
86
107
|
const { glob, pattern } = json,
|
|
87
108
|
regExp = new RegExp(pattern);
|
|
88
109
|
|
|
89
|
-
globRule = new GlobRule(glob, pattern, regExp);
|
|
110
|
+
globRule = new GlobRule(type, glob, pattern, regExp);
|
|
90
111
|
}
|
|
91
112
|
|
|
92
113
|
return globRule;
|
|
@@ -98,10 +119,11 @@ class GlobRule {
|
|
|
98
119
|
const glob = globFromStringAndDirectory(string, directory);
|
|
99
120
|
|
|
100
121
|
if (glob !== null) {
|
|
101
|
-
const
|
|
122
|
+
const type = GLOB_TYPE,
|
|
123
|
+
pattern = patternFromGlobAndAnchored(glob, anchored),
|
|
102
124
|
regExp = new RegExp(pattern);
|
|
103
125
|
|
|
104
|
-
globRule = new GlobRule(glob, pattern, regExp);
|
|
126
|
+
globRule = new GlobRule(type, glob, pattern, regExp);
|
|
105
127
|
}
|
|
106
128
|
|
|
107
129
|
return globRule;
|
package/bin/rule/regex.js
CHANGED
|
@@ -12,11 +12,16 @@ const { REGEX_TYPE } = require("../types"),
|
|
|
12
12
|
removeTrailingEscapedForwardSlash } = require("../utilities/string");
|
|
13
13
|
|
|
14
14
|
class RegexRule {
|
|
15
|
-
constructor(pattern, regExp) {
|
|
15
|
+
constructor(type, pattern, regExp) {
|
|
16
|
+
this.type = type;
|
|
16
17
|
this.pattern = pattern;
|
|
17
18
|
this.regExp = regExp;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
getType() {
|
|
22
|
+
return this.type;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
getPattern() {
|
|
21
26
|
return this.pattern;
|
|
22
27
|
}
|
|
@@ -26,7 +31,7 @@ class RegexRule {
|
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
toJSON() {
|
|
29
|
-
const type =
|
|
34
|
+
const type = this.type,
|
|
30
35
|
pattern = this.pattern,
|
|
31
36
|
json = {
|
|
32
37
|
type,
|
|
@@ -67,6 +72,22 @@ class RegexRule {
|
|
|
67
72
|
return matches;
|
|
68
73
|
}
|
|
69
74
|
|
|
75
|
+
isEqualTo(rule) {
|
|
76
|
+
let equalTo = false;
|
|
77
|
+
|
|
78
|
+
const ruleType = rule.getType();
|
|
79
|
+
|
|
80
|
+
if (ruleType === this.type) {
|
|
81
|
+
const rulePattern = rule.getPattern();
|
|
82
|
+
|
|
83
|
+
if (rulePattern === this.pattern) {
|
|
84
|
+
equalTo = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return equalTo;
|
|
89
|
+
}
|
|
90
|
+
|
|
70
91
|
asString() {
|
|
71
92
|
const string = addForwardSlashes(this.pattern); ///
|
|
72
93
|
|
|
@@ -82,7 +103,7 @@ class RegexRule {
|
|
|
82
103
|
const { pattern } = json,
|
|
83
104
|
regExp = new RegExp(pattern);
|
|
84
105
|
|
|
85
|
-
regexRule = new RegexRule(pattern, regExp);
|
|
106
|
+
regexRule = new RegexRule(type, pattern, regExp);
|
|
86
107
|
}
|
|
87
108
|
|
|
88
109
|
return regexRule;
|
|
@@ -94,9 +115,10 @@ class RegexRule {
|
|
|
94
115
|
const pattern = patternFromStringAndDirectory(string, anchored, directory);
|
|
95
116
|
|
|
96
117
|
if (pattern !== null) {
|
|
97
|
-
const
|
|
118
|
+
const type = REGEX_TYPE,
|
|
119
|
+
regExp = new RegExp(pattern);
|
|
98
120
|
|
|
99
|
-
regexRule = new RegexRule(pattern, regExp);
|
|
121
|
+
regexRule = new RegexRule(type, pattern, regExp);
|
|
100
122
|
}
|
|
101
123
|
|
|
102
124
|
return regexRule;
|
package/bin/rule/string.js
CHANGED
|
@@ -4,19 +4,24 @@ const Occurrence = require("../occurrence");
|
|
|
4
4
|
|
|
5
5
|
const { STRING_TYPE } = require("../types"),
|
|
6
6
|
{ isStringStringLiteral } = require("../utilities/literal"),
|
|
7
|
-
{
|
|
7
|
+
{ removeDoubleQuotes, addTrailingForwardSlash, removeTrailingForwardSlash } = require("../utilities/string");
|
|
8
8
|
|
|
9
9
|
class StringRule {
|
|
10
|
-
constructor(string) {
|
|
10
|
+
constructor(type, string) {
|
|
11
|
+
this.type = type;
|
|
11
12
|
this.string = string;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
getType() {
|
|
16
|
+
return this.type;
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
getString() {
|
|
15
20
|
return this.string;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
toJSON() {
|
|
19
|
-
const type =
|
|
24
|
+
const type = this.type,
|
|
20
25
|
string = this.string,
|
|
21
26
|
json = {
|
|
22
27
|
type,
|
|
@@ -32,10 +37,11 @@ class StringRule {
|
|
|
32
37
|
|
|
33
38
|
let offset = 0,
|
|
34
39
|
string = content, ///
|
|
35
|
-
index = string.indexOf(this.string)
|
|
40
|
+
index = string.indexOf(this.string),
|
|
41
|
+
length = this.string.length;
|
|
36
42
|
|
|
37
43
|
while (index !== -1) {
|
|
38
|
-
const occurrence = Occurrence.
|
|
44
|
+
const occurrence = Occurrence.fromIndexLengthAndOffset(index, length, offset),
|
|
39
45
|
end = occurrence.getEnd(),
|
|
40
46
|
start = end; ///
|
|
41
47
|
|
|
@@ -45,24 +51,38 @@ class StringRule {
|
|
|
45
51
|
|
|
46
52
|
occurrences.push(occurrence);
|
|
47
53
|
|
|
48
|
-
index = string.
|
|
54
|
+
index = string.indexOf(this.string);
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
return occurrences;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
match(string) {
|
|
55
|
-
this.string = removeDoubleQuotes(this.string); ///
|
|
56
|
-
|
|
57
61
|
const matches = (this.string === string);
|
|
58
62
|
|
|
59
|
-
this.string = addDoubleQuotes(this.string); ///
|
|
60
|
-
|
|
61
63
|
return matches;
|
|
62
64
|
}
|
|
63
65
|
|
|
66
|
+
isEqualTo(rule) {
|
|
67
|
+
let equalTo = false;
|
|
68
|
+
|
|
69
|
+
const ruleType = rule.getType();
|
|
70
|
+
|
|
71
|
+
if (ruleType === this.type) {
|
|
72
|
+
const ruleString = rule.getString();
|
|
73
|
+
|
|
74
|
+
if (ruleString === this.string) {
|
|
75
|
+
equalTo = true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return equalTo;
|
|
80
|
+
}
|
|
81
|
+
|
|
64
82
|
asString() {
|
|
65
|
-
|
|
83
|
+
const string = `"${this.string}"`;
|
|
84
|
+
|
|
85
|
+
return string;
|
|
66
86
|
}
|
|
67
87
|
|
|
68
88
|
static fromJSON(json) {
|
|
@@ -73,7 +93,7 @@ class StringRule {
|
|
|
73
93
|
if (type === STRING_TYPE) {
|
|
74
94
|
const { string } = json;
|
|
75
95
|
|
|
76
|
-
stringRule = new StringRule(string);
|
|
96
|
+
stringRule = new StringRule(type, string);
|
|
77
97
|
}
|
|
78
98
|
|
|
79
99
|
return stringRule;
|
|
@@ -85,7 +105,9 @@ class StringRule {
|
|
|
85
105
|
string = stringFromStringAndDirectory(string, directory); ///
|
|
86
106
|
|
|
87
107
|
if (string !== null) {
|
|
88
|
-
|
|
108
|
+
const type = STRING_TYPE; ///
|
|
109
|
+
|
|
110
|
+
stringRule = new StringRule(type, string);
|
|
89
111
|
}
|
|
90
112
|
|
|
91
113
|
return stringRule;
|
|
@@ -107,8 +129,6 @@ function stringFromStringAndDirectory(string, directory) {
|
|
|
107
129
|
if (directory) {
|
|
108
130
|
string = addTrailingForwardSlash(string); ///
|
|
109
131
|
}
|
|
110
|
-
|
|
111
|
-
string = addDoubleQuotes(string); ///
|
|
112
132
|
} else {
|
|
113
133
|
string = null;
|
|
114
134
|
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { fileSystemUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const find = require("../find");
|
|
6
|
+
|
|
7
|
+
const { red, green } = require("../utilities/log"),
|
|
8
|
+
{ synchronousIsFilePathIgnored, synchronousIsDirectoryPathIgnored } = require("../isIgnored/synchronous"),
|
|
9
|
+
{ asynchronousIsFilePathIgnored, asynchronousIsDirectoryPathIgnored } = require("../isIgnored/asynchronous"),
|
|
10
|
+
{ isDirectoryPathRootDirectoryPath, entryPathsFromEntryNamesAndDirectoryPath } = require("../utilities/path");
|
|
11
|
+
|
|
12
|
+
const { readDirectory, isEntryDirectory } = fileSystemUtilities;
|
|
13
|
+
|
|
14
|
+
function findInEntries(entryPaths, callback, context) {
|
|
15
|
+
let synchronous = true;
|
|
16
|
+
|
|
17
|
+
let entryNamesLength;
|
|
18
|
+
|
|
19
|
+
entryNamesLength = entryPaths.length;
|
|
20
|
+
|
|
21
|
+
while (entryNamesLength > 0) {
|
|
22
|
+
const entryPath = entryPaths.shift();
|
|
23
|
+
|
|
24
|
+
synchronous = findInEntry(entryPath, entryPaths, callback, context);
|
|
25
|
+
|
|
26
|
+
if (!synchronous) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
entryNamesLength = entryPaths.length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return synchronous;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
findInEntries
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function findInEntry(entryPath, entryPaths, callback, context) {
|
|
41
|
+
let synchronous;
|
|
42
|
+
|
|
43
|
+
const path = entryPath,
|
|
44
|
+
directory = isEntryDirectory(path);
|
|
45
|
+
|
|
46
|
+
if (directory) {
|
|
47
|
+
const directoryPath = entryPath; ///
|
|
48
|
+
|
|
49
|
+
synchronous = findInDirectory(directoryPath, (pathIgnored) => {
|
|
50
|
+
const synchronous = (pathIgnored !== null) ?
|
|
51
|
+
findInEntries(entryPaths, callback, context) :
|
|
52
|
+
true;
|
|
53
|
+
|
|
54
|
+
if (synchronous) {
|
|
55
|
+
callback(pathIgnored);
|
|
56
|
+
}
|
|
57
|
+
}, context);
|
|
58
|
+
} else {
|
|
59
|
+
const filePath = entryPath; ///
|
|
60
|
+
|
|
61
|
+
synchronous = findInFile(filePath, (pathIgnored) => {
|
|
62
|
+
const synchronous = (pathIgnored !== null) ?
|
|
63
|
+
findInEntries(entryPaths, callback, context) :
|
|
64
|
+
true;
|
|
65
|
+
if (synchronous) {
|
|
66
|
+
callback(pathIgnored);
|
|
67
|
+
}
|
|
68
|
+
}, context);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (synchronous) {
|
|
72
|
+
synchronous = findInEntries(entryPaths, callback, context);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return synchronous;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function findInFile(filePath, callback, context) {
|
|
79
|
+
let synchronous;
|
|
80
|
+
|
|
81
|
+
const filePathIgnored = synchronousIsFilePathIgnored(filePath, context);
|
|
82
|
+
|
|
83
|
+
if (filePathIgnored !== null) {
|
|
84
|
+
synchronous = true;
|
|
85
|
+
|
|
86
|
+
const { quietly } = context;
|
|
87
|
+
|
|
88
|
+
if (!quietly) {
|
|
89
|
+
let message;
|
|
90
|
+
|
|
91
|
+
const { format, ruleString } = context;
|
|
92
|
+
|
|
93
|
+
message = filePathIgnored ?
|
|
94
|
+
`Ignore ${filePath}`:
|
|
95
|
+
`Permit ${filePath}`;
|
|
96
|
+
|
|
97
|
+
if (format) {
|
|
98
|
+
message = filePathIgnored ?
|
|
99
|
+
red(message) :
|
|
100
|
+
green(message);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
message = `${message} ${ruleString}`;
|
|
104
|
+
|
|
105
|
+
console.log(message);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!filePathIgnored) {
|
|
109
|
+
let { filesTotal } = context;
|
|
110
|
+
|
|
111
|
+
filesTotal++;
|
|
112
|
+
|
|
113
|
+
Object.assign(context, {
|
|
114
|
+
filesTotal
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const { dryRun } = context;
|
|
118
|
+
|
|
119
|
+
if (!dryRun) {
|
|
120
|
+
find(filePath, context);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
synchronous = false;
|
|
125
|
+
|
|
126
|
+
asynchronousIsFilePathIgnored(filePath, context, (pathIgnored) => {
|
|
127
|
+
const synchronous = (pathIgnored !== null) ?
|
|
128
|
+
findInFile(filePath, callback, context) :
|
|
129
|
+
true;
|
|
130
|
+
|
|
131
|
+
if (synchronous) {
|
|
132
|
+
callback(pathIgnored);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return synchronous;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function findInDirectory(directoryPath, callback, context) {
|
|
141
|
+
let synchronous;
|
|
142
|
+
|
|
143
|
+
const directoryPathIgnored = synchronousIsDirectoryPathIgnored(directoryPath, context);
|
|
144
|
+
|
|
145
|
+
if (directoryPathIgnored !== null) {
|
|
146
|
+
synchronous = true;
|
|
147
|
+
|
|
148
|
+
const directoryPathRootDirectoryPath = isDirectoryPathRootDirectoryPath(directoryPath, context);
|
|
149
|
+
|
|
150
|
+
if (!directoryPathRootDirectoryPath) {
|
|
151
|
+
const { quietly } = context;
|
|
152
|
+
|
|
153
|
+
if (!quietly) {
|
|
154
|
+
let message;
|
|
155
|
+
|
|
156
|
+
const { format, ruleString } = context;
|
|
157
|
+
|
|
158
|
+
message = directoryPathIgnored ?
|
|
159
|
+
`Ignore ${directoryPath}/` :
|
|
160
|
+
`Permit ${directoryPath}/`;
|
|
161
|
+
|
|
162
|
+
if (format) {
|
|
163
|
+
message = directoryPathIgnored ?
|
|
164
|
+
red(message) :
|
|
165
|
+
green(message);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
message = `${message} ${ruleString}`;
|
|
169
|
+
|
|
170
|
+
console.log(message);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!directoryPathIgnored) {
|
|
175
|
+
let { directoriesTotal } = context;
|
|
176
|
+
|
|
177
|
+
directoriesTotal++;
|
|
178
|
+
|
|
179
|
+
Object.assign(context, {
|
|
180
|
+
directoriesTotal
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const entryNames = readDirectory(directoryPath),
|
|
184
|
+
entryPaths = entryPathsFromEntryNamesAndDirectoryPath(entryNames, directoryPath);
|
|
185
|
+
|
|
186
|
+
synchronous = findInEntries(entryPaths, callback, context);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
synchronous = false;
|
|
190
|
+
|
|
191
|
+
asynchronousIsDirectoryPathIgnored(directoryPath, context, (pathIgnored) => {
|
|
192
|
+
const synchronous = (pathIgnored !== null) ?
|
|
193
|
+
findInDirectory(directoryPath, callback, context) :
|
|
194
|
+
true;
|
|
195
|
+
|
|
196
|
+
if (synchronous) {
|
|
197
|
+
callback(pathIgnored);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return synchronous;
|
|
203
|
+
}
|