find-cli 1.4.10 → 1.5.0
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 +2 -1
- package/bin/action/find.js +9 -6
- package/bin/action/help.js +2 -0
- package/bin/defaults.js +2 -0
- package/bin/find.js +10 -4
- package/bin/line.js +10 -5
- package/bin/main.js +3 -3
- package/bin/operation/find.js +24 -8
- package/bin/options.js +2 -0
- package/bin/utilities/log.js +1 -9
- package/package.json +1 -1
package/README.md
CHANGED
package/bin/abbreviations.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const { HELP_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION } = require("./options");
|
|
3
|
+
const { HELP_OPTION, FORMAT_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION } = require("./options");
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
"h": HELP_OPTION,
|
|
7
|
+
"f": FORMAT_OPTION,
|
|
7
8
|
"v": VERSION_OPTION,
|
|
8
9
|
"d": DRY_RUN_OPTION,
|
|
9
10
|
"q": QUIETLY_OPTION
|
package/bin/action/find.js
CHANGED
|
@@ -7,7 +7,7 @@ const ruleOperation = require("../operation/rule"),
|
|
|
7
7
|
const { S, EMPTY_STRING } = require("../constants"),
|
|
8
8
|
{ executeOperations } = require("../utilities/operation");
|
|
9
9
|
|
|
10
|
-
function findAction(string, dryRun, quietly) {
|
|
10
|
+
function findAction(string, dryRun, format, quietly) {
|
|
11
11
|
const operations = [
|
|
12
12
|
ruleOperation,
|
|
13
13
|
readConfigurationOperation,
|
|
@@ -22,6 +22,7 @@ function findAction(string, dryRun, quietly) {
|
|
|
22
22
|
context = {
|
|
23
23
|
string,
|
|
24
24
|
dryRun,
|
|
25
|
+
format,
|
|
25
26
|
quietly,
|
|
26
27
|
rule,
|
|
27
28
|
lines,
|
|
@@ -32,13 +33,15 @@ function findAction(string, dryRun, quietly) {
|
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
executeOperations(operations, (completed) => {
|
|
35
|
-
|
|
36
|
+
if (format) {
|
|
37
|
+
logLines(context);
|
|
38
|
+
}
|
|
36
39
|
|
|
37
40
|
if (!completed) {
|
|
38
41
|
return;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
logTotals(context);
|
|
42
45
|
}, context);
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -62,13 +65,13 @@ function logLines(context) {
|
|
|
62
65
|
requiredContentLength = maximumContentLength; ///
|
|
63
66
|
|
|
64
67
|
lines.forEach((line) => {
|
|
65
|
-
const
|
|
68
|
+
const formattedMessage = line.asFormattedMessage(requiredIndexLength, requiredContentLength);
|
|
66
69
|
|
|
67
|
-
console.log(
|
|
70
|
+
console.log(formattedMessage);
|
|
68
71
|
});
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
function
|
|
74
|
+
function logTotals(context) {
|
|
72
75
|
const { linesTotal, filesTotal, directoriesTotal, occurrencesTotal } = context,
|
|
73
76
|
optionalS = (occurrencesTotal === 1) ?
|
|
74
77
|
EMPTY_STRING :
|
package/bin/action/help.js
CHANGED
package/bin/defaults.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const DEFAULT_HELP = false,
|
|
4
|
+
DEFAULT_FORMAT = false,
|
|
4
5
|
DEFAULT_VERSION = false,
|
|
5
6
|
DEFAULT_DRY_RUN = false,
|
|
6
7
|
DEFAULT_QUIETLY = false;
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
9
10
|
DEFAULT_HELP,
|
|
11
|
+
DEFAULT_FORMAT,
|
|
10
12
|
DEFAULT_VERSION,
|
|
11
13
|
DEFAULT_DRY_RUN,
|
|
12
14
|
DEFAULT_QUIETLY
|
package/bin/find.js
CHANGED
|
@@ -7,7 +7,7 @@ const Line = require("./line");
|
|
|
7
7
|
const { readFile } = fileSystemUtilities;
|
|
8
8
|
|
|
9
9
|
function find(filePath, context) {
|
|
10
|
-
const { rule } = context,
|
|
10
|
+
const { rule, format } = context,
|
|
11
11
|
content = readFile(filePath),
|
|
12
12
|
lines = linesFromContentAndFilePath(content, filePath);
|
|
13
13
|
|
|
@@ -26,11 +26,17 @@ function find(filePath, context) {
|
|
|
26
26
|
occurrencesTotal
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
line.setOccurrences(occurrences);
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
if (!format) {
|
|
32
|
+
const message = line.asMessage();
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
console.log(message);
|
|
35
|
+
} else {
|
|
36
|
+
const { lines } = context;
|
|
37
|
+
|
|
38
|
+
lines.push(line);
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
linesTotal++;
|
package/bin/line.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { arrayUtilities } = require("necessary");
|
|
4
4
|
|
|
5
|
-
const { grey, blue, yellow
|
|
5
|
+
const { grey, blue, yellow } = require("./utilities/log"),
|
|
6
6
|
{ EMPTY_STRING, SINGLE_SPACE } = require("./constants");
|
|
7
7
|
|
|
8
8
|
const { backwardsForEach } = arrayUtilities;
|
|
@@ -128,7 +128,7 @@ class Line {
|
|
|
128
128
|
|
|
129
129
|
gap = grey(gap); ///
|
|
130
130
|
|
|
131
|
-
match =
|
|
131
|
+
match = blue(match); ///
|
|
132
132
|
|
|
133
133
|
string = `${string}${match}${gap}`;
|
|
134
134
|
});
|
|
@@ -142,13 +142,18 @@ class Line {
|
|
|
142
142
|
const filePathLength = this.getFilePathLength(),
|
|
143
143
|
paddingLength = requiredFilePathLength - filePathLength,
|
|
144
144
|
padding = paddingFromPaddingLength(paddingLength),
|
|
145
|
-
|
|
146
|
-
formattedFilePath = blue(filePath);
|
|
145
|
+
formattedFilePath = `${this.filePath}${padding}`;
|
|
147
146
|
|
|
148
147
|
return formattedFilePath;
|
|
149
148
|
}
|
|
150
149
|
|
|
151
|
-
asMessage(
|
|
150
|
+
asMessage() {
|
|
151
|
+
const message = `${this.filePath} ${this.index} | ${this.content}`;
|
|
152
|
+
|
|
153
|
+
return message;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
asFormattedMessage(requiredIndexLength, requiredFilePathLength) {
|
|
152
157
|
const formattedIndex = this.getFormattedIndex(requiredIndexLength),
|
|
153
158
|
formattedContent = this.getFormattedContent(),
|
|
154
159
|
formattedFilePath = this.getFormattedFilePath(requiredFilePathLength),
|
package/bin/main.js
CHANGED
|
@@ -9,7 +9,7 @@ const findAction = require("./action/find"),
|
|
|
9
9
|
removeRootDirectoryPathAction = require("./action/removeRootDirectoryPath");
|
|
10
10
|
|
|
11
11
|
const { NO_ARGUMENT_GIVEN_MESSAGE, COMMAND_NOT_RECOGNISED_MESSAGE } = require("./messages"),
|
|
12
|
-
{ DEFAULT_DRY_RUN, DEFAULT_QUIETLY } = require("./defaults"),
|
|
12
|
+
{ DEFAULT_FORMAT, DEFAULT_DRY_RUN, DEFAULT_QUIETLY } = require("./defaults"),
|
|
13
13
|
{ FIND_COMMAND,
|
|
14
14
|
HELP_COMMAND,
|
|
15
15
|
VERSION_COMMAND,
|
|
@@ -19,7 +19,7 @@ const { NO_ARGUMENT_GIVEN_MESSAGE, COMMAND_NOT_RECOGNISED_MESSAGE } = require(".
|
|
|
19
19
|
REMOVE_ROOT_DIRECTORY_PATH_COMMAND } = require("./commands");
|
|
20
20
|
|
|
21
21
|
function main(command, argument, options) {
|
|
22
|
-
const { dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY } = options;
|
|
22
|
+
const { format = DEFAULT_FORMAT, dryRun = DEFAULT_DRY_RUN, quietly = DEFAULT_QUIETLY } = options;
|
|
23
23
|
|
|
24
24
|
switch (command) {
|
|
25
25
|
case HELP_COMMAND: {
|
|
@@ -68,7 +68,7 @@ function main(command, argument, options) {
|
|
|
68
68
|
} else {
|
|
69
69
|
const string = argument; ///
|
|
70
70
|
|
|
71
|
-
findAction(string, dryRun, quietly);
|
|
71
|
+
findAction(string, dryRun, format, quietly);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
break;
|
package/bin/operation/find.js
CHANGED
|
@@ -100,11 +100,19 @@ function findInFile(filePath, callback, context) {
|
|
|
100
100
|
const { quietly } = context;
|
|
101
101
|
|
|
102
102
|
if (!quietly) {
|
|
103
|
-
|
|
103
|
+
let message;
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
const { format, ruleString } = context;
|
|
106
|
+
|
|
107
|
+
message = filePathIgnored ?
|
|
108
|
+
`Ignore ${filePath}`:
|
|
109
|
+
`Permit ${filePath}`;
|
|
110
|
+
|
|
111
|
+
if (format) {
|
|
112
|
+
message = filePathIgnored ?
|
|
113
|
+
red(message) :
|
|
114
|
+
green(message);
|
|
115
|
+
}
|
|
108
116
|
|
|
109
117
|
message = `${message} ${ruleString}`;
|
|
110
118
|
|
|
@@ -157,11 +165,19 @@ function findInDirectory(directoryPath, callback, context) {
|
|
|
157
165
|
const { quietly } = context;
|
|
158
166
|
|
|
159
167
|
if (!quietly) {
|
|
160
|
-
|
|
168
|
+
let message;
|
|
169
|
+
|
|
170
|
+
const { format, ruleString } = context;
|
|
171
|
+
|
|
172
|
+
message = directoryPathIgnored ?
|
|
173
|
+
`Ignore ${directoryPath}/` :
|
|
174
|
+
`Permit ${directoryPath}/`;
|
|
161
175
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
176
|
+
if (format) {
|
|
177
|
+
message = directoryPathIgnored ?
|
|
178
|
+
red(message) :
|
|
179
|
+
green(message);
|
|
180
|
+
}
|
|
165
181
|
|
|
166
182
|
message = `${message} ${ruleString}`;
|
|
167
183
|
|
package/bin/options.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const HELP_OPTION = "help",
|
|
4
|
+
FORMAT_OPTION = "format",
|
|
4
5
|
VERSION_OPTION = "version",
|
|
5
6
|
QUIETLY_OPTION = "quietly",
|
|
6
7
|
DRY_RUN_OPTION = "dry-run";
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
9
10
|
HELP_OPTION,
|
|
11
|
+
FORMAT_OPTION,
|
|
10
12
|
VERSION_OPTION,
|
|
11
13
|
QUIETLY_OPTION,
|
|
12
14
|
DRY_RUN_OPTION
|
package/bin/utilities/log.js
CHANGED
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
const RED_FOREGROUND_COLOUR = "\u001b[31m",
|
|
4
4
|
GREY_FOREGROUND_COLOUR = "\u001b[90m",
|
|
5
5
|
BLUE_FOREGROUND_COLOUR = "\u001b[34m",
|
|
6
|
-
CYAN_FOREGROUND_COLOUR = "\u001b[36m",
|
|
7
6
|
GREEN_FOREGROUND_COLOUR = "\u001b[32m",
|
|
8
7
|
YELLOW_FOREGROUND_COLOUR = "\u001b[33m",
|
|
9
|
-
MAGENTA_FOREGROUND_COLOUR = "\u001b[35m",
|
|
10
8
|
RESET_FOREGROUND_COLOUR = "\u001b[39m";
|
|
11
9
|
|
|
12
10
|
function red(string) { return `${RED_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
@@ -15,20 +13,14 @@ function grey(string) { return `${GREY_FOREGROUND_COLOUR}${string}${RESET_FOREGR
|
|
|
15
13
|
|
|
16
14
|
function blue(string) { return `${BLUE_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
17
15
|
|
|
18
|
-
function cyan(string) { return `${CYAN_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
19
|
-
|
|
20
16
|
function green(string) { return `${GREEN_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
21
17
|
|
|
22
18
|
function yellow(string) { return `${YELLOW_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
23
19
|
|
|
24
|
-
function magenta(string) { return `${MAGENTA_FOREGROUND_COLOUR}${string}${RESET_FOREGROUND_COLOUR}`; }
|
|
25
|
-
|
|
26
20
|
module.exports = {
|
|
27
21
|
red,
|
|
28
22
|
grey,
|
|
29
23
|
blue,
|
|
30
|
-
cyan,
|
|
31
24
|
green,
|
|
32
|
-
yellow
|
|
33
|
-
magenta
|
|
25
|
+
yellow
|
|
34
26
|
};
|