find-cli 0.0.3 → 1.4.3
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 +46 -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 +19 -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 +118 -0
- package/bin/isIgnored/asynchronous.js +59 -0
- package/bin/isIgnored/synchronous.js +104 -0
- package/bin/main.js +85 -0
- package/bin/messages.js +37 -0
- package/bin/occurrence.js +38 -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 +24 -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 +165 -0
- package/bin/rule/regex.js +136 -0
- package/bin/rule/string.js +112 -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/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) {
|
|
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,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
class Occurrence {
|
|
4
|
+
constructor(start, end) {
|
|
5
|
+
this.start = start;
|
|
6
|
+
this.end = end;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getStart() {
|
|
10
|
+
return this.start;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getEnd() {
|
|
14
|
+
return this.end;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static fromResult(result) {
|
|
18
|
+
const { index } = result,
|
|
19
|
+
match = result[0], ///
|
|
20
|
+
length = match.length,
|
|
21
|
+
start = index, ///
|
|
22
|
+
end = start + length,
|
|
23
|
+
occurrence = new Occurrence(start, end);
|
|
24
|
+
|
|
25
|
+
return occurrence;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static fromIndexAndString(index, string) {
|
|
29
|
+
const length = string.length,
|
|
30
|
+
start = index, ///
|
|
31
|
+
end = start + length,
|
|
32
|
+
occurrence = new Occurrence(start, end);
|
|
33
|
+
|
|
34
|
+
return occurrence;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
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;
|
|
@@ -0,0 +1,201 @@
|
|
|
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 findOperation(proceed, abort, context) {
|
|
15
|
+
const { rootDirectoryPaths } = context,
|
|
16
|
+
entryPaths = [ ///
|
|
17
|
+
...rootDirectoryPaths
|
|
18
|
+
],
|
|
19
|
+
synchronous = findInEntries(entryPaths, (pathIgnored) => {
|
|
20
|
+
if (pathIgnored === null) {
|
|
21
|
+
abort();
|
|
22
|
+
}
|
|
23
|
+
}, context);
|
|
24
|
+
|
|
25
|
+
if (synchronous) {
|
|
26
|
+
proceed();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = findOperation;
|
|
31
|
+
|
|
32
|
+
function findInEntries(entryPaths, callback, context) {
|
|
33
|
+
let synchronous = true;
|
|
34
|
+
|
|
35
|
+
let entryNamesLength;
|
|
36
|
+
|
|
37
|
+
entryNamesLength = entryPaths.length;
|
|
38
|
+
|
|
39
|
+
while (entryNamesLength > 0) {
|
|
40
|
+
const entryPath = entryPaths.shift();
|
|
41
|
+
|
|
42
|
+
synchronous = findInEntry(entryPath, entryPaths, callback, context);
|
|
43
|
+
|
|
44
|
+
if (!synchronous) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
entryNamesLength = entryPaths.length;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return synchronous;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function findInEntry(entryPath, entryPaths, callback, context) {
|
|
55
|
+
let synchronous;
|
|
56
|
+
|
|
57
|
+
const path = entryPath,
|
|
58
|
+
directory = isEntryDirectory(path);
|
|
59
|
+
|
|
60
|
+
if (directory) {
|
|
61
|
+
const directoryPath = entryPath; ///
|
|
62
|
+
|
|
63
|
+
synchronous = findInDirectory(directoryPath, (pathIgnored) => {
|
|
64
|
+
const synchronous = (pathIgnored !== null) ?
|
|
65
|
+
findInEntries(entryPaths, callback, context) :
|
|
66
|
+
true;
|
|
67
|
+
|
|
68
|
+
if (synchronous) {
|
|
69
|
+
callback(pathIgnored);
|
|
70
|
+
}
|
|
71
|
+
}, context);
|
|
72
|
+
} else {
|
|
73
|
+
const filePath = entryPath; ///
|
|
74
|
+
|
|
75
|
+
synchronous = findInFile(filePath, (pathIgnored) => {
|
|
76
|
+
const synchronous = (pathIgnored !== null) ?
|
|
77
|
+
findInEntries(entryPaths, callback, context) :
|
|
78
|
+
true;
|
|
79
|
+
if (synchronous) {
|
|
80
|
+
callback(pathIgnored);
|
|
81
|
+
}
|
|
82
|
+
}, context);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (synchronous) {
|
|
86
|
+
synchronous = findInEntries(entryPaths, callback, context);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return synchronous;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function findInFile(filePath, callback, context) {
|
|
93
|
+
let synchronous;
|
|
94
|
+
|
|
95
|
+
const filePathIgnored = synchronousIsFilePathIgnored(filePath, context);
|
|
96
|
+
|
|
97
|
+
if (filePathIgnored !== null) {
|
|
98
|
+
synchronous = true;
|
|
99
|
+
|
|
100
|
+
const { quietly } = context;
|
|
101
|
+
|
|
102
|
+
if (!quietly) {
|
|
103
|
+
const { ruleString } = context;
|
|
104
|
+
|
|
105
|
+
let message = filePathIgnored ?
|
|
106
|
+
red(`Ignore ${filePath}`) :
|
|
107
|
+
green(`Permit ${filePath}`);
|
|
108
|
+
|
|
109
|
+
message = `${message} ${ruleString}`;
|
|
110
|
+
|
|
111
|
+
console.log(message);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!filePathIgnored) {
|
|
115
|
+
let { totalFiles } = context;
|
|
116
|
+
|
|
117
|
+
totalFiles++;
|
|
118
|
+
|
|
119
|
+
Object.assign(context, {
|
|
120
|
+
totalFiles
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const { dryRun } = context;
|
|
124
|
+
|
|
125
|
+
if (!dryRun) {
|
|
126
|
+
find(filePath, context);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
synchronous = false;
|
|
131
|
+
|
|
132
|
+
asynchronousIsFilePathIgnored(filePath, context, (pathIgnored) => {
|
|
133
|
+
const synchronous = (pathIgnored !== null) ?
|
|
134
|
+
findInFile(filePath, callback, context) :
|
|
135
|
+
true;
|
|
136
|
+
|
|
137
|
+
if (synchronous) {
|
|
138
|
+
callback(pathIgnored);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return synchronous;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function findInDirectory(directoryPath, callback, context) {
|
|
147
|
+
let synchronous;
|
|
148
|
+
|
|
149
|
+
const directoryPathIgnored = synchronousIsDirectoryPathIgnored(directoryPath, context);
|
|
150
|
+
|
|
151
|
+
if (directoryPathIgnored !== null) {
|
|
152
|
+
synchronous = true;
|
|
153
|
+
|
|
154
|
+
const directoryPathRootDirectoryPath = isDirectoryPathRootDirectoryPath(directoryPath, context);
|
|
155
|
+
|
|
156
|
+
if (!directoryPathRootDirectoryPath) {
|
|
157
|
+
const { quietly } = context;
|
|
158
|
+
|
|
159
|
+
if (!quietly) {
|
|
160
|
+
const { ruleString } = context;
|
|
161
|
+
|
|
162
|
+
let message = directoryPathIgnored ?
|
|
163
|
+
red(`Ignore ${directoryPath}/`) :
|
|
164
|
+
green(`Permit ${directoryPath}/`);
|
|
165
|
+
|
|
166
|
+
message = `${message} ${ruleString}`;
|
|
167
|
+
|
|
168
|
+
console.log(message);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!directoryPathIgnored) {
|
|
173
|
+
let { totalDirectories } = context;
|
|
174
|
+
|
|
175
|
+
totalDirectories++;
|
|
176
|
+
|
|
177
|
+
Object.assign(context, {
|
|
178
|
+
totalDirectories
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const entryNames = readDirectory(directoryPath),
|
|
182
|
+
entryPaths = entryPathsFromEntryNamesAndDirectoryPath(entryNames, directoryPath);
|
|
183
|
+
|
|
184
|
+
synchronous = findInEntries(entryPaths, callback, context);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
synchronous = false;
|
|
188
|
+
|
|
189
|
+
asynchronousIsDirectoryPathIgnored(directoryPath, context, (pathIgnored) => {
|
|
190
|
+
const synchronous = (pathIgnored !== null) ?
|
|
191
|
+
findInDirectory(directoryPath, callback, context) :
|
|
192
|
+
true;
|
|
193
|
+
|
|
194
|
+
if (synchronous) {
|
|
195
|
+
callback(pathIgnored);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return synchronous;
|
|
201
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { retrieveRootDirectoryPaths } = require("../configuration"),
|
|
4
|
+
{ NO_ROOT_DIRECTORY_PATHS_MESSAGE } = require("../messages");
|
|
5
|
+
|
|
6
|
+
function listRootDirectoryPathsOperation(proceed, abort, context) {
|
|
7
|
+
listRootDirectoryPaths()
|
|
8
|
+
|
|
9
|
+
proceed();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function listRootDirectoryPaths() {
|
|
13
|
+
const rootDirectoryPaths = retrieveRootDirectoryPaths(),
|
|
14
|
+
rootDirectoryPathsLength = rootDirectoryPaths.length,
|
|
15
|
+
lastIndex = rootDirectoryPathsLength - 1;
|
|
16
|
+
|
|
17
|
+
if (lastIndex === 0) {
|
|
18
|
+
console.log(NO_ROOT_DIRECTORY_PATHS_MESSAGE);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
rootDirectoryPaths.forEach((rootDirectoryPath, index) => {
|
|
22
|
+
if (index > 0) {
|
|
23
|
+
console.log(index, rootDirectoryPath);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return lastIndex;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = listRootDirectoryPathsOperation;
|
|
31
|
+
|
|
32
|
+
Object.assign(module.exports, {
|
|
33
|
+
listRootDirectoryPaths
|
|
34
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { shellUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { validateRootDirectoryPath } = require("../../utilities/validate"),
|
|
6
|
+
{ INVALID_ROOT_DIRECTORY_PATH_MESSAGE } = require("../../messages"),
|
|
7
|
+
{ ADD_ROOT_DIRECTORY_PATH_DESCRIPTION } = require("../../descriptions");
|
|
8
|
+
|
|
9
|
+
const { prompt } = shellUtilities;
|
|
10
|
+
|
|
11
|
+
function addRootDirectoryPathPromptOperation(proceed, abort, context) {
|
|
12
|
+
const { rootDirectoryPath } = context;
|
|
13
|
+
|
|
14
|
+
if (rootDirectoryPath !== null) {
|
|
15
|
+
proceed();
|
|
16
|
+
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const description = ADD_ROOT_DIRECTORY_PATH_DESCRIPTION,
|
|
21
|
+
errorMessage = INVALID_ROOT_DIRECTORY_PATH_MESSAGE,
|
|
22
|
+
validationFunction = validateRootDirectoryPath, ///
|
|
23
|
+
options = {
|
|
24
|
+
description,
|
|
25
|
+
errorMessage,
|
|
26
|
+
validationFunction
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
prompt(options, (answer) => {
|
|
30
|
+
const valid = (answer !== null);
|
|
31
|
+
|
|
32
|
+
if(!valid) {
|
|
33
|
+
abort();
|
|
34
|
+
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const rootDirectoryPath = answer; ///
|
|
39
|
+
|
|
40
|
+
Object.assign(context, {
|
|
41
|
+
rootDirectoryPath
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
proceed();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = addRootDirectoryPathPromptOperation;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { shellUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { isAnswerIgnore } = require("../../utilities/prompt"),
|
|
6
|
+
{ FILE, DIRECTORY } = require("../../constants"),
|
|
7
|
+
{ validateIgnoreOrPermit } = require("../../utilities/validate"),
|
|
8
|
+
{ INVALID_IGNORE_OR_PERMIT_MESSAGE } = require("../../messages");
|
|
9
|
+
|
|
10
|
+
const { prompt } = shellUtilities;
|
|
11
|
+
|
|
12
|
+
function ignoreOrPermitPathPromptOperation(proceed, abort, context) {
|
|
13
|
+
const { path, directory } = context,
|
|
14
|
+
fileOrDirectory = directory ?
|
|
15
|
+
DIRECTORY :
|
|
16
|
+
FILE,
|
|
17
|
+
description = `Ignore or permit the '${path}' ${fileOrDirectory}? (i)gnore (p)ermit: `,
|
|
18
|
+
errorMessage = INVALID_IGNORE_OR_PERMIT_MESSAGE,
|
|
19
|
+
validationFunction = validateIgnoreOrPermit, ///
|
|
20
|
+
options = {
|
|
21
|
+
description,
|
|
22
|
+
errorMessage,
|
|
23
|
+
validationFunction
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
prompt(options, (answer) => {
|
|
27
|
+
const valid = (answer !== null);
|
|
28
|
+
|
|
29
|
+
if(!valid) {
|
|
30
|
+
abort();
|
|
31
|
+
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ignore = isAnswerIgnore(answer),
|
|
36
|
+
pathIgnored = ignore; ///
|
|
37
|
+
|
|
38
|
+
Object.assign(context, {
|
|
39
|
+
pathIgnored
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
proceed();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = ignoreOrPermitPathPromptOperation;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { shellUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { validateIndex } = require("../../utilities/validate"),
|
|
6
|
+
{ listRootDirectoryPaths } = require("../../operation/listRootDirectoryPaths"),
|
|
7
|
+
{ REMOVE_ROOT_DIRECTORY_PATH_DESCRIPTION } = require("../../descriptions"),
|
|
8
|
+
{ INVALID_ROOT_DIRECTORY_PATH_INDEX_MESSAGE } = require("../../messages");
|
|
9
|
+
|
|
10
|
+
const { prompt } = shellUtilities;
|
|
11
|
+
|
|
12
|
+
function removeRootDirectoryPathPromptOperation(proceed, abort, context) {
|
|
13
|
+
const { rootDirectoryPath } = context;
|
|
14
|
+
|
|
15
|
+
if (rootDirectoryPath !== null) {
|
|
16
|
+
proceed();
|
|
17
|
+
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const lastIndex = listRootDirectoryPaths();
|
|
22
|
+
|
|
23
|
+
if (lastIndex === 0) {
|
|
24
|
+
abort();
|
|
25
|
+
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const description = REMOVE_ROOT_DIRECTORY_PATH_DESCRIPTION,
|
|
30
|
+
errorMessage = INVALID_ROOT_DIRECTORY_PATH_INDEX_MESSAGE,
|
|
31
|
+
validationFunction = (answer) => {
|
|
32
|
+
const valid = validateIndex(answer, lastIndex);
|
|
33
|
+
|
|
34
|
+
return valid;
|
|
35
|
+
}, ///
|
|
36
|
+
options = {
|
|
37
|
+
description,
|
|
38
|
+
errorMessage,
|
|
39
|
+
validationFunction
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
prompt(options, (answer) => {
|
|
43
|
+
const valid = (answer !== null);
|
|
44
|
+
|
|
45
|
+
if(!valid) {
|
|
46
|
+
abort();
|
|
47
|
+
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const index = answer; ///
|
|
52
|
+
|
|
53
|
+
Object.assign(context, {
|
|
54
|
+
index
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
proceed();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = removeRootDirectoryPathPromptOperation;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { shellUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
|
|
6
|
+
{ validateGlobStringOrPattern } = require("../../utilities/validate"),
|
|
7
|
+
{ GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../../descriptions"),
|
|
8
|
+
{ INVALID_GLOB_REGEX_OR_STRING_MESSAGE } = require("../../messages");
|
|
9
|
+
|
|
10
|
+
const { prompt } = shellUtilities;
|
|
11
|
+
|
|
12
|
+
function rulePromptOperation(proceed, abort, context) {
|
|
13
|
+
const { path, directory } = context,
|
|
14
|
+
description = GLOB_STRING_OR_REGEX_DESCRIPTION,
|
|
15
|
+
errorMessage = INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
|
|
16
|
+
initialAnswer = path, ///
|
|
17
|
+
validationFunction = (answer) => {
|
|
18
|
+
const valid = validateGlobStringOrPattern(answer, directory);
|
|
19
|
+
|
|
20
|
+
return valid;
|
|
21
|
+
},
|
|
22
|
+
options = {
|
|
23
|
+
description,
|
|
24
|
+
errorMessage,
|
|
25
|
+
initialAnswer,
|
|
26
|
+
validationFunction
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
prompt(options, (answer) => {
|
|
30
|
+
const valid = (answer !== null);
|
|
31
|
+
|
|
32
|
+
if(!valid) {
|
|
33
|
+
abort();
|
|
34
|
+
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const string = answer, ///
|
|
39
|
+
anchored = true,
|
|
40
|
+
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory);
|
|
41
|
+
|
|
42
|
+
Object.assign(context, {
|
|
43
|
+
rule
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
proceed();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = rulePromptOperation;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { retrieveRootDirectoryPaths,
|
|
4
|
+
retrieveIgnoredFilePathRules,
|
|
5
|
+
retrievePermittedFilePathRules,
|
|
6
|
+
retrieveIgnoredDirectoryPathRules,
|
|
7
|
+
retrievePermittedDirectoryPathRules } = require("../configuration");
|
|
8
|
+
|
|
9
|
+
function readConfigurationOperation(proceed, abort, context) {
|
|
10
|
+
const rootDirectoryPaths = retrieveRootDirectoryPaths(),
|
|
11
|
+
ignoredFilePathRules = retrieveIgnoredFilePathRules(),
|
|
12
|
+
permittedFilePathRules = retrievePermittedFilePathRules(),
|
|
13
|
+
ignoredDirectoryPathRules = retrieveIgnoredDirectoryPathRules(),
|
|
14
|
+
permittedDirectoryPathRules = retrievePermittedDirectoryPathRules();
|
|
15
|
+
|
|
16
|
+
Object.assign(context, {
|
|
17
|
+
rootDirectoryPaths,
|
|
18
|
+
ignoredFilePathRules,
|
|
19
|
+
permittedFilePathRules,
|
|
20
|
+
ignoredDirectoryPathRules,
|
|
21
|
+
permittedDirectoryPathRules
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
proceed();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = readConfigurationOperation;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { retrieveRootDirectoryPaths } = require("../configuration"),
|
|
4
|
+
{ removeRootDirectoryPathByIndex } = require("./removeRootDirectoryPathByIndex");
|
|
5
|
+
|
|
6
|
+
function removeRootDirectoryPathOperation(proceed, abort, context) {
|
|
7
|
+
const { rootDirectoryPath } = context;
|
|
8
|
+
|
|
9
|
+
if (rootDirectoryPath === null) {
|
|
10
|
+
proceed();
|
|
11
|
+
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const rootDirectoryPaths = retrieveRootDirectoryPaths(),
|
|
16
|
+
index = rootDirectoryPaths.indexOf(rootDirectoryPath);
|
|
17
|
+
|
|
18
|
+
if (index === -1) {
|
|
19
|
+
abort();
|
|
20
|
+
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
removeRootDirectoryPathByIndex(index);
|
|
25
|
+
|
|
26
|
+
proceed();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = removeRootDirectoryPathOperation;
|