find-cli 0.0.3 → 1.4.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/README.md +43 -5
- package/bin/abbreviations.js +10 -0
- package/bin/action/addRootDirectoryPath.js +31 -0
- package/bin/action/find.js +84 -0
- package/bin/action/help.js +40 -0
- package/bin/action/initialise.js +18 -0
- package/bin/action/listRootDirectoryPaths.js +18 -0
- package/bin/action/removeRootDirectoryPath.js +33 -0
- package/bin/action/version.js +15 -0
- package/bin/commands.js +19 -0
- package/bin/configuration/version_1_1.js +26 -0
- package/bin/configuration/version_1_2.js +48 -0
- package/bin/configuration/version_1_3.js +22 -0
- package/bin/configuration/version_1_4.js +58 -0
- package/bin/configuration.js +230 -0
- package/bin/constants.js +25 -0
- package/bin/converter/alternates.js +29 -0
- package/bin/converter/characterClass.js +45 -0
- package/bin/converter/default.js +19 -0
- package/bin/converter/directory.js +19 -0
- package/bin/converter/escapedCharacter.js +19 -0
- package/bin/converter/period.js +19 -0
- package/bin/converter/questionMark.js +19 -0
- package/bin/converter/repeatedDirectories.js +19 -0
- package/bin/converter/repeatedWildcard.js +19 -0
- package/bin/converter/singleDirectory.js +19 -0
- package/bin/converter/singleWildcard.js +19 -0
- package/bin/converter.js +48 -0
- package/bin/converters.js +29 -0
- package/bin/defaults.js +13 -0
- package/bin/descriptions.js +11 -0
- package/bin/find.js +55 -0
- package/bin/isIgnored/asynchronous.js +59 -0
- package/bin/isIgnored/synchronous.js +104 -0
- package/bin/line.js +181 -0
- package/bin/main.js +85 -0
- package/bin/messages.js +37 -0
- package/bin/occurrence.js +40 -0
- package/bin/operation/addRootDirectoryPath.js +16 -0
- package/bin/operation/find.js +201 -0
- package/bin/operation/listRootDirectoryPaths.js +34 -0
- package/bin/operation/prompt/addRootDirectoryPath.js +48 -0
- package/bin/operation/prompt/ignoreOrPermitPath.js +46 -0
- package/bin/operation/prompt/removeRootDirectoryPath.js +61 -0
- package/bin/operation/prompt/rule.js +50 -0
- package/bin/operation/readConfiguration.js +27 -0
- package/bin/operation/removeRootDirectoryPath.js +29 -0
- package/bin/operation/removeRootDirectoryPathByIndex.js +34 -0
- package/bin/operation/rule.js +32 -0
- package/bin/operation/updatePatRules.js +54 -0
- package/bin/operation/validateRootDirectoryPath.js +30 -0
- package/bin/options.js +13 -0
- package/bin/prepare.js +51 -0
- package/bin/rule/glob.js +170 -0
- package/bin/rule/regex.js +141 -0
- package/bin/rule/string.js +117 -0
- package/bin/types.js +11 -0
- package/bin/utilities/literal.js +19 -0
- package/bin/utilities/log.js +26 -0
- package/bin/utilities/operation.js +38 -0
- package/bin/utilities/path.js +58 -0
- package/bin/utilities/prompt.js +7 -0
- package/bin/utilities/rule.js +18 -0
- package/bin/utilities/string.js +36 -0
- package/bin/utilities/validate.js +56 -0
- package/bin/versions.js +15 -0
- package/find.js +18 -0
- package/package.json +5 -2
package/bin/prepare.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { migrateConfigurationFile } = require("./configuration"),
|
|
4
|
+
{ DEFAULT_HELP, DEFAULT_VERSION } = require("./defaults"),
|
|
5
|
+
{ FIND_COMMAND,
|
|
6
|
+
HELP_COMMAND,
|
|
7
|
+
VERSION_COMMAND,
|
|
8
|
+
INITIALISE_COMMAND,
|
|
9
|
+
ADD_ROOT_DIRECTORY_PATH_COMMAND,
|
|
10
|
+
LIST_ROOT_DIRECTORY_PATHS_COMMAND,
|
|
11
|
+
REMOVE_ROOT_DIRECTORY_PATH_COMMAND } = require("./commands");
|
|
12
|
+
|
|
13
|
+
function prepare(command, argument, options, main) {
|
|
14
|
+
const { help = DEFAULT_HELP, version = DEFAULT_VERSION } = options;
|
|
15
|
+
|
|
16
|
+
if (false) {
|
|
17
|
+
///
|
|
18
|
+
} else if (help) {
|
|
19
|
+
command = HELP_COMMAND;
|
|
20
|
+
} else if (version) {
|
|
21
|
+
command = VERSION_COMMAND;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ((command === HELP_COMMAND) ||
|
|
25
|
+
(command === VERSION_COMMAND) ||
|
|
26
|
+
(command === INITIALISE_COMMAND)) {
|
|
27
|
+
|
|
28
|
+
main(command, argument, options);
|
|
29
|
+
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
migrateConfigurationFile();
|
|
34
|
+
|
|
35
|
+
if ((command === ADD_ROOT_DIRECTORY_PATH_COMMAND) ||
|
|
36
|
+
(command === LIST_ROOT_DIRECTORY_PATHS_COMMAND) ||
|
|
37
|
+
(command === REMOVE_ROOT_DIRECTORY_PATH_COMMAND)) {
|
|
38
|
+
|
|
39
|
+
main(command, argument, options);
|
|
40
|
+
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
argument = command; ///
|
|
45
|
+
|
|
46
|
+
command = FIND_COMMAND;
|
|
47
|
+
|
|
48
|
+
main(command, argument, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = prepare;
|
package/bin/rule/glob.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const converters = require("../converters"),
|
|
4
|
+
Occurrence = require("../occurrence");
|
|
5
|
+
|
|
6
|
+
const { GLOB_TYPE } = require("../types"),
|
|
7
|
+
{ EMPTY_STRING } = require("../constants"),
|
|
8
|
+
{ isStringGlobLiteral } = require("../utilities/literal"),
|
|
9
|
+
{ addAnchors, addTrailingForwardSlash, removeTrailingForwardSlash } = require("../utilities/string");
|
|
10
|
+
|
|
11
|
+
class GlobRule {
|
|
12
|
+
constructor(glob, pattern, regExp) {
|
|
13
|
+
this.glob = glob;
|
|
14
|
+
this.pattern = pattern;
|
|
15
|
+
this.regExp = regExp;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getGlob() {
|
|
19
|
+
return this.glob;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getPattern() {
|
|
23
|
+
return this.pattern;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getRegExp() {
|
|
27
|
+
return this.regExp;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
toJSON() {
|
|
31
|
+
const type = GLOB_TYPE,
|
|
32
|
+
glob = this.glob,
|
|
33
|
+
pattern = this.pattern,
|
|
34
|
+
json = {
|
|
35
|
+
type,
|
|
36
|
+
glob,
|
|
37
|
+
pattern
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return json;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
find(line) {
|
|
44
|
+
const occurrences = [],
|
|
45
|
+
content = line.getContent();
|
|
46
|
+
|
|
47
|
+
let offset = 0,
|
|
48
|
+
string = content, ///
|
|
49
|
+
result = string.match(this.regExp);
|
|
50
|
+
|
|
51
|
+
while (result !== null) {
|
|
52
|
+
const occurrence = Occurrence.fromResultAndOffset(result, offset),
|
|
53
|
+
end = occurrence.getEnd(),
|
|
54
|
+
start = end; ///
|
|
55
|
+
|
|
56
|
+
string = string.substring(start); ///
|
|
57
|
+
|
|
58
|
+
offset += start;
|
|
59
|
+
|
|
60
|
+
occurrences.push(occurrence);
|
|
61
|
+
|
|
62
|
+
result = string.match(this.regExp);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return occurrences;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
match(string) {
|
|
69
|
+
const matches = this.regExp.test(string);
|
|
70
|
+
|
|
71
|
+
return matches;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
asString() {
|
|
75
|
+
const string = this.glob; ///
|
|
76
|
+
|
|
77
|
+
return string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static fromJSON(json) {
|
|
81
|
+
let globRule = null;
|
|
82
|
+
|
|
83
|
+
const { type } = json;
|
|
84
|
+
|
|
85
|
+
if (type === GLOB_TYPE) {
|
|
86
|
+
const { glob, pattern } = json,
|
|
87
|
+
regExp = new RegExp(pattern);
|
|
88
|
+
|
|
89
|
+
globRule = new GlobRule(glob, pattern, regExp);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return globRule;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static fromStringAnchoredAndDirectory(string, anchored, directory) {
|
|
96
|
+
let globRule = null;
|
|
97
|
+
|
|
98
|
+
const glob = globFromStringAndDirectory(string, directory);
|
|
99
|
+
|
|
100
|
+
if (glob !== null) {
|
|
101
|
+
const pattern = patternFromGlobAndAnchored(glob, anchored),
|
|
102
|
+
regExp = new RegExp(pattern);
|
|
103
|
+
|
|
104
|
+
globRule = new GlobRule(glob, pattern, regExp);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return globRule;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = GlobRule;
|
|
112
|
+
|
|
113
|
+
function patternFromGlobAndAnchored(glob, anchored) {
|
|
114
|
+
let pattern = EMPTY_STRING;
|
|
115
|
+
|
|
116
|
+
const characters = [ ...glob ];
|
|
117
|
+
|
|
118
|
+
for (;;) {
|
|
119
|
+
const converted = converters.some((converter) => {
|
|
120
|
+
const result = converter.match(characters);
|
|
121
|
+
|
|
122
|
+
if (result !== null) {
|
|
123
|
+
pattern = `${pattern}${result}`;
|
|
124
|
+
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (!converted) {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (anchored) {
|
|
135
|
+
pattern = addAnchors(pattern);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return pattern;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function globFromStringAndDirectory(string, directory) {
|
|
142
|
+
let glob;
|
|
143
|
+
|
|
144
|
+
const stringGlobLiteral = isStringGlobLiteral(string);
|
|
145
|
+
|
|
146
|
+
if (stringGlobLiteral) {
|
|
147
|
+
const globLiteral = string; ///
|
|
148
|
+
|
|
149
|
+
glob = globLiteral; ///
|
|
150
|
+
|
|
151
|
+
glob = removeTrailingForwardSlash(glob); ///
|
|
152
|
+
|
|
153
|
+
if (directory) {
|
|
154
|
+
glob = addTrailingForwardSlash(glob); ///
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
const anchored = false,
|
|
159
|
+
pattern = patternFromGlobAndAnchored(glob, anchored);
|
|
160
|
+
|
|
161
|
+
new RegExp(pattern);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
glob = null;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
glob = null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return glob;
|
|
170
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Occurrence = require("../occurrence");
|
|
4
|
+
|
|
5
|
+
const { REGEX_TYPE } = require("../types"),
|
|
6
|
+
{ isStringRegexLiteral } = require("../utilities/literal"),
|
|
7
|
+
{ addAnchors,
|
|
8
|
+
removeAnchors,
|
|
9
|
+
addForwardSlashes,
|
|
10
|
+
removeForwardSlashes,
|
|
11
|
+
addTrailingEscapedForwardSlash,
|
|
12
|
+
removeTrailingEscapedForwardSlash } = require("../utilities/string");
|
|
13
|
+
|
|
14
|
+
class RegexRule {
|
|
15
|
+
constructor(pattern, regExp) {
|
|
16
|
+
this.pattern = pattern;
|
|
17
|
+
this.regExp = regExp;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getPattern() {
|
|
21
|
+
return this.pattern;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getRegExp() {
|
|
25
|
+
return this.regExp;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
toJSON() {
|
|
29
|
+
const type = REGEX_TYPE,
|
|
30
|
+
pattern = this.pattern,
|
|
31
|
+
json = {
|
|
32
|
+
type,
|
|
33
|
+
pattern
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return json;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
find(line) {
|
|
40
|
+
const occurrences = [],
|
|
41
|
+
content = line.getContent();
|
|
42
|
+
|
|
43
|
+
let offset = 0,
|
|
44
|
+
string = content, ///
|
|
45
|
+
result = string.match(this.regExp);
|
|
46
|
+
|
|
47
|
+
while (result !== null) {
|
|
48
|
+
const occurrence = Occurrence.fromResultAndOffset(result, offset),
|
|
49
|
+
end = occurrence.getEnd(),
|
|
50
|
+
start = end; ///
|
|
51
|
+
|
|
52
|
+
string = string.substring(start); ///
|
|
53
|
+
|
|
54
|
+
offset += start;
|
|
55
|
+
|
|
56
|
+
occurrences.push(occurrence);
|
|
57
|
+
|
|
58
|
+
result = string.match(this.regExp);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return occurrences;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
match(string) {
|
|
65
|
+
const matches = this.regExp.test(string);
|
|
66
|
+
|
|
67
|
+
return matches;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
asString() {
|
|
71
|
+
const string = addForwardSlashes(this.pattern); ///
|
|
72
|
+
|
|
73
|
+
return string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static fromJSON(json) {
|
|
77
|
+
let regexRule = null;
|
|
78
|
+
|
|
79
|
+
const { type } = json;
|
|
80
|
+
|
|
81
|
+
if (type === REGEX_TYPE) {
|
|
82
|
+
const { pattern } = json,
|
|
83
|
+
regExp = new RegExp(pattern);
|
|
84
|
+
|
|
85
|
+
regexRule = new RegexRule(pattern, regExp);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return regexRule;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static fromStringAnchoredAndDirectory(string, anchored, directory) {
|
|
92
|
+
let regexRule = null;
|
|
93
|
+
|
|
94
|
+
const pattern = patternFromStringAndDirectory(string, anchored, directory);
|
|
95
|
+
|
|
96
|
+
if (pattern !== null) {
|
|
97
|
+
const regExp = new RegExp(pattern);
|
|
98
|
+
|
|
99
|
+
regexRule = new RegexRule(pattern, regExp);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return regexRule;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = RegexRule;
|
|
107
|
+
|
|
108
|
+
function patternFromStringAndDirectory(string, anchored, directory) {
|
|
109
|
+
let pattern;
|
|
110
|
+
|
|
111
|
+
const stringRegexLiteral = isStringRegexLiteral(string);
|
|
112
|
+
|
|
113
|
+
if (stringRegexLiteral) {
|
|
114
|
+
const regexLiteral = string; ///
|
|
115
|
+
|
|
116
|
+
pattern = removeForwardSlashes(regexLiteral);
|
|
117
|
+
|
|
118
|
+
pattern = removeAnchors(pattern); ///
|
|
119
|
+
|
|
120
|
+
pattern = removeTrailingEscapedForwardSlash(pattern); ///
|
|
121
|
+
|
|
122
|
+
if (directory) {
|
|
123
|
+
pattern = addTrailingEscapedForwardSlash(pattern); ///
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (anchored) {
|
|
127
|
+
pattern = addAnchors(pattern);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
new RegExp(pattern);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
pattern = null;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
pattern = null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return pattern;
|
|
140
|
+
}
|
|
141
|
+
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Occurrence = require("../occurrence");
|
|
4
|
+
|
|
5
|
+
const { STRING_TYPE } = require("../types"),
|
|
6
|
+
{ isStringStringLiteral } = require("../utilities/literal"),
|
|
7
|
+
{ addDoubleQuotes, removeDoubleQuotes, addTrailingForwardSlash, removeTrailingForwardSlash } = require("../utilities/string");
|
|
8
|
+
|
|
9
|
+
class StringRule {
|
|
10
|
+
constructor(string) {
|
|
11
|
+
this.string = string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getString() {
|
|
15
|
+
return this.string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
toJSON() {
|
|
19
|
+
const type = STRING_TYPE,
|
|
20
|
+
string = this.string,
|
|
21
|
+
json = {
|
|
22
|
+
type,
|
|
23
|
+
string
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return json;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
find(line) {
|
|
30
|
+
const occurrences = [],
|
|
31
|
+
content = line.getContent();
|
|
32
|
+
|
|
33
|
+
let offset = 0,
|
|
34
|
+
string = content, ///
|
|
35
|
+
index = string.indexOf(this.string);
|
|
36
|
+
|
|
37
|
+
while (index !== -1) {
|
|
38
|
+
const occurrence = Occurrence.fromIndexStringAndOffset(index, string, offset),
|
|
39
|
+
end = occurrence.getEnd(),
|
|
40
|
+
start = end; ///
|
|
41
|
+
|
|
42
|
+
string = string.substring(start); ///
|
|
43
|
+
|
|
44
|
+
offset += start;
|
|
45
|
+
|
|
46
|
+
occurrences.push(occurrence);
|
|
47
|
+
|
|
48
|
+
index = string.match(this.regExp);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return occurrences;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
match(string) {
|
|
55
|
+
this.string = removeDoubleQuotes(this.string); ///
|
|
56
|
+
|
|
57
|
+
const matches = (this.string === string);
|
|
58
|
+
|
|
59
|
+
this.string = addDoubleQuotes(this.string); ///
|
|
60
|
+
|
|
61
|
+
return matches;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
asString() {
|
|
65
|
+
return this.string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static fromJSON(json) {
|
|
69
|
+
let stringRule = null;
|
|
70
|
+
|
|
71
|
+
const { type } = json;
|
|
72
|
+
|
|
73
|
+
if (type === STRING_TYPE) {
|
|
74
|
+
const { string } = json;
|
|
75
|
+
|
|
76
|
+
stringRule = new StringRule(string);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return stringRule;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static fromStringAnchoredAndDirectory(string, anchored, directory) {
|
|
83
|
+
let stringRule = null;
|
|
84
|
+
|
|
85
|
+
string = stringFromStringAndDirectory(string, directory); ///
|
|
86
|
+
|
|
87
|
+
if (string !== null) {
|
|
88
|
+
stringRule = new StringRule(string);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return stringRule;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = StringRule;
|
|
96
|
+
|
|
97
|
+
function stringFromStringAndDirectory(string, directory) {
|
|
98
|
+
const stringStringLiteral = isStringStringLiteral(string);
|
|
99
|
+
|
|
100
|
+
if (stringStringLiteral) {
|
|
101
|
+
const stringLiteral = string; ///
|
|
102
|
+
|
|
103
|
+
string = removeDoubleQuotes(stringLiteral); ///
|
|
104
|
+
|
|
105
|
+
string = removeTrailingForwardSlash(string); ///
|
|
106
|
+
|
|
107
|
+
if (directory) {
|
|
108
|
+
string = addTrailingForwardSlash(string); ///
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
string = addDoubleQuotes(string); ///
|
|
112
|
+
} else {
|
|
113
|
+
string = null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return string;
|
|
117
|
+
}
|
package/bin/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function isStringGlobLiteral(string) {
|
|
4
|
+
const stringStringLiteral = isStringStringLiteral(string),
|
|
5
|
+
stringRegexLiteral = isStringRegexLiteral(string),
|
|
6
|
+
stringGlobLiteral = (!stringStringLiteral && !stringRegexLiteral);
|
|
7
|
+
|
|
8
|
+
return stringGlobLiteral;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isStringRegexLiteral(string) { return /^\/.*?\/$/.test(string); }
|
|
12
|
+
|
|
13
|
+
function isStringStringLiteral(string) { return /^".*?"$/.test(string); }
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
isStringGlobLiteral,
|
|
17
|
+
isStringRegexLiteral,
|
|
18
|
+
isStringStringLiteral
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const GREY_FOREGROUND_COLOUR = "\u001b[90m",
|
|
4
|
+
RED_FOREGROUND_COLOUR = "\u001b[31m",
|
|
5
|
+
BLUE_FOREGROUND_COLOUR = "\u001b[34m",
|
|
6
|
+
GREEN_FOREGROUND_COLOUR = "\u001b[32m",
|
|
7
|
+
YELLOW_FOREGROUND_COLOUR = "\u001b[33m",
|
|
8
|
+
RESET_FOREGROUND_COLOUR = "\u001b[39m";
|
|
9
|
+
|
|
10
|
+
function grey(string) { return `${GREY_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
11
|
+
|
|
12
|
+
function red(string) { return `${RED_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
13
|
+
|
|
14
|
+
function blue(string) { return `${BLUE_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
15
|
+
|
|
16
|
+
function green(string) { return `${GREEN_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
17
|
+
|
|
18
|
+
function yellow(string) { return `${YELLOW_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
grey,
|
|
22
|
+
red,
|
|
23
|
+
blue,
|
|
24
|
+
green,
|
|
25
|
+
yellow
|
|
26
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { asynchronousUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { whilst } = asynchronousUtilities;
|
|
6
|
+
|
|
7
|
+
function executeOperations(operations, callback, context) {
|
|
8
|
+
let completed = true;
|
|
9
|
+
|
|
10
|
+
const operationsLength = operations.length,
|
|
11
|
+
lastIndex = operationsLength - 1;
|
|
12
|
+
|
|
13
|
+
whilst((next, done, context, index) => {
|
|
14
|
+
if (index > lastIndex) {
|
|
15
|
+
done();
|
|
16
|
+
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const operation = operations[index],
|
|
21
|
+
proceed = next, ///
|
|
22
|
+
abort = () => {
|
|
23
|
+
completed = false;
|
|
24
|
+
|
|
25
|
+
done();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
operation(proceed, abort, context);
|
|
29
|
+
}, done, context);
|
|
30
|
+
|
|
31
|
+
function done() {
|
|
32
|
+
callback(completed);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
executeOperations
|
|
38
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { pathUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { CURRENT_DIRECTORY_PATH } = require("../constants");
|
|
6
|
+
|
|
7
|
+
const { concatenatePaths } = pathUtilities;
|
|
8
|
+
|
|
9
|
+
function stripRootDirectoryFromPath(path, context) {
|
|
10
|
+
const { rootDirectoryPaths } = context;
|
|
11
|
+
|
|
12
|
+
rootDirectoryPaths.some((rootDirectoryPath) => {
|
|
13
|
+
const pathStartsWithRootDirectoryPath = path.startsWith(rootDirectoryPath);
|
|
14
|
+
|
|
15
|
+
if (pathStartsWithRootDirectoryPath) {
|
|
16
|
+
const length = rootDirectoryPath.length,
|
|
17
|
+
start = length;
|
|
18
|
+
|
|
19
|
+
path = path.substring(start); ///
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isDirectoryPathRootDirectoryPath(directoryPath, context) {
|
|
29
|
+
const { rootDirectoryPaths } = context,
|
|
30
|
+
rootDirectoryPathsIncludesDirectoryPath = rootDirectoryPaths.includes(directoryPath),
|
|
31
|
+
directoryPathRootDirectoryPath = rootDirectoryPathsIncludesDirectoryPath; ///
|
|
32
|
+
|
|
33
|
+
return directoryPathRootDirectoryPath;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function entryPathsFromEntryNamesAndDirectoryPath(entryNames, directoryPath) {
|
|
37
|
+
const entryPaths = entryNames.map((entryName) => {
|
|
38
|
+
const entryPath = entryPathFromEntryNameAndDirectoryPath(entryName, directoryPath);
|
|
39
|
+
|
|
40
|
+
return entryPath
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return entryPaths;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
stripRootDirectoryFromPath,
|
|
48
|
+
isDirectoryPathRootDirectoryPath,
|
|
49
|
+
entryPathsFromEntryNamesAndDirectoryPath
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function entryPathFromEntryNameAndDirectoryPath(entryName, directoryPath) {
|
|
53
|
+
const entryPath = (directoryPath === CURRENT_DIRECTORY_PATH) ?
|
|
54
|
+
entryName : ///
|
|
55
|
+
concatenatePaths(directoryPath, entryName);
|
|
56
|
+
|
|
57
|
+
return entryPath;
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const GlobRule = require("../rule/glob"),
|
|
4
|
+
RegexRule = require("../rule/regex"),
|
|
5
|
+
StringRule = require("../rule/string");
|
|
6
|
+
|
|
7
|
+
function ruleFromStringAnchoredAndDirectory(string, anchored, directory) {
|
|
8
|
+
const globRule = GlobRule.fromStringAnchoredAndDirectory(string, anchored, directory),
|
|
9
|
+
regexRule = RegexRule.fromStringAnchoredAndDirectory(string, anchored, directory),
|
|
10
|
+
stringRule = StringRule.fromStringAnchoredAndDirectory(string, anchored, directory),
|
|
11
|
+
rule = (globRule || regexRule || stringRule);
|
|
12
|
+
|
|
13
|
+
return rule;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
ruleFromStringAnchoredAndDirectory
|
|
18
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { EMPTY_STRING } = require("../constants");
|
|
4
|
+
|
|
5
|
+
function addAnchors(string) { return `^${string}$`; }
|
|
6
|
+
|
|
7
|
+
function removeAnchors(string) { return string.replace(/(^\^|\$$)/g, EMPTY_STRING); }
|
|
8
|
+
|
|
9
|
+
function addDoubleQuotes(string) { return `"${string}"`; }
|
|
10
|
+
|
|
11
|
+
function addForwardSlashes(string) { return `/${string}/`; }
|
|
12
|
+
|
|
13
|
+
function removeDoubleQuotes(string) { return string.replace(/(^"|"$)/g, EMPTY_STRING); }
|
|
14
|
+
|
|
15
|
+
function removeForwardSlashes(string) { return string.replace(/(^\/|\/$)/g, EMPTY_STRING); }
|
|
16
|
+
|
|
17
|
+
function addTrailingForwardSlash(string) { return `${string}\/`; }
|
|
18
|
+
|
|
19
|
+
function removeTrailingForwardSlash(string) { return string.replace(/(\/$)/, EMPTY_STRING); }
|
|
20
|
+
|
|
21
|
+
function addTrailingEscapedForwardSlash(string) { return `${string}\\\/`; }
|
|
22
|
+
|
|
23
|
+
function removeTrailingEscapedForwardSlash(string) { return string.replace(/(\\\/$)/, EMPTY_STRING); }
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
addAnchors,
|
|
27
|
+
removeAnchors,
|
|
28
|
+
addDoubleQuotes,
|
|
29
|
+
addForwardSlashes,
|
|
30
|
+
removeDoubleQuotes,
|
|
31
|
+
removeForwardSlashes,
|
|
32
|
+
addTrailingForwardSlash,
|
|
33
|
+
removeTrailingForwardSlash,
|
|
34
|
+
addTrailingEscapedForwardSlash,
|
|
35
|
+
removeTrailingEscapedForwardSlash
|
|
36
|
+
};
|