find-cli 1.6.4 → 1.7.2

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.
@@ -2,7 +2,8 @@
2
2
 
3
3
  const { shellUtilities } = require("necessary");
4
4
 
5
- const { validateGlobStringOrPattern } = require("../../utilities/validate"),
5
+ const { EMPTY_STRING } = require("../../constants"),
6
+ { validateGlobStringOrPattern } = require("../../utilities/validate"),
6
7
  { GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../../descriptions"),
7
8
  { ruleFromStringAnchoredAndDirectory } = require("../../utilities/rule"),
8
9
  { INVALID_GLOB_REGEX_OR_STRING_MESSAGE } = require("../../messages");
@@ -26,22 +27,33 @@ function rulePromptOperation(proceed, abort, context) {
26
27
  return;
27
28
  }
28
29
 
29
- const { path, anchored, directory } = context,
30
+ const { rule, anchored, directory } = context,
30
31
  description = GLOB_STRING_OR_REGEX_DESCRIPTION,
31
32
  errorMessage = INVALID_GLOB_REGEX_OR_STRING_MESSAGE,
32
- initialAnswer = path, ///
33
33
  validationFunction = (answer) => {
34
- const valid = validateGlobStringOrPattern(answer, anchored, directory);
34
+ let valid = false;
35
+
36
+ if (answer !== EMPTY_STRING) {
37
+ valid = validateGlobStringOrPattern(answer, anchored, directory);
38
+ }
35
39
 
36
40
  return valid;
37
41
  },
38
42
  options = {
39
43
  description,
40
44
  errorMessage,
41
- initialAnswer,
42
45
  validationFunction
43
46
  };
44
47
 
48
+ if (rule !== null) {
49
+ const ruleString = rule.asString(),
50
+ initialAnswer = ruleString; ///
51
+
52
+ Object.assign(options, {
53
+ initialAnswer
54
+ });
55
+ }
56
+
45
57
  prompt(options, (answer) => {
46
58
  const valid = (answer !== null);
47
59
 
@@ -11,9 +11,9 @@ function ruleOperation(proceed, abort, context) {
11
11
  return;
12
12
  }
13
13
 
14
- const { interactive } = context;
14
+ const { previous, interactive } = context;
15
15
 
16
- if (interactive) {
16
+ if (previous || interactive) {
17
17
  proceed();
18
18
 
19
19
  return;
package/bin/options.js CHANGED
@@ -8,6 +8,7 @@ const HELP_OPTION = "help",
8
8
  VERSION_OPTION = "version",
9
9
  QUIETLY_OPTION = "quietly",
10
10
  DRY_RUN_OPTION = "dry-run",
11
+ PREVIOUS_OPTION = "previous",
11
12
  INTERACTIVE_OPTION = "interactive";
12
13
 
13
14
  module.exports = {
@@ -19,5 +20,6 @@ module.exports = {
19
20
  VERSION_OPTION,
20
21
  QUIETLY_OPTION,
21
22
  DRY_RUN_OPTION,
23
+ PREVIOUS_OPTION,
22
24
  INTERACTIVE_OPTION
23
25
  };
package/bin/rule/glob.js CHANGED
@@ -9,12 +9,17 @@ const { GLOB_TYPE } = require("../types"),
9
9
  { addAnchors, addTrailingForwardSlash, removeTrailingForwardSlash } = require("../utilities/string");
10
10
 
11
11
  class GlobRule {
12
- constructor(glob, pattern, regExp) {
12
+ constructor(type, glob, pattern, regExp) {
13
+ this.type = type;
13
14
  this.glob = glob;
14
15
  this.pattern = pattern;
15
16
  this.regExp = regExp;
16
17
  }
17
18
 
19
+ getType() {
20
+ return this.type;
21
+ }
22
+
18
23
  getGlob() {
19
24
  return this.glob;
20
25
  }
@@ -28,7 +33,7 @@ class GlobRule {
28
33
  }
29
34
 
30
35
  toJSON() {
31
- const type = GLOB_TYPE,
36
+ const type = this.type,
32
37
  glob = this.glob,
33
38
  pattern = this.pattern,
34
39
  json = {
@@ -71,6 +76,22 @@ class GlobRule {
71
76
  return matches;
72
77
  }
73
78
 
79
+ isEqualTo(rule) {
80
+ let equalTo = false;
81
+
82
+ const ruleType = rule.getType();
83
+
84
+ if (ruleType === this.type) {
85
+ const ruleGlob = rule.getGlob();
86
+
87
+ if (ruleGlob === this.glob) {
88
+ equalTo = true;
89
+ }
90
+ }
91
+
92
+ return equalTo;
93
+ }
94
+
74
95
  asString() {
75
96
  const string = this.glob; ///
76
97
 
@@ -86,7 +107,7 @@ class GlobRule {
86
107
  const { glob, pattern } = json,
87
108
  regExp = new RegExp(pattern);
88
109
 
89
- globRule = new GlobRule(glob, pattern, regExp);
110
+ globRule = new GlobRule(type, glob, pattern, regExp);
90
111
  }
91
112
 
92
113
  return globRule;
@@ -98,10 +119,11 @@ class GlobRule {
98
119
  const glob = globFromStringAndDirectory(string, directory);
99
120
 
100
121
  if (glob !== null) {
101
- const pattern = patternFromGlobAndAnchored(glob, anchored),
122
+ const type = GLOB_TYPE,
123
+ pattern = patternFromGlobAndAnchored(glob, anchored),
102
124
  regExp = new RegExp(pattern);
103
125
 
104
- globRule = new GlobRule(glob, pattern, regExp);
126
+ globRule = new GlobRule(type, glob, pattern, regExp);
105
127
  }
106
128
 
107
129
  return globRule;
package/bin/rule/regex.js CHANGED
@@ -12,11 +12,16 @@ const { REGEX_TYPE } = require("../types"),
12
12
  removeTrailingEscapedForwardSlash } = require("../utilities/string");
13
13
 
14
14
  class RegexRule {
15
- constructor(pattern, regExp) {
15
+ constructor(type, pattern, regExp) {
16
+ this.type = type;
16
17
  this.pattern = pattern;
17
18
  this.regExp = regExp;
18
19
  }
19
20
 
21
+ getType() {
22
+ return this.type;
23
+ }
24
+
20
25
  getPattern() {
21
26
  return this.pattern;
22
27
  }
@@ -26,7 +31,7 @@ class RegexRule {
26
31
  }
27
32
 
28
33
  toJSON() {
29
- const type = REGEX_TYPE,
34
+ const type = this.type,
30
35
  pattern = this.pattern,
31
36
  json = {
32
37
  type,
@@ -67,6 +72,22 @@ class RegexRule {
67
72
  return matches;
68
73
  }
69
74
 
75
+ isEqualTo(rule) {
76
+ let equalTo = false;
77
+
78
+ const ruleType = rule.getType();
79
+
80
+ if (ruleType === this.type) {
81
+ const rulePattern = rule.getPattern();
82
+
83
+ if (rulePattern === this.pattern) {
84
+ equalTo = true;
85
+ }
86
+ }
87
+
88
+ return equalTo;
89
+ }
90
+
70
91
  asString() {
71
92
  const string = addForwardSlashes(this.pattern); ///
72
93
 
@@ -82,7 +103,7 @@ class RegexRule {
82
103
  const { pattern } = json,
83
104
  regExp = new RegExp(pattern);
84
105
 
85
- regexRule = new RegexRule(pattern, regExp);
106
+ regexRule = new RegexRule(type, pattern, regExp);
86
107
  }
87
108
 
88
109
  return regexRule;
@@ -94,9 +115,10 @@ class RegexRule {
94
115
  const pattern = patternFromStringAndDirectory(string, anchored, directory);
95
116
 
96
117
  if (pattern !== null) {
97
- const regExp = new RegExp(pattern);
118
+ const type = REGEX_TYPE,
119
+ regExp = new RegExp(pattern);
98
120
 
99
- regexRule = new RegexRule(pattern, regExp);
121
+ regexRule = new RegexRule(type, pattern, regExp);
100
122
  }
101
123
 
102
124
  return regexRule;
@@ -7,16 +7,21 @@ const { STRING_TYPE } = require("../types"),
7
7
  { removeDoubleQuotes, addTrailingForwardSlash, removeTrailingForwardSlash } = require("../utilities/string");
8
8
 
9
9
  class StringRule {
10
- constructor(string) {
10
+ constructor(type, string) {
11
+ this.type = type;
11
12
  this.string = string;
12
13
  }
13
14
 
15
+ getType() {
16
+ return this.type;
17
+ }
18
+
14
19
  getString() {
15
20
  return this.string;
16
21
  }
17
22
 
18
23
  toJSON() {
19
- const type = STRING_TYPE,
24
+ const type = this.type,
20
25
  string = this.string,
21
26
  json = {
22
27
  type,
@@ -58,8 +63,26 @@ class StringRule {
58
63
  return matches;
59
64
  }
60
65
 
66
+ isEqualTo(rule) {
67
+ let equalTo = false;
68
+
69
+ const ruleType = rule.getType();
70
+
71
+ if (ruleType === this.type) {
72
+ const ruleString = rule.getString();
73
+
74
+ if (ruleString === this.string) {
75
+ equalTo = true;
76
+ }
77
+ }
78
+
79
+ return equalTo;
80
+ }
81
+
61
82
  asString() {
62
- return this.string;
83
+ const string = `"${this.string}"`;
84
+
85
+ return string;
63
86
  }
64
87
 
65
88
  static fromJSON(json) {
@@ -70,7 +93,7 @@ class StringRule {
70
93
  if (type === STRING_TYPE) {
71
94
  const { string } = json;
72
95
 
73
- stringRule = new StringRule(string);
96
+ stringRule = new StringRule(type, string);
74
97
  }
75
98
 
76
99
  return stringRule;
@@ -82,7 +105,9 @@ class StringRule {
82
105
  string = stringFromStringAndDirectory(string, directory); ///
83
106
 
84
107
  if (string !== null) {
85
- stringRule = new StringRule(string);
108
+ const type = STRING_TYPE; ///
109
+
110
+ stringRule = new StringRule(type, string);
86
111
  }
87
112
 
88
113
  return stringRule;
@@ -0,0 +1,203 @@
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 findInEntries(entryPaths, callback, context) {
15
+ let synchronous = true;
16
+
17
+ let entryNamesLength;
18
+
19
+ entryNamesLength = entryPaths.length;
20
+
21
+ while (entryNamesLength > 0) {
22
+ const entryPath = entryPaths.shift();
23
+
24
+ synchronous = findInEntry(entryPath, entryPaths, callback, context);
25
+
26
+ if (!synchronous) {
27
+ break;
28
+ }
29
+
30
+ entryNamesLength = entryPaths.length;
31
+ }
32
+
33
+ return synchronous;
34
+ }
35
+
36
+ module.exports = {
37
+ findInEntries
38
+ };
39
+
40
+ function findInEntry(entryPath, entryPaths, callback, context) {
41
+ let synchronous;
42
+
43
+ const path = entryPath,
44
+ directory = isEntryDirectory(path);
45
+
46
+ if (directory) {
47
+ const directoryPath = entryPath; ///
48
+
49
+ synchronous = findInDirectory(directoryPath, (pathIgnored) => {
50
+ const synchronous = (pathIgnored !== null) ?
51
+ findInEntries(entryPaths, callback, context) :
52
+ true;
53
+
54
+ if (synchronous) {
55
+ callback(pathIgnored);
56
+ }
57
+ }, context);
58
+ } else {
59
+ const filePath = entryPath; ///
60
+
61
+ synchronous = findInFile(filePath, (pathIgnored) => {
62
+ const synchronous = (pathIgnored !== null) ?
63
+ findInEntries(entryPaths, callback, context) :
64
+ true;
65
+ if (synchronous) {
66
+ callback(pathIgnored);
67
+ }
68
+ }, context);
69
+ }
70
+
71
+ if (synchronous) {
72
+ synchronous = findInEntries(entryPaths, callback, context);
73
+ }
74
+
75
+ return synchronous;
76
+ }
77
+
78
+ function findInFile(filePath, callback, context) {
79
+ let synchronous;
80
+
81
+ const filePathIgnored = synchronousIsFilePathIgnored(filePath, context);
82
+
83
+ if (filePathIgnored !== null) {
84
+ synchronous = true;
85
+
86
+ const { quietly } = context;
87
+
88
+ if (!quietly) {
89
+ let message;
90
+
91
+ const { format, ruleString } = context;
92
+
93
+ message = filePathIgnored ?
94
+ `Ignore ${filePath}`:
95
+ `Permit ${filePath}`;
96
+
97
+ if (format) {
98
+ message = filePathIgnored ?
99
+ red(message) :
100
+ green(message);
101
+ }
102
+
103
+ message = `${message} ${ruleString}`;
104
+
105
+ console.log(message);
106
+ }
107
+
108
+ if (!filePathIgnored) {
109
+ let { filesTotal } = context;
110
+
111
+ filesTotal++;
112
+
113
+ Object.assign(context, {
114
+ filesTotal
115
+ });
116
+
117
+ const { dryRun } = context;
118
+
119
+ if (!dryRun) {
120
+ find(filePath, context);
121
+ }
122
+ }
123
+ } else {
124
+ synchronous = false;
125
+
126
+ asynchronousIsFilePathIgnored(filePath, context, (pathIgnored) => {
127
+ const synchronous = (pathIgnored !== null) ?
128
+ findInFile(filePath, callback, context) :
129
+ true;
130
+
131
+ if (synchronous) {
132
+ callback(pathIgnored);
133
+ }
134
+ });
135
+ }
136
+
137
+ return synchronous;
138
+ }
139
+
140
+ function findInDirectory(directoryPath, callback, context) {
141
+ let synchronous;
142
+
143
+ const directoryPathIgnored = synchronousIsDirectoryPathIgnored(directoryPath, context);
144
+
145
+ if (directoryPathIgnored !== null) {
146
+ synchronous = true;
147
+
148
+ const directoryPathRootDirectoryPath = isDirectoryPathRootDirectoryPath(directoryPath, context);
149
+
150
+ if (!directoryPathRootDirectoryPath) {
151
+ const { quietly } = context;
152
+
153
+ if (!quietly) {
154
+ let message;
155
+
156
+ const { format, ruleString } = context;
157
+
158
+ message = directoryPathIgnored ?
159
+ `Ignore ${directoryPath}/` :
160
+ `Permit ${directoryPath}/`;
161
+
162
+ if (format) {
163
+ message = directoryPathIgnored ?
164
+ red(message) :
165
+ green(message);
166
+ }
167
+
168
+ message = `${message} ${ruleString}`;
169
+
170
+ console.log(message);
171
+ }
172
+ }
173
+
174
+ if (!directoryPathIgnored) {
175
+ let { directoriesTotal } = context;
176
+
177
+ directoriesTotal++;
178
+
179
+ Object.assign(context, {
180
+ directoriesTotal
181
+ });
182
+
183
+ const entryNames = readDirectory(directoryPath),
184
+ entryPaths = entryPathsFromEntryNamesAndDirectoryPath(entryNames, directoryPath);
185
+
186
+ synchronous = findInEntries(entryPaths, callback, context);
187
+ }
188
+ } else {
189
+ synchronous = false;
190
+
191
+ asynchronousIsDirectoryPathIgnored(directoryPath, context, (pathIgnored) => {
192
+ const synchronous = (pathIgnored !== null) ?
193
+ findInDirectory(directoryPath, callback, context) :
194
+ true;
195
+
196
+ if (synchronous) {
197
+ callback(pathIgnored);
198
+ }
199
+ });
200
+ }
201
+
202
+ return synchronous;
203
+ }
@@ -1,7 +1,129 @@
1
1
  "use strict";
2
2
 
3
- function isAnswerIgnore(answer) { return /^(?:ignore|i)$/i.test(answer); }
3
+ const { encodings, characters } = require("necessary");
4
+
5
+ const { DATA } = require("../constants"),
6
+ { PREVIOUS_GLOB_STRING_OR_REGEX_DESCRIPTION } = require("../descriptions");
7
+
8
+ const { UTF8_ENCODING } = encodings,
9
+ { UP_CHARACTER,
10
+ ETX_CHARACTER,
11
+ DOWN_CHARACTER,
12
+ ESCAPE_CHARACTER,
13
+ CTRL_C_CHARACTER,
14
+ NEW_LINE_CHARACTER,
15
+ CARRIAGE_RETURN_CHARACTER } = characters;
16
+
17
+ function selectPreviousRule(previousRules, callback) {
18
+ let index = 0,
19
+ previousRule = previousRules[index];
20
+
21
+ writePreviousRule(previousRule);
22
+
23
+ const rawMode = true,
24
+ encoding = UTF8_ENCODING,
25
+ previousRulesLength = previousRules.length;
26
+
27
+ process.stdin.setRawMode(rawMode);
28
+
29
+ process.stdin.setEncoding(encoding);
30
+
31
+ process.stdin.addListener(DATA, listener);
32
+
33
+ process.stdin.resume();
34
+
35
+ function listener(data) {
36
+ const character = data.toString(encoding);
37
+
38
+ switch (character) {
39
+ case UP_CHARACTER: {
40
+ const firstIndex = 0;
41
+
42
+ if (index > firstIndex) {
43
+ index--;
44
+
45
+ previousRule = previousRules[index];
46
+
47
+ writePreviousRule(previousRule);
48
+ }
49
+
50
+ break;
51
+ }
52
+
53
+ case DOWN_CHARACTER: {
54
+ const lastIndex = previousRulesLength - 1;
55
+
56
+ if (index < lastIndex) {
57
+ index++;
58
+
59
+ previousRule = previousRules[index];
60
+
61
+ writePreviousRule(previousRule);
62
+ }
63
+
64
+ break;
65
+ }
66
+
67
+ case ESCAPE_CHARACTER: {
68
+ previousRule = null;
69
+
70
+ console.log(CARRIAGE_RETURN_CHARACTER);
71
+
72
+ process.stdin.removeListener(DATA, listener);
73
+
74
+ process.stdin.pause();
75
+
76
+ callback(previousRule);
77
+
78
+ break;
79
+ }
80
+
81
+ case NEW_LINE_CHARACTER:
82
+ case CARRIAGE_RETURN_CHARACTER: {
83
+ process.stdout.clearLine();
84
+
85
+ process.stdout.cursorTo(0);
86
+
87
+ process.stdin.removeListener(DATA, listener);
88
+
89
+ process.stdin.pause();
90
+
91
+ callback(previousRule);
92
+
93
+ break;
94
+ }
95
+
96
+ case ETX_CHARACTER: {
97
+ console.log(CTRL_C_CHARACTER);
98
+
99
+ process.exit();
100
+
101
+ break;
102
+ }
103
+
104
+ default: {
105
+ ///
106
+
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ }
4
112
 
5
113
  module.exports = {
6
- isAnswerIgnore
114
+ selectPreviousRule
7
115
  };
116
+
117
+ function writePreviousRule(previousRule) {
118
+ const description = PREVIOUS_GLOB_STRING_OR_REGEX_DESCRIPTION, ///
119
+ previousRuleString = previousRule.asString();
120
+
121
+ process.stdout.clearLine();
122
+
123
+ process.stdout.cursorTo(0);
124
+
125
+ process.stdout.write(description);
126
+
127
+ process.stdout.write(previousRuleString);
128
+ }
129
+
package/bin/versions.js CHANGED
@@ -4,12 +4,14 @@ const VERSION_1_0 = "1.0",
4
4
  VERSION_1_1 = "1.1",
5
5
  VERSION_1_2 = "1.2",
6
6
  VERSION_1_3 = "1.3",
7
- VERSION_1_4 = "1.4";
7
+ VERSION_1_4 = "1.4",
8
+ VERSION_1_7 = "1.7";
8
9
 
9
10
  module.exports = {
10
11
  VERSION_1_0,
11
12
  VERSION_1_1,
12
13
  VERSION_1_2,
13
14
  VERSION_1_3,
14
- VERSION_1_4
15
+ VERSION_1_4,
16
+ VERSION_1_7
15
17
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "find-cli",
3
3
  "author": "James Smith",
4
- "version": "1.6.4",
4
+ "version": "1.7.2",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/find-cli",
7
7
  "description": "An alternative to grep.",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "argumentative": "^2.0.32",
17
- "necessary": "^14.2.3"
17
+ "necessary": "^14.3.2"
18
18
  },
19
19
  "scripts": {}
20
20
  }
@@ -1,27 +0,0 @@
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;