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.
Files changed (68) hide show
  1. package/README.md +43 -5
  2. package/bin/abbreviations.js +10 -0
  3. package/bin/action/addRootDirectoryPath.js +31 -0
  4. package/bin/action/find.js +84 -0
  5. package/bin/action/help.js +40 -0
  6. package/bin/action/initialise.js +18 -0
  7. package/bin/action/listRootDirectoryPaths.js +18 -0
  8. package/bin/action/removeRootDirectoryPath.js +33 -0
  9. package/bin/action/version.js +15 -0
  10. package/bin/commands.js +19 -0
  11. package/bin/configuration/version_1_1.js +26 -0
  12. package/bin/configuration/version_1_2.js +48 -0
  13. package/bin/configuration/version_1_3.js +22 -0
  14. package/bin/configuration/version_1_4.js +58 -0
  15. package/bin/configuration.js +230 -0
  16. package/bin/constants.js +25 -0
  17. package/bin/converter/alternates.js +29 -0
  18. package/bin/converter/characterClass.js +45 -0
  19. package/bin/converter/default.js +19 -0
  20. package/bin/converter/directory.js +19 -0
  21. package/bin/converter/escapedCharacter.js +19 -0
  22. package/bin/converter/period.js +19 -0
  23. package/bin/converter/questionMark.js +19 -0
  24. package/bin/converter/repeatedDirectories.js +19 -0
  25. package/bin/converter/repeatedWildcard.js +19 -0
  26. package/bin/converter/singleDirectory.js +19 -0
  27. package/bin/converter/singleWildcard.js +19 -0
  28. package/bin/converter.js +48 -0
  29. package/bin/converters.js +29 -0
  30. package/bin/defaults.js +13 -0
  31. package/bin/descriptions.js +11 -0
  32. package/bin/find.js +55 -0
  33. package/bin/isIgnored/asynchronous.js +59 -0
  34. package/bin/isIgnored/synchronous.js +104 -0
  35. package/bin/line.js +181 -0
  36. package/bin/main.js +85 -0
  37. package/bin/messages.js +37 -0
  38. package/bin/occurrence.js +40 -0
  39. package/bin/operation/addRootDirectoryPath.js +16 -0
  40. package/bin/operation/find.js +201 -0
  41. package/bin/operation/listRootDirectoryPaths.js +34 -0
  42. package/bin/operation/prompt/addRootDirectoryPath.js +48 -0
  43. package/bin/operation/prompt/ignoreOrPermitPath.js +46 -0
  44. package/bin/operation/prompt/removeRootDirectoryPath.js +61 -0
  45. package/bin/operation/prompt/rule.js +50 -0
  46. package/bin/operation/readConfiguration.js +27 -0
  47. package/bin/operation/removeRootDirectoryPath.js +29 -0
  48. package/bin/operation/removeRootDirectoryPathByIndex.js +34 -0
  49. package/bin/operation/rule.js +32 -0
  50. package/bin/operation/updatePatRules.js +54 -0
  51. package/bin/operation/validateRootDirectoryPath.js +30 -0
  52. package/bin/options.js +13 -0
  53. package/bin/prepare.js +51 -0
  54. package/bin/rule/glob.js +170 -0
  55. package/bin/rule/regex.js +141 -0
  56. package/bin/rule/string.js +117 -0
  57. package/bin/types.js +11 -0
  58. package/bin/utilities/literal.js +19 -0
  59. package/bin/utilities/log.js +26 -0
  60. package/bin/utilities/operation.js +38 -0
  61. package/bin/utilities/path.js +58 -0
  62. package/bin/utilities/prompt.js +7 -0
  63. package/bin/utilities/rule.js +18 -0
  64. package/bin/utilities/string.js +36 -0
  65. package/bin/utilities/validate.js +56 -0
  66. package/bin/versions.js +15 -0
  67. package/find.js +18 -0
  68. package/package.json +5 -2
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+
3
+ const { versionUtilities, configurationUtilities } = require("necessary");
4
+
5
+ const GlobRule = require("./rule/glob"),
6
+ RegexRule = require("./rule/regex"),
7
+ StringRule = require("./rule/string");
8
+
9
+ const { FIND } = require("./constants"),
10
+ { createConfiguration } = require("./configuration/version_1_4"),
11
+ { migrateConfigurationToVersion_1_1 } = require("./configuration/version_1_1"),
12
+ { migrateConfigurationToVersion_1_2 } = require("./configuration/version_1_2"),
13
+ { migrateConfigurationToVersion_1_3 } = require("./configuration/version_1_3"),
14
+ { migrateConfigurationToVersion_1_4 } = require("./configuration/version_1_4"),
15
+ { CONFIGURATION_FILE_DOES_NOT_EXIST_MESSAGE } = require("./messages"),
16
+ { VERSION_1_0, VERSION_1_1, VERSION_1_2, VERSION_1_3, VERSION_1_4 } = require("./versions");
17
+
18
+ const { rc } = configurationUtilities,
19
+ { migrate } = versionUtilities,
20
+ { setRCBaseExtension, checkRCFileExists, updateRCFile, writeRCFile, readRCFile } = rc;
21
+
22
+ setRCBaseExtension(FIND);
23
+
24
+ function retrieveRootDirectoryPaths() {
25
+ const configuration = readConfigurationFile(),
26
+ { rootDirectoryPaths } = configuration;
27
+
28
+ return rootDirectoryPaths;
29
+ }
30
+
31
+ function retrieveIgnoredFilePathRules() {
32
+ const configuration = readConfigurationFile();
33
+
34
+ let { ignoredFilePathRules } = configuration;
35
+
36
+ const ignoredFilePathRulesJSON = ignoredFilePathRules; ///
37
+
38
+ ignoredFilePathRules = rulesFromPathRulesJSON(ignoredFilePathRulesJSON);
39
+
40
+ return ignoredFilePathRules;
41
+ }
42
+
43
+ function retrievePermittedFilePathRules() {
44
+ const configuration = readConfigurationFile();
45
+
46
+ let { permittedFilePathRules } = configuration;
47
+
48
+ const permittedFilePathRulesJSON = permittedFilePathRules; ///
49
+
50
+ permittedFilePathRules = rulesFromPathRulesJSON(permittedFilePathRulesJSON);
51
+
52
+ return permittedFilePathRules;
53
+ }
54
+
55
+ function retrieveIgnoredDirectoryPathRules() {
56
+ const configuration = readConfigurationFile();
57
+
58
+ let { ignoredDirectoryPathRules } = configuration;
59
+
60
+ const ignoredDirectoryPathRulesJSON = ignoredDirectoryPathRules; ///
61
+
62
+ ignoredDirectoryPathRules = rulesFromPathRulesJSON(ignoredDirectoryPathRulesJSON);
63
+
64
+ return ignoredDirectoryPathRules;
65
+ }
66
+
67
+ function retrievePermittedDirectoryPathRules() {
68
+ const configuration = readConfigurationFile();
69
+
70
+ let { permittedDirectoryPathRules } = configuration;
71
+
72
+ const permittedDirectoryPathRulesJSON = permittedDirectoryPathRules; ///
73
+
74
+ permittedDirectoryPathRules = rulesFromPathRulesJSON(permittedDirectoryPathRulesJSON);
75
+
76
+ return permittedDirectoryPathRules;
77
+ }
78
+
79
+ function updateRootDirectoryPaths(rootDirectoryPaths) {
80
+ updateConfigurationFile({
81
+ rootDirectoryPaths
82
+ });
83
+ }
84
+
85
+ function updateIgnoredFilePathRules(ignoredFilePathRules) {
86
+ const ignoredFilePathRulesJSON = rulesJSONFromRules(ignoredFilePathRules);
87
+
88
+ ignoredFilePathRules = ignoredFilePathRulesJSON; ///
89
+
90
+ updateConfigurationFile({
91
+ ignoredFilePathRules
92
+ });
93
+ }
94
+
95
+ function updatePermittedFilePathRules(permittedFilePathRules) {
96
+ const permittedFilePathRulesJSON = rulesJSONFromRules(permittedFilePathRules);
97
+
98
+ permittedFilePathRules = permittedFilePathRulesJSON; ///
99
+
100
+ updateConfigurationFile({
101
+ permittedFilePathRules
102
+ });
103
+ }
104
+
105
+ function updateIgnoredDirectoryPathRules(ignoredDirectoryPathRules) {
106
+ const ignoredDirectoryPathRulesJSON = rulesJSONFromRules(ignoredDirectoryPathRules);
107
+
108
+ ignoredDirectoryPathRules = ignoredDirectoryPathRulesJSON; ///
109
+
110
+ updateConfigurationFile({
111
+ ignoredDirectoryPathRules
112
+ });
113
+ }
114
+
115
+ function updatePermittedDirectoryPathRules(permittedDirectoryPathRules) {
116
+ const permittedDirectoryPathRulesJSON = rulesJSONFromRules(permittedDirectoryPathRules);
117
+
118
+ permittedDirectoryPathRules = permittedDirectoryPathRulesJSON; ///
119
+
120
+ updateConfigurationFile({
121
+ permittedDirectoryPathRules
122
+ });
123
+ }
124
+
125
+ function createConfigurationFile() {
126
+ const configuration = createConfiguration(),
127
+ json = configuration; ///
128
+
129
+ writeRCFile(json);
130
+ }
131
+
132
+ function migrateConfigurationFile() {
133
+ assertConfigurationFileExists();
134
+
135
+ let json = readRCFile();
136
+
137
+ const migrationMap = {
138
+ [ VERSION_1_0 ]: migrateConfigurationToVersion_1_1,
139
+ [ VERSION_1_1 ]: migrateConfigurationToVersion_1_2,
140
+ [ VERSION_1_2 ]: migrateConfigurationToVersion_1_3,
141
+ [ VERSION_1_3 ]: migrateConfigurationToVersion_1_4
142
+ },
143
+ latestVersion = VERSION_1_4;
144
+
145
+ json = migrate(json, migrationMap, latestVersion);
146
+
147
+ writeRCFile(json);
148
+ }
149
+
150
+ function checkConfigurationFileExists() {
151
+ const rcFileExists = checkRCFileExists(),
152
+ configurationFileExists = rcFileExists; ///
153
+
154
+ return configurationFileExists;
155
+ }
156
+
157
+ function assertConfigurationFileExists() {
158
+ const configurationFileExists = checkConfigurationFileExists();
159
+
160
+ if (!configurationFileExists) {
161
+ console.log(CONFIGURATION_FILE_DOES_NOT_EXIST_MESSAGE);
162
+
163
+ process.exit(1);
164
+ }
165
+ }
166
+
167
+ module.exports = {
168
+ retrieveRootDirectoryPaths,
169
+ retrieveIgnoredFilePathRules,
170
+ retrievePermittedFilePathRules,
171
+ retrieveIgnoredDirectoryPathRules,
172
+ retrievePermittedDirectoryPathRules,
173
+ updateRootDirectoryPaths,
174
+ updateIgnoredFilePathRules,
175
+ updatePermittedFilePathRules,
176
+ updateIgnoredDirectoryPathRules,
177
+ updatePermittedDirectoryPathRules,
178
+ createConfigurationFile,
179
+ migrateConfigurationFile,
180
+ checkConfigurationFileExists
181
+ };
182
+
183
+ function readConfigurationFile() {
184
+ assertConfigurationFileExists();
185
+
186
+ const json = readRCFile(),
187
+ configuration = json; ///
188
+
189
+ return configuration;
190
+ }
191
+
192
+ function writeConfigurationFile(configuration) {
193
+ assertConfigurationFileExists();
194
+
195
+ const json = configuration; ///
196
+
197
+ writeRCFile(json);
198
+ }
199
+
200
+ function updateConfigurationFile(addedConfiguration, ...deleteConfigurationNames) {
201
+ assertConfigurationFileExists();
202
+
203
+ const addedProperties = addedConfiguration, ///
204
+ deletedPropertyNames = deleteConfigurationNames; ///
205
+
206
+ updateRCFile(addedProperties, ...deletedPropertyNames);
207
+ }
208
+
209
+ function rulesFromPathRulesJSON(rulesJSON) {
210
+ const rules = rulesJSON.map((ruleJSON) => {
211
+ const json = ruleJSON, ///
212
+ rule = GlobRule.fromJSON(json) ||
213
+ RegexRule.fromJSON(json) ||
214
+ StringRule.fromJSON(json);
215
+
216
+ return rule;
217
+ });
218
+
219
+ return rules;
220
+ }
221
+
222
+ function rulesJSONFromRules(rules) {
223
+ const rulesJSON = rules.map((rule) => {
224
+ const ruleJSON = rule.toJSON();
225
+
226
+ return ruleJSON;
227
+ });
228
+
229
+ return rulesJSON;
230
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ const S = "s",
4
+ ZERO = 0,
5
+ FIND = "find",
6
+ FILE = "file",
7
+ G_FLAG = "g",
8
+ FIND_CLI = "Find-CLI",
9
+ DIRECTORY = "directory",
10
+ EMPTY_STRING = "",
11
+ SINGLE_SPACE = " ",
12
+ ROOT_DIRECTORY_PATH = "./";
13
+
14
+ module.exports = {
15
+ S,
16
+ ZERO,
17
+ FIND,
18
+ FILE,
19
+ G_FLAG,
20
+ FIND_CLI,
21
+ DIRECTORY,
22
+ EMPTY_STRING,
23
+ SINGLE_SPACE,
24
+ ROOT_DIRECTORY_PATH
25
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ const { characters } = require("necessary");
4
+
5
+ const Converter = require("../converter");
6
+
7
+ const { BAR_CHARACTER, COMMA_CHARACTER } = characters;
8
+
9
+ class AlternatesConverter extends Converter {
10
+ callback(characters) {
11
+ characters.pop();
12
+
13
+ characters.shift();
14
+
15
+ const alternates = characters.split(COMMA_CHARACTER),
16
+ alternation = alternates.join(BAR_CHARACTER),
17
+ result = `(${alternation})`;
18
+
19
+ return result;
20
+ }
21
+
22
+ static regex = /^{[^}]+}/;
23
+
24
+ static fromNothing() { return Converter.fromNothing(AlternatesConverter); }
25
+ }
26
+
27
+ const alternatesConverter = AlternatesConverter.fromNothing();
28
+
29
+ module.exports = alternatesConverter;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ const { characters } = require("necessary");
4
+
5
+ const Converter = require("../converter");
6
+
7
+ const { HAT_CHARACTER, EXCLAMATION_MARK_CHARACTER } = characters;
8
+
9
+ class CharacterClassConverter extends Converter {
10
+ callback(characters) {
11
+ characters.pop();
12
+
13
+ characters.shift();
14
+
15
+ let negated = true;
16
+
17
+ const firstCharacter = characters.shift() || null;
18
+
19
+ if (firstCharacter !== null) {
20
+ if ((firstCharacter === HAT_CHARACTER) || (firstCharacter === EXCLAMATION_MARK_CHARACTER)) {
21
+ negated = true;
22
+ } else {
23
+ characters.unshift(firstCharacter);
24
+ }
25
+ }
26
+
27
+ let characterClass = `${characters}`;
28
+
29
+ if (negated) {
30
+ characterClass = `^${characterClass}`;
31
+ }
32
+
33
+ const result = `[${characterClass}]`;
34
+
35
+ return result;
36
+ }
37
+
38
+ static regex = /^\[[^\]]+]/;
39
+
40
+ static fromNothing() { return Converter.fromNothing(CharacterClassConverter); }
41
+ }
42
+
43
+ const characterClassConverter = CharacterClassConverter.fromNothing();
44
+
45
+ module.exports = characterClassConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class DefaultConverter extends Converter {
6
+ callback(characters) {
7
+ const result = characters; ///
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /./;
13
+
14
+ static fromNothing() { return Converter.fromNothing(DefaultConverter); }
15
+ }
16
+
17
+ const defaultConverter = DefaultConverter.fromNothing();
18
+
19
+ module.exports = defaultConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class DirectoryConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `\\/`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\//;
13
+
14
+ static fromNothing() { return Converter.fromNothing(DirectoryConverter); }
15
+ }
16
+
17
+ const directoryConverter = DirectoryConverter.fromNothing();
18
+
19
+ module.exports = directoryConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class EscapedCharacterConverter extends Converter {
6
+ callback(characters) {
7
+ const result = characters; ///
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\\./;
13
+
14
+ static fromNothing() { return Converter.fromNothing(EscapedCharacterConverter); }
15
+ }
16
+
17
+ const questionMarkCharacterConverter = EscapedCharacterConverter.fromNothing();
18
+
19
+ module.exports = questionMarkCharacterConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class PeriodConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `\\.`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\./;
13
+
14
+ static fromNothing() { return Converter.fromNothing(PeriodConverter); }
15
+ }
16
+
17
+ const periodConverter = PeriodConverter.fromNothing();
18
+
19
+ module.exports = periodConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class QuestionMarkConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `.`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\?/;
13
+
14
+ static fromNothing() { return Converter.fromNothing(QuestionMarkConverter); }
15
+ }
16
+
17
+ const questionMarkConverter = QuestionMarkConverter.fromNothing();
18
+
19
+ module.exports = questionMarkConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class RepeatedDirectoriesConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `(?:[^/]*\\/)*`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\*\*\//;
13
+
14
+ static fromNothing() { return Converter.fromNothing(RepeatedDirectoriesConverter); }
15
+ }
16
+
17
+ const repeatedDirectoriesConverter = RepeatedDirectoriesConverter.fromNothing();
18
+
19
+ module.exports = repeatedDirectoriesConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class RepeatedWildcardConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `.*`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\*\*/;
13
+
14
+ static fromNothing() { return Converter.fromNothing(RepeatedWildcardConverter); }
15
+ }
16
+
17
+ const singleDirectoryConverter = RepeatedWildcardConverter.fromNothing();
18
+
19
+ module.exports = singleDirectoryConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class SingleDirectoryConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `[^/]*\\/`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\*\//;
13
+
14
+ static fromNothing() { return Converter.fromNothing(SingleDirectoryConverter); }
15
+ }
16
+
17
+ const singleDirectoryConverter = SingleDirectoryConverter.fromNothing();
18
+
19
+ module.exports = singleDirectoryConverter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const Converter = require("../converter");
4
+
5
+ class SingleWildcardConverter extends Converter {
6
+ callback(characters) {
7
+ const result = `.+?`;
8
+
9
+ return result;
10
+ }
11
+
12
+ static regex = /^\*/;
13
+
14
+ static fromNothing() { return Converter.fromNothing(SingleWildcardConverter); }
15
+ }
16
+
17
+ const singleWildcardConverter = SingleWildcardConverter.fromNothing();
18
+
19
+ module.exports = singleWildcardConverter;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ const { arrayUtilities } = require("necessary");
4
+
5
+ const { EMPTY_STRING } = require("./constants");
6
+
7
+ const { first } = arrayUtilities;
8
+
9
+ class Converter {
10
+ constructor(regex) {
11
+ this.regex = regex;
12
+ }
13
+
14
+ getRegex() {
15
+ return this.regex;
16
+ }
17
+
18
+ match(characters) {
19
+ let result = null;
20
+
21
+ const string = characters.join(EMPTY_STRING),
22
+ matches = this.regex.exec(string);
23
+
24
+ if (matches !== null) {
25
+ const firstMatch = first(matches),
26
+ match = firstMatch; ///
27
+
28
+ result = this.callback(match);
29
+
30
+ const length = match.length,
31
+ start = 0,
32
+ deleteCount = length;
33
+
34
+ characters.splice(start, deleteCount);
35
+ }
36
+
37
+ return result;
38
+ }
39
+
40
+ static fromNothing(Class) {
41
+ const { regex } = Class,
42
+ converter = new Class(regex);
43
+
44
+ return converter;
45
+ }
46
+ }
47
+
48
+ module.exports = Converter;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ const periodConverter = require("./converter/period"),
4
+ defaultConverter = require("./converter/default"),
5
+ directoryConverter = require("./converter/directory"),
6
+ alternatesConverter = require("./converter/alternates"),
7
+ questionMarkConverter = require("./converter/questionMark"),
8
+ characterClassConverter = require("./converter/characterClass"),
9
+ singleWildcardConverter = require("./converter/singleWildcard"),
10
+ singleDirectoryConverter = require("./converter/singleDirectory"),
11
+ repeatedWildcardConverter = require("./converter/repeatedWildcard"),
12
+ escapedCharacterConverter = require("./converter/escapedCharacter"),
13
+ repeatedDirectoriesConverter = require("./converter/repeatedDirectories");
14
+
15
+ const converters = [
16
+ repeatedDirectoriesConverter,
17
+ singleDirectoryConverter,
18
+ directoryConverter,
19
+ repeatedWildcardConverter,
20
+ singleWildcardConverter,
21
+ escapedCharacterConverter,
22
+ questionMarkConverter,
23
+ periodConverter,
24
+ alternatesConverter,
25
+ characterClassConverter,
26
+ defaultConverter
27
+ ];
28
+
29
+ module.exports = converters;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ const DEFAULT_HELP = false,
4
+ DEFAULT_VERSION = false,
5
+ DEFAULT_DRY_RUN = false,
6
+ DEFAULT_QUIETLY = false;
7
+
8
+ module.exports = {
9
+ DEFAULT_HELP,
10
+ DEFAULT_VERSION,
11
+ DEFAULT_DRY_RUN,
12
+ DEFAULT_QUIETLY
13
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ const GLOB_STRING_OR_REGEX_DESCRIPTION = `Glob, string or regex: `,
4
+ ADD_ROOT_DIRECTORY_PATH_DESCRIPTION = `Root directory: `,
5
+ REMOVE_ROOT_DIRECTORY_PATH_DESCRIPTION = `Root directory index: `;
6
+
7
+ module.exports = {
8
+ GLOB_STRING_OR_REGEX_DESCRIPTION,
9
+ ADD_ROOT_DIRECTORY_PATH_DESCRIPTION,
10
+ REMOVE_ROOT_DIRECTORY_PATH_DESCRIPTION
11
+ };
package/bin/find.js ADDED
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ const { fileSystemUtilities } = require("necessary");
4
+
5
+ const Line = require("./line");
6
+
7
+ const { readFile } = fileSystemUtilities;
8
+
9
+ function find(filePath, context) {
10
+ const { rule } = context,
11
+ content = readFile(filePath),
12
+ lines = linesFromContentAndFilePath(content, filePath);
13
+
14
+ let { linesTotal } = context;
15
+
16
+ lines.forEach((line) => {
17
+ const occurrences = rule.find(line, filePath),
18
+ occurrencesLength = occurrences.length;
19
+
20
+ if (occurrencesLength > 0) {
21
+ let { occurrencesTotal } = context;
22
+
23
+ occurrencesTotal += occurrencesLength;
24
+
25
+ Object.assign(context, {
26
+ occurrencesTotal
27
+ });
28
+
29
+ const { lines } = context;
30
+
31
+ lines.push(line);
32
+
33
+ line.setOccurrences(occurrences);
34
+ }
35
+
36
+ linesTotal++;
37
+ });
38
+
39
+ Object.assign(context, {
40
+ linesTotal
41
+ });
42
+ }
43
+
44
+ module.exports = find;
45
+
46
+ function linesFromContentAndFilePath(content, filePath) {
47
+ const contents = content.split(/(\r\n|\r|\n)/),
48
+ lines = contents.map((content, index) => {
49
+ const line = Line.fromIndexContentAndFilePath(index, content, filePath);
50
+
51
+ return line;
52
+ });
53
+
54
+ return lines;
55
+ }