find-cli 1.6.2 → 1.6.4
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/bin/action/find.js +0 -4
- package/bin/isIgnored/asynchronous.js +5 -11
- package/bin/occurrence.js +2 -3
- package/bin/operation/find.js +4 -0
- package/bin/operation/prompt/pathRule.js +51 -0
- package/bin/operation/rule.js +3 -1
- package/bin/operation/updatePatRules.js +9 -9
- package/bin/rule/string.js +5 -10
- package/bin/utilities/string.js +0 -3
- package/package.json +1 -1
package/bin/action/find.js
CHANGED
|
@@ -17,8 +17,6 @@ function findAction(string, dryRun, format, quietly, interactive) {
|
|
|
17
17
|
],
|
|
18
18
|
rule = null,
|
|
19
19
|
lines = [],
|
|
20
|
-
anchored = false,
|
|
21
|
-
directory = false,
|
|
22
20
|
linesTotal = 0,
|
|
23
21
|
filesTotal = 0,
|
|
24
22
|
directoriesTotal = 0,
|
|
@@ -31,8 +29,6 @@ function findAction(string, dryRun, format, quietly, interactive) {
|
|
|
31
29
|
interactive,
|
|
32
30
|
rule,
|
|
33
31
|
lines,
|
|
34
|
-
anchored,
|
|
35
|
-
directory,
|
|
36
32
|
linesTotal,
|
|
37
33
|
filesTotal,
|
|
38
34
|
directoriesTotal,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const pathRulePromptOperation = require("../operation/prompt/pathRule"),
|
|
4
4
|
updatePathRulesOperation = require("../operation/updatePatRules"),
|
|
5
5
|
ignoreOrPermitPathPromptOperation = require("../operation/prompt/ignoreOrPermitPath");
|
|
6
6
|
|
|
@@ -33,31 +33,25 @@ module.exports = {
|
|
|
33
33
|
function asynchronousIsPathIgnored(path, directory, context, callback) {
|
|
34
34
|
const operations = [
|
|
35
35
|
ignoreOrPermitPathPromptOperation,
|
|
36
|
-
|
|
36
|
+
pathRulePromptOperation,
|
|
37
37
|
updatePathRulesOperation
|
|
38
38
|
],
|
|
39
|
-
|
|
40
|
-
dryRun = false,
|
|
41
|
-
anchored = true,
|
|
42
|
-
interactive = true,
|
|
39
|
+
pathRule = null,
|
|
43
40
|
pathIgnored = null;
|
|
44
41
|
|
|
45
42
|
Object.assign(context, {
|
|
46
43
|
path,
|
|
47
44
|
directory,
|
|
48
|
-
|
|
49
|
-
dryRun,
|
|
50
|
-
anchored,
|
|
51
|
-
interactive,
|
|
45
|
+
pathRule,
|
|
52
46
|
pathIgnored
|
|
53
47
|
});
|
|
54
48
|
|
|
55
49
|
executeOperations(operations, (completed) => {
|
|
56
50
|
const { pathIgnored } = context;
|
|
57
51
|
|
|
58
|
-
delete context.rule;
|
|
59
52
|
delete context.path;
|
|
60
53
|
delete context.directory;
|
|
54
|
+
delete context.pathRule;
|
|
61
55
|
delete context.pathIgnored;
|
|
62
56
|
|
|
63
57
|
callback(pathIgnored);
|
package/bin/occurrence.js
CHANGED
|
@@ -27,9 +27,8 @@ class Occurrence {
|
|
|
27
27
|
return occurrence;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
static
|
|
31
|
-
const
|
|
32
|
-
start = index + offset,
|
|
30
|
+
static fromIndexLengthAndOffset(index, length, offset) {
|
|
31
|
+
const start = index + offset,
|
|
33
32
|
end = start + length,
|
|
34
33
|
occurrence = new Occurrence(start, end);
|
|
35
34
|
|
package/bin/operation/find.js
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { shellUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { validateGlobStringOrPattern } = require("../../utilities/validate"),
|
|
6
|
+
{ GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../../descriptions"),
|
|
7
|
+
{ ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
|
|
8
|
+
{ INVALID_GLOB_REGEX_OR_STRING_MESSAGE } = require("../../messages");
|
|
9
|
+
|
|
10
|
+
const { prompt } = shellUtilities;
|
|
11
|
+
|
|
12
|
+
function pathRulePromptOperation(proceed, abort, context) {
|
|
13
|
+
const { path, directory } = context,
|
|
14
|
+
anchored = true,
|
|
15
|
+
description = GLOB_STRING_OR_REGEX_DESCRIPTION,
|
|
16
|
+
errorMessage = INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
17
|
+
initialAnswer = path, ///
|
|
18
|
+
validationFunction = (answer) => {
|
|
19
|
+
const valid = validateGlobStringOrPattern(answer, anchored, directory);
|
|
20
|
+
|
|
21
|
+
return valid;
|
|
22
|
+
},
|
|
23
|
+
options = {
|
|
24
|
+
description,
|
|
25
|
+
errorMessage,
|
|
26
|
+
initialAnswer,
|
|
27
|
+
validationFunction
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
prompt(options, (answer) => {
|
|
31
|
+
const valid = (answer !== null);
|
|
32
|
+
|
|
33
|
+
if(!valid) {
|
|
34
|
+
abort();
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const string = answer, ///
|
|
40
|
+
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory),
|
|
41
|
+
pathRule = rule; ///
|
|
42
|
+
|
|
43
|
+
Object.assign(context, {
|
|
44
|
+
pathRule
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
proceed();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = pathRulePromptOperation;
|
package/bin/operation/rule.js
CHANGED
|
@@ -19,7 +19,9 @@ function ruleOperation(proceed, abort, context) {
|
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const { string
|
|
22
|
+
const { string } = context,
|
|
23
|
+
anchored = true,
|
|
24
|
+
directory = false,
|
|
23
25
|
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory);
|
|
24
26
|
|
|
25
27
|
if (rule === null) {
|
|
@@ -6,28 +6,28 @@ const { updateIgnoredFilePathRules,
|
|
|
6
6
|
updatePermittedDirectoryPathRules } = require("../configuration");
|
|
7
7
|
|
|
8
8
|
function updatePathRulesOperation(proceed, abort, context) {
|
|
9
|
-
const {
|
|
9
|
+
const { pathRule, directory, pathIgnored } = context;
|
|
10
10
|
|
|
11
11
|
pathIgnored ?
|
|
12
|
-
addIgnoreRule(
|
|
13
|
-
addPermitRule(
|
|
12
|
+
addIgnoreRule(pathRule, directory, context) :
|
|
13
|
+
addPermitRule(pathRule, directory, context);
|
|
14
14
|
|
|
15
15
|
proceed();
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
module.exports = updatePathRulesOperation;
|
|
19
19
|
|
|
20
|
-
function addIgnoreRule(
|
|
20
|
+
function addIgnoreRule(pathRule, directory, context) {
|
|
21
21
|
if (directory) {
|
|
22
22
|
const { ignoredDirectoryPathRules } = context,
|
|
23
|
-
ignoredDirectoryPathRule =
|
|
23
|
+
ignoredDirectoryPathRule = pathRule; ///
|
|
24
24
|
|
|
25
25
|
ignoredDirectoryPathRules.push(ignoredDirectoryPathRule);
|
|
26
26
|
|
|
27
27
|
updateIgnoredDirectoryPathRules(ignoredDirectoryPathRules);
|
|
28
28
|
} else {
|
|
29
29
|
const { ignoredFilePathRules } = context,
|
|
30
|
-
ignoredFilePathRule =
|
|
30
|
+
ignoredFilePathRule = pathRule; ///
|
|
31
31
|
|
|
32
32
|
ignoredFilePathRules.push(ignoredFilePathRule);
|
|
33
33
|
|
|
@@ -35,17 +35,17 @@ function addIgnoreRule(rule, directory, context) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function addPermitRule(
|
|
38
|
+
function addPermitRule(pathRule, directory, context) {
|
|
39
39
|
if (directory) {
|
|
40
40
|
const { permittedDirectoryPathRules } = context,
|
|
41
|
-
permittedDirectoryPathRule =
|
|
41
|
+
permittedDirectoryPathRule = pathRule; ///
|
|
42
42
|
|
|
43
43
|
permittedDirectoryPathRules.push(permittedDirectoryPathRule);
|
|
44
44
|
|
|
45
45
|
updatePermittedDirectoryPathRules(permittedDirectoryPathRules);
|
|
46
46
|
} else {
|
|
47
47
|
const { permittedFilePathRules } = context,
|
|
48
|
-
permittedFilePathRule =
|
|
48
|
+
permittedFilePathRule = pathRule; ///
|
|
49
49
|
|
|
50
50
|
permittedFilePathRules.push(permittedFilePathRule);
|
|
51
51
|
|
package/bin/rule/string.js
CHANGED
|
@@ -4,7 +4,7 @@ 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
10
|
constructor(string) {
|
|
@@ -32,10 +32,11 @@ class StringRule {
|
|
|
32
32
|
|
|
33
33
|
let offset = 0,
|
|
34
34
|
string = content, ///
|
|
35
|
-
index = string.indexOf(this.string)
|
|
35
|
+
index = string.indexOf(this.string),
|
|
36
|
+
length = this.string.length;
|
|
36
37
|
|
|
37
38
|
while (index !== -1) {
|
|
38
|
-
const occurrence = Occurrence.
|
|
39
|
+
const occurrence = Occurrence.fromIndexLengthAndOffset(index, length, offset),
|
|
39
40
|
end = occurrence.getEnd(),
|
|
40
41
|
start = end; ///
|
|
41
42
|
|
|
@@ -45,19 +46,15 @@ class StringRule {
|
|
|
45
46
|
|
|
46
47
|
occurrences.push(occurrence);
|
|
47
48
|
|
|
48
|
-
index = string.
|
|
49
|
+
index = string.indexOf(this.string);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
return occurrences;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
match(string) {
|
|
55
|
-
this.string = removeDoubleQuotes(this.string); ///
|
|
56
|
-
|
|
57
56
|
const matches = (this.string === string);
|
|
58
57
|
|
|
59
|
-
this.string = addDoubleQuotes(this.string); ///
|
|
60
|
-
|
|
61
58
|
return matches;
|
|
62
59
|
}
|
|
63
60
|
|
|
@@ -107,8 +104,6 @@ function stringFromStringAndDirectory(string, directory) {
|
|
|
107
104
|
if (directory) {
|
|
108
105
|
string = addTrailingForwardSlash(string); ///
|
|
109
106
|
}
|
|
110
|
-
|
|
111
|
-
string = addDoubleQuotes(string); ///
|
|
112
107
|
} else {
|
|
113
108
|
string = null;
|
|
114
109
|
}
|
package/bin/utilities/string.js
CHANGED
|
@@ -6,8 +6,6 @@ function addAnchors(string) { return `^${string}$`; }
|
|
|
6
6
|
|
|
7
7
|
function removeAnchors(string) { return string.replace(/(^\^|\$$)/g, EMPTY_STRING); }
|
|
8
8
|
|
|
9
|
-
function addDoubleQuotes(string) { return `"${string}"`; }
|
|
10
|
-
|
|
11
9
|
function addForwardSlashes(string) { return `/${string}/`; }
|
|
12
10
|
|
|
13
11
|
function removeDoubleQuotes(string) { return string.replace(/(^"|"$)/g, EMPTY_STRING); }
|
|
@@ -25,7 +23,6 @@ function removeTrailingEscapedForwardSlash(string) { return string.replace(/(\\\
|
|
|
25
23
|
module.exports = {
|
|
26
24
|
addAnchors,
|
|
27
25
|
removeAnchors,
|
|
28
|
-
addDoubleQuotes,
|
|
29
26
|
addForwardSlashes,
|
|
30
27
|
removeDoubleQuotes,
|
|
31
28
|
removeForwardSlashes,
|