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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const rulePromptOperation = require("../operation/prompt/rule"),
|
|
4
|
+
updatePathRulesOperation = require("../operation/updatePatRules"),
|
|
5
|
+
ignoreOrPermitPathPromptOperation = require("../operation/prompt/ignoreOrPermitPath");
|
|
6
|
+
|
|
7
|
+
const { executeOperations } = require("../utilities/operation"),
|
|
8
|
+
{ stripRootDirectoryFromPath } = require("../utilities/path");
|
|
9
|
+
|
|
10
|
+
function asynchronousIsFilePathIgnored(filePath, context, callback) {
|
|
11
|
+
filePath = stripRootDirectoryFromPath(filePath, context); ///
|
|
12
|
+
|
|
13
|
+
const path = filePath, ///
|
|
14
|
+
directory = false;
|
|
15
|
+
|
|
16
|
+
asynchronousIsPathIgnored(path, directory, context, callback);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function asynchronousIsDirectoryPathIgnored(directoryPath, context, callback) {
|
|
20
|
+
directoryPath = stripRootDirectoryFromPath(directoryPath, context); ///
|
|
21
|
+
|
|
22
|
+
const path = directoryPath, ///
|
|
23
|
+
directory = true;
|
|
24
|
+
|
|
25
|
+
asynchronousIsPathIgnored(path, directory, context, callback);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
asynchronousIsFilePathIgnored,
|
|
30
|
+
asynchronousIsDirectoryPathIgnored
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function asynchronousIsPathIgnored(path, directory, context, callback) {
|
|
34
|
+
const operations = [
|
|
35
|
+
ignoreOrPermitPathPromptOperation,
|
|
36
|
+
rulePromptOperation,
|
|
37
|
+
updatePathRulesOperation
|
|
38
|
+
],
|
|
39
|
+
rule = null,
|
|
40
|
+
pathIgnored = null;
|
|
41
|
+
|
|
42
|
+
Object.assign(context, {
|
|
43
|
+
rule,
|
|
44
|
+
path,
|
|
45
|
+
directory,
|
|
46
|
+
pathIgnored
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
executeOperations(operations, (completed) => {
|
|
50
|
+
const { pathIgnored } = context;
|
|
51
|
+
|
|
52
|
+
delete context.rule;
|
|
53
|
+
delete context.path;
|
|
54
|
+
delete context.directory;
|
|
55
|
+
delete context.pathIgnored;
|
|
56
|
+
|
|
57
|
+
callback(pathIgnored);
|
|
58
|
+
}, context);
|
|
59
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { EMPTY_STRING } = require("../constants"),
|
|
4
|
+
{ addTrailingForwardSlash } = require("../utilities/string"),
|
|
5
|
+
{ stripRootDirectoryFromPath } = require("../utilities/path");
|
|
6
|
+
|
|
7
|
+
function synchronousIsFilePathIgnored(filePath, context) {
|
|
8
|
+
let filePathIgnored = null;
|
|
9
|
+
|
|
10
|
+
filePath = stripRootDirectoryFromPath(filePath, context); ///
|
|
11
|
+
|
|
12
|
+
const { ignoredFilePathRules, permittedFilePathRules } = context,
|
|
13
|
+
string = filePath; ///
|
|
14
|
+
|
|
15
|
+
ignoredFilePathRules.some((ignoredFilePathRule) => {
|
|
16
|
+
const matches = ignoredFilePathRule.match(string);
|
|
17
|
+
|
|
18
|
+
if (matches) {
|
|
19
|
+
const rule = ignoredFilePathRule, ///
|
|
20
|
+
ruleString = rule.asString();
|
|
21
|
+
|
|
22
|
+
Object.assign(context, {
|
|
23
|
+
ruleString
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
filePathIgnored = true;
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
permittedFilePathRules.some((permittedFilePathRule) => {
|
|
33
|
+
const matches = permittedFilePathRule.match(string);
|
|
34
|
+
|
|
35
|
+
if (matches) {
|
|
36
|
+
const rule = permittedFilePathRule, ///
|
|
37
|
+
ruleString = rule.asString();
|
|
38
|
+
|
|
39
|
+
Object.assign(context, {
|
|
40
|
+
ruleString
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
filePathIgnored = false;
|
|
44
|
+
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return filePathIgnored;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function synchronousIsDirectoryPathIgnored(directoryPath, context) {
|
|
53
|
+
let directoryPathIgnored = null;
|
|
54
|
+
|
|
55
|
+
directoryPath = stripRootDirectoryFromPath(directoryPath, context); ///
|
|
56
|
+
|
|
57
|
+
if (directoryPath === EMPTY_STRING) {
|
|
58
|
+
directoryPathIgnored = false;
|
|
59
|
+
} else {
|
|
60
|
+
const { ignoredDirectoryPathRules, permittedDirectoryPathRules } = context,
|
|
61
|
+
string = addTrailingForwardSlash(directoryPath); ///
|
|
62
|
+
|
|
63
|
+
ignoredDirectoryPathRules.some((ignoredDirectoryPathRule) => {
|
|
64
|
+
const matches = ignoredDirectoryPathRule.match(string);
|
|
65
|
+
|
|
66
|
+
if (matches) {
|
|
67
|
+
const rule = ignoredDirectoryPathRule, ///
|
|
68
|
+
ruleString = rule.asString();
|
|
69
|
+
|
|
70
|
+
Object.assign(context, {
|
|
71
|
+
ruleString
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
directoryPathIgnored = true;
|
|
75
|
+
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
permittedDirectoryPathRules.some((permittedDirectoryPathRule) => {
|
|
81
|
+
const matches = permittedDirectoryPathRule.match(string);
|
|
82
|
+
|
|
83
|
+
if (matches) {
|
|
84
|
+
const rule = permittedDirectoryPathRule, ///
|
|
85
|
+
ruleString = rule.asString();
|
|
86
|
+
|
|
87
|
+
Object.assign(context, {
|
|
88
|
+
ruleString
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
directoryPathIgnored = false;
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return directoryPathIgnored;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
synchronousIsFilePathIgnored,
|
|
103
|
+
synchronousIsDirectoryPathIgnored
|
|
104
|
+
};
|
package/bin/line.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { arrayUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { grey, blue, yellow } = require("./utilities/log"),
|
|
6
|
+
{ EMPTY_STRING, SINGLE_SPACE } = require("./constants");
|
|
7
|
+
|
|
8
|
+
const { backwardsForEach } = arrayUtilities;
|
|
9
|
+
|
|
10
|
+
class Line {
|
|
11
|
+
constructor(index, content, filePath, occurrences) {
|
|
12
|
+
this.index = index;
|
|
13
|
+
this.content = content;
|
|
14
|
+
this.filePath = filePath;
|
|
15
|
+
this.occurences = occurrences;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getIndex() {
|
|
19
|
+
return this.index;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getContent() {
|
|
23
|
+
return this.content;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getFilePath() {
|
|
27
|
+
return this.filePath;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getOccurrences() {
|
|
31
|
+
return this.occurences;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
setIndex(index) {
|
|
35
|
+
this.index = index;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setContent(content) {
|
|
39
|
+
this.content = content;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setFilePath(filePath) {
|
|
43
|
+
this.filePath = filePath;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setOccurrences(occurrences) {
|
|
47
|
+
this.occurrences = occurrences;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getIndexLength() {
|
|
51
|
+
const indexLength = this.index.length;
|
|
52
|
+
|
|
53
|
+
return indexLength;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getFilePathLength() {
|
|
57
|
+
const filePathLength = this.filePath.length;
|
|
58
|
+
|
|
59
|
+
return filePathLength;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
addOccurrences(occurrences) {
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getFormattedIndex(requiredIndexLength) {
|
|
67
|
+
let index;
|
|
68
|
+
|
|
69
|
+
const indexLength = this.getIndexLength(),
|
|
70
|
+
paddingLength = requiredIndexLength - indexLength,
|
|
71
|
+
padding = paddingFromPaddingLength(paddingLength);
|
|
72
|
+
|
|
73
|
+
index = `${padding}${this.index}`;
|
|
74
|
+
|
|
75
|
+
const formattedIndex = yellow(index);
|
|
76
|
+
|
|
77
|
+
return formattedIndex;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getFormattedContent() {
|
|
81
|
+
const gaps = [],
|
|
82
|
+
matches = [];
|
|
83
|
+
|
|
84
|
+
let end,
|
|
85
|
+
start,
|
|
86
|
+
string = this.content; ///
|
|
87
|
+
|
|
88
|
+
backwardsForEach(this.occurrences, (occurrence) => {
|
|
89
|
+
end = occurrence.getEnd();
|
|
90
|
+
|
|
91
|
+
start = end; ///
|
|
92
|
+
|
|
93
|
+
end = Infinity;
|
|
94
|
+
|
|
95
|
+
const gap = string.substring(start, end);
|
|
96
|
+
|
|
97
|
+
gaps.unshift(gap);
|
|
98
|
+
|
|
99
|
+
end = occurrence.getEnd();
|
|
100
|
+
|
|
101
|
+
start = 0;
|
|
102
|
+
|
|
103
|
+
string = string.substring(start, end);
|
|
104
|
+
|
|
105
|
+
start = occurrence.getStart();
|
|
106
|
+
|
|
107
|
+
end = Infinity;
|
|
108
|
+
|
|
109
|
+
const match = string.substring(start, end);
|
|
110
|
+
|
|
111
|
+
matches.unshift(match);
|
|
112
|
+
|
|
113
|
+
end = start; ///
|
|
114
|
+
|
|
115
|
+
start = 0;
|
|
116
|
+
|
|
117
|
+
string = string.substring(start, end); ///
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
let gap = string; ///
|
|
121
|
+
|
|
122
|
+
gap = grey(gap); ///
|
|
123
|
+
|
|
124
|
+
string = gap; ///
|
|
125
|
+
|
|
126
|
+
gaps.forEach((gap, index) => {
|
|
127
|
+
let match = matches[index];
|
|
128
|
+
|
|
129
|
+
gap = grey(gap); ///
|
|
130
|
+
|
|
131
|
+
match = blue(match); ///
|
|
132
|
+
|
|
133
|
+
string = `${string}${match}${gap}`;
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const formattedContent = string; ///
|
|
137
|
+
|
|
138
|
+
return formattedContent;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getFormattedFilePath(requiredFilePathLength) {
|
|
142
|
+
const filePathLength = this.getFilePathLength(),
|
|
143
|
+
paddingLength = requiredFilePathLength - filePathLength,
|
|
144
|
+
padding = paddingFromPaddingLength(paddingLength),
|
|
145
|
+
formattedFilePath = `${this.filePath}${padding}`;
|
|
146
|
+
|
|
147
|
+
return formattedFilePath;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
asMessage(requiredIndexLength, requiredFilePathLength) {
|
|
151
|
+
const formattedIndex = this.getFormattedIndex(requiredIndexLength),
|
|
152
|
+
formattedContent = this.getFormattedContent(),
|
|
153
|
+
formattedFilePath = this.getFormattedFilePath(requiredFilePathLength),
|
|
154
|
+
message = `|${formattedFilePath} ${formattedIndex}|${formattedContent}`;
|
|
155
|
+
|
|
156
|
+
return message;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static fromIndexContentAndFilePath(index, content, filePath) {
|
|
160
|
+
index = `${index}`; ///
|
|
161
|
+
|
|
162
|
+
content = content.replace(/(\r\n|\r|\n)$/, EMPTY_STRING); ///
|
|
163
|
+
|
|
164
|
+
const occurrences = [],
|
|
165
|
+
line = new Line(index, content, filePath, occurrences);
|
|
166
|
+
|
|
167
|
+
return line;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
module.exports = Line;
|
|
172
|
+
|
|
173
|
+
function paddingFromPaddingLength(paddingLength) {
|
|
174
|
+
let padding = EMPTY_STRING;
|
|
175
|
+
|
|
176
|
+
for (let count = 0; count < paddingLength; count++) {
|
|
177
|
+
padding += SINGLE_SPACE;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return padding;
|
|
181
|
+
}
|
package/bin/main.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const findAction = require("./action/find"),
|
|
4
|
+
helpAction = require("./action/help"),
|
|
5
|
+
versionAction = require("./action/version"),
|
|
6
|
+
initialiseAction = require("./action/initialise"),
|
|
7
|
+
addRootDirectoryPathAction = require("./action/addRootDirectoryPath"),
|
|
8
|
+
listRootDirectoryPathsAction = require("./action/listRootDirectoryPaths"),
|
|
9
|
+
removeRootDirectoryPathAction = require("./action/removeRootDirectoryPath");
|
|
10
|
+
|
|
11
|
+
const { NO_ARGUMENT_GIVEN_MESSAGE, COMMAND_NOT_RECOGNISED_MESSAGE } = require("./messages"),
|
|
12
|
+
{ DEFAULT_DRY_RUN, DEFAULT_QUIETLY } = require("./defaults"),
|
|
13
|
+
{ FIND_COMMAND,
|
|
14
|
+
HELP_COMMAND,
|
|
15
|
+
VERSION_COMMAND,
|
|
16
|
+
INITIALISE_COMMAND,
|
|
17
|
+
ADD_ROOT_DIRECTORY_PATH_COMMAND,
|
|
18
|
+
LIST_ROOT_DIRECTORY_PATHS_COMMAND,
|
|
19
|
+
REMOVE_ROOT_DIRECTORY_PATH_COMMAND } = require("./commands");
|
|
20
|
+
|
|
21
|
+
function main(command, argument, options) {
|
|
22
|
+
const { dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY } = options;
|
|
23
|
+
|
|
24
|
+
switch (command) {
|
|
25
|
+
case HELP_COMMAND: {
|
|
26
|
+
helpAction();
|
|
27
|
+
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
case VERSION_COMMAND: {
|
|
32
|
+
versionAction();
|
|
33
|
+
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
case INITIALISE_COMMAND: {
|
|
38
|
+
initialiseAction();
|
|
39
|
+
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
case ADD_ROOT_DIRECTORY_PATH_COMMAND: {
|
|
44
|
+
const rootDirectoryPath = argument; ///
|
|
45
|
+
|
|
46
|
+
addRootDirectoryPathAction(rootDirectoryPath);
|
|
47
|
+
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
case LIST_ROOT_DIRECTORY_PATHS_COMMAND: {
|
|
52
|
+
listRootDirectoryPathsAction();
|
|
53
|
+
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
case REMOVE_ROOT_DIRECTORY_PATH_COMMAND: {
|
|
58
|
+
const rootDirectoryPath = argument; ///
|
|
59
|
+
|
|
60
|
+
removeRootDirectoryPathAction(rootDirectoryPath);
|
|
61
|
+
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
case FIND_COMMAND: {
|
|
66
|
+
if ((argument === null) && !dryRun) {
|
|
67
|
+
console.log(NO_ARGUMENT_GIVEN_MESSAGE);
|
|
68
|
+
} else {
|
|
69
|
+
const string = argument; ///
|
|
70
|
+
|
|
71
|
+
findAction(string, dryRun, quietly);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
default: {
|
|
78
|
+
console.log(COMMAND_NOT_RECOGNISED_MESSAGE);
|
|
79
|
+
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = main;
|
package/bin/messages.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const NO_ARGUMENT_GIVEN_MESSAGE = "No argument has been given.",
|
|
4
|
+
COMMAND_NOT_RECOGNISED_MESSAGE = "The command is not recognised.",
|
|
5
|
+
NO_ROOT_DIRECTORY_PATHS_MESSAGE = "There are no root directory paths bar the default one.",
|
|
6
|
+
CONFIGURATION_FILE_DOES_NOT_EXIST_MESSAGE = "The action cannot be performed because the configuration file is missing. Run 'find initialise' to create one.",
|
|
7
|
+
INVALID_IGNORE_OR_PERMIT_MESSAGE = "You must answer (i)gnore or (p)ermit.",
|
|
8
|
+
INVALID_ROOT_DIRECTORY_PATH_MESSAGE = "Additional root directories must be globs of the form '../**/'.",
|
|
9
|
+
INVALID_GLOB_REGEX_OR_STRING_MESSAGE = "The glob, regex or string is invalid.",
|
|
10
|
+
INVALID_ROOT_DIRECTORY_PATH_INDEX_MESSAGE = "The index is either not a number or not within range.",
|
|
11
|
+
FAILED_FIND_MESSAGE = "Failed to search everything.",
|
|
12
|
+
FAILED_INITIALISE_MESSAGE = "Failed to create a configuration file because one is already present.",
|
|
13
|
+
FAILED_ADD_ROOT_DIRECTORY_MESSAGE = "Failed to add the root directory.",
|
|
14
|
+
FAILED_REMOVE_ROOT_DIRECTORY_MESSAGE = "Failed to remove the root directory.",
|
|
15
|
+
SUCCESSFUL_FIND_MESSAGE = "Searched everything successfully.",
|
|
16
|
+
SUCCESSFUL_INITIALISE_MESSAGE = "The configuration file has been created successfully.",
|
|
17
|
+
SUCCESSFUL_ADD_ROOT_DIRECTORY_MESSAGE = "Added the root directory successfully.",
|
|
18
|
+
SUCCESSFUL_REMOVE_ROOT_DIRECTORY_MESSAGE = "Removed the root directory successfully.";
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
NO_ARGUMENT_GIVEN_MESSAGE,
|
|
22
|
+
COMMAND_NOT_RECOGNISED_MESSAGE,
|
|
23
|
+
NO_ROOT_DIRECTORY_PATHS_MESSAGE,
|
|
24
|
+
CONFIGURATION_FILE_DOES_NOT_EXIST_MESSAGE,
|
|
25
|
+
INVALID_IGNORE_OR_PERMIT_MESSAGE,
|
|
26
|
+
INVALID_ROOT_DIRECTORY_PATH_MESSAGE,
|
|
27
|
+
INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
28
|
+
INVALID_ROOT_DIRECTORY_PATH_INDEX_MESSAGE,
|
|
29
|
+
FAILED_FIND_MESSAGE,
|
|
30
|
+
FAILED_INITIALISE_MESSAGE,
|
|
31
|
+
FAILED_ADD_ROOT_DIRECTORY_MESSAGE,
|
|
32
|
+
FAILED_REMOVE_ROOT_DIRECTORY_MESSAGE,
|
|
33
|
+
SUCCESSFUL_FIND_MESSAGE,
|
|
34
|
+
SUCCESSFUL_INITIALISE_MESSAGE,
|
|
35
|
+
SUCCESSFUL_ADD_ROOT_DIRECTORY_MESSAGE,
|
|
36
|
+
SUCCESSFUL_REMOVE_ROOT_DIRECTORY_MESSAGE
|
|
37
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ZERO } = require("./constants");
|
|
4
|
+
|
|
5
|
+
class Occurrence {
|
|
6
|
+
constructor(start, end) {
|
|
7
|
+
this.start = start;
|
|
8
|
+
this.end = end;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getStart() {
|
|
12
|
+
return this.start;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getEnd() {
|
|
16
|
+
return this.end;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static fromResultAndOffset(result, offset) {
|
|
20
|
+
const { index } = result,
|
|
21
|
+
match = result[ZERO],
|
|
22
|
+
length = match.length,
|
|
23
|
+
start = index + offset,
|
|
24
|
+
end = start + length,
|
|
25
|
+
occurrence = new Occurrence(start, end);
|
|
26
|
+
|
|
27
|
+
return occurrence;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static fromIndexStringAndOffset(index, string, offset) {
|
|
31
|
+
const length = string.length,
|
|
32
|
+
start = index + offset,
|
|
33
|
+
end = start + length,
|
|
34
|
+
occurrence = new Occurrence(start, end);
|
|
35
|
+
|
|
36
|
+
return occurrence;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = Occurrence;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { retrieveRootDirectoryPaths, updateRootDirectoryPaths } = require("../configuration");
|
|
4
|
+
|
|
5
|
+
function addRootDirectoryPathOperation(proceed, abort, context) {
|
|
6
|
+
const { rootDirectoryPath } = context,
|
|
7
|
+
rootDirectoryPaths = retrieveRootDirectoryPaths();
|
|
8
|
+
|
|
9
|
+
rootDirectoryPaths.push(rootDirectoryPath);
|
|
10
|
+
|
|
11
|
+
updateRootDirectoryPaths(rootDirectoryPaths);
|
|
12
|
+
|
|
13
|
+
proceed();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = addRootDirectoryPathOperation;
|