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
package/README.md CHANGED
@@ -1,21 +1,59 @@
1
1
  # Find-CLI
2
2
 
3
- An alternative to grep.
3
+ Find...
4
4
 
5
5
  ## Installation
6
6
 
7
- You can install Furtle with [npm](https://www.npmjs.com/):
7
+ You can install Find via [npm](https://www.npmjs.com/):
8
8
 
9
- npm install find-cli
9
+ npm install --global find-cli
10
10
 
11
- You can also clone the repository with [Git](https://git-scm.com/):
11
+ You may need to prepend [`sudo`](https://en.wikipedia.org/wiki/Sudo), depending on your setup.
12
+
13
+ If you would like to contribute or would simply like to have a look at the code, you can clone the repository with [Git](https://git-scm.com/)...
12
14
 
13
15
  git clone https://github.com/djalbat/find-cli.git
14
16
 
15
- ...and then install the dependencies with npm from within the project's root directory:
17
+ ...then install the dependencies with npm from within the project's root directory:
16
18
 
17
19
  npm install
18
20
 
21
+ ## Usage
22
+
23
+ Find has the following commands and options:
24
+
25
+ ```
26
+ find [<options>] [<command>] [<argument>]
27
+
28
+ Commands:
29
+
30
+ help Show this help
31
+
32
+ version Show the version
33
+
34
+ initialise Create a configuration file
35
+
36
+ add-root-directory Add a root directory
37
+
38
+ remove-root-directory Remove a root directory
39
+
40
+ list-root-directories List the root directories
41
+
42
+ Options:
43
+
44
+ --help|-h Show this help
45
+
46
+ --version|-v Show the version
47
+
48
+ --dry-run|-d Traverse the directories and files but do not search
49
+
50
+ --quietly|-q Execute shell commands without printing to the console
51
+ ```
52
+
53
+ In the directory that contains the sub-directories holding your project's packages and binaries, run the following command:
54
+
55
+ find initialise
56
+
19
57
  ## Contact
20
58
 
21
59
  * james.smith@djalbat.com
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const { HELP_OPTION, VERSION_OPTION, DRY_RUN_OPTION, QUIETLY_OPTION } = require("./options");
4
+
5
+ module.exports = {
6
+ "h": HELP_OPTION,
7
+ "v": VERSION_OPTION,
8
+ "d": DRY_RUN_OPTION,
9
+ "q": QUIETLY_OPTION
10
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ const addRootDirectoryPathOperation = require("../operation/addRootDirectoryPath"),
4
+ validateRootDirectoryPathOperation = require("../operation/validateRootDirectoryPath"),
5
+ addRootDirectoryPathPromptOperation = require("../operation/prompt/addRootDirectoryPath");
6
+
7
+ const { executeOperations } = require("../utilities/operation"),
8
+ { FAILED_ADD_ROOT_DIRECTORY_MESSAGE, SUCCESSFUL_ADD_ROOT_DIRECTORY_MESSAGE } = require("../messages");
9
+
10
+ function addRootDirectoryPathAction(rootDirectoryPath) {
11
+ const operations = [
12
+ validateRootDirectoryPathOperation,
13
+ addRootDirectoryPathPromptOperation,
14
+ addRootDirectoryPathOperation
15
+ ],
16
+ context = {
17
+ rootDirectoryPath
18
+ };
19
+
20
+ executeOperations(operations, (completed) => {
21
+ if (!completed) {
22
+ console.log(FAILED_ADD_ROOT_DIRECTORY_MESSAGE);
23
+
24
+ return;
25
+ }
26
+
27
+ console.log(SUCCESSFUL_ADD_ROOT_DIRECTORY_MESSAGE);
28
+ }, context);
29
+ }
30
+
31
+ module.exports = addRootDirectoryPathAction;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ const ruleOperation = require("../operation/rule"),
4
+ findOperation = require("../operation/find"),
5
+ readConfigurationOperation = require("../operation/readConfiguration");
6
+
7
+ const { S, EMPTY_STRING } = require("../constants"),
8
+ { executeOperations } = require("../utilities/operation"),
9
+ { FAILED_FIND_MESSAGE, SUCCESSFUL_FIND_MESSAGE } = require("../messages");
10
+
11
+ function findAction(string, dryRun, quietly) {
12
+ const operations = [
13
+ ruleOperation,
14
+ readConfigurationOperation,
15
+ findOperation
16
+ ],
17
+ rule = null,
18
+ lines = [],
19
+ linesTotal = 0,
20
+ filesTotal = 0,
21
+ directoriesTotal = 0,
22
+ occurrencesTotal = 0,
23
+ context = {
24
+ string,
25
+ dryRun,
26
+ quietly,
27
+ rule,
28
+ lines,
29
+ linesTotal,
30
+ filesTotal,
31
+ directoriesTotal,
32
+ occurrencesTotal
33
+ };
34
+
35
+ executeOperations(operations, (completed) => {
36
+ logTottals(context);
37
+
38
+ if (!completed) {
39
+ console.log(FAILED_FIND_MESSAGE);
40
+
41
+ return;
42
+ }
43
+
44
+ logLines(context);
45
+
46
+ console.log(SUCCESSFUL_FIND_MESSAGE);
47
+ }, context);
48
+ }
49
+
50
+ module.exports = findAction;
51
+
52
+ function logLines(context) {
53
+ const { lines } = context;
54
+
55
+ let maximumIndexLength = 0,
56
+ maximumContentLength = 0;
57
+
58
+ lines.forEach((line) => {
59
+ const indexLength = line.getIndexLength(),
60
+ filePathLength = line.getFilePathLength();
61
+
62
+ maximumIndexLength = Math.max(indexLength, maximumIndexLength);
63
+ maximumContentLength = Math.max(filePathLength, maximumContentLength);
64
+ });
65
+
66
+ const requiredIndexLength = maximumIndexLength, ///
67
+ requiredContentLength = maximumContentLength; ///
68
+
69
+ lines.forEach((line) => {
70
+ const message = line.asMessage(requiredIndexLength, requiredContentLength);
71
+
72
+ console.log(message);
73
+ });
74
+ }
75
+
76
+ function logTottals(context) {
77
+ const { linesTotal, filesTotal, directoriesTotal, occurrencesTotal } = context,
78
+ optionalS = (occurrencesTotal === 1) ?
79
+ EMPTY_STRING :
80
+ S,
81
+ message = `Found ${occurrencesTotal} occurrence${optionalS} across ${directoriesTotal} directories, ${filesTotal} files and ${linesTotal} lines.`;
82
+
83
+ console.log(message);
84
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ function helpAction() {
4
+ console.log(`Usage:
5
+
6
+ find [<options>] [<command>] [<argument>]
7
+
8
+ Commands:
9
+
10
+ help Show this help
11
+
12
+ version Show the version
13
+
14
+ initialise Create a configuration file
15
+
16
+ add-root-directory Add a root directory
17
+
18
+ remove-root-directory Remove a root directory
19
+
20
+ list-root-directories List the root directories
21
+
22
+ Options:
23
+
24
+ --help|-h Show this help
25
+
26
+ --version|-v Show the version
27
+
28
+ --dry-run|-d Traverse the directories and files but do not search
29
+
30
+ --quietly|-q Execute shell commands without printing to the console
31
+
32
+ Further information:
33
+
34
+ Please see the readme file on GitHub:
35
+
36
+ https://github.com/djalbat/find-cli
37
+ `);
38
+ }
39
+
40
+ module.exports = helpAction;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ const { createConfigurationFile, checkConfigurationFileExists } = require("../configuration"),
4
+ { FAILED_INITIALISE_MESSAGE, SUCCESSFUL_INITIALISE_MESSAGE } = require("../messages");
5
+
6
+ function initialiseAction() {
7
+ const configurationFileExists = checkConfigurationFileExists();
8
+
9
+ if (configurationFileExists) {
10
+ console.log(FAILED_INITIALISE_MESSAGE);
11
+ } else {
12
+ createConfigurationFile();
13
+
14
+ console.log(SUCCESSFUL_INITIALISE_MESSAGE);
15
+ }
16
+ }
17
+
18
+ module.exports = initialiseAction;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ const listRootDirectoryPathsOperation = require("../operation/listRootDirectoryPaths");
4
+
5
+ const { executeOperations } = require("../utilities/operation");
6
+
7
+ function listRootDirectoryPathsAction() {
8
+ const operations = [
9
+ listRootDirectoryPathsOperation
10
+ ],
11
+ context = {};
12
+
13
+ executeOperations(operations, (completed) => {
14
+ ///
15
+ }, context);
16
+ }
17
+
18
+ module.exports = listRootDirectoryPathsAction;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ const removeRootDirectoryPathOperation = require("../operation/removeRootDirectoryPath"),
4
+ removeRootDirectoryPathPromptOperation = require("../operation/prompt/removeRootDirectoryPath"),
5
+ removeRootDirectoryPathByIndexOperation = require("../operation/removeRootDirectoryPathByIndex");
6
+
7
+ const { executeOperations } = require("../utilities/operation"),
8
+ { FAILED_REMOVE_ROOT_DIRECTORY_MESSAGE, SUCCESSFUL_REMOVE_ROOT_DIRECTORY_MESSAGE } = require("../messages");
9
+
10
+ function removeRootDirectoryPathAction(rootDirectoryPath) {
11
+ const operations = [
12
+ removeRootDirectoryPathOperation,
13
+ removeRootDirectoryPathPromptOperation,
14
+ removeRootDirectoryPathByIndexOperation
15
+ ],
16
+ index = null,
17
+ context = {
18
+ index,
19
+ rootDirectoryPath
20
+ };
21
+
22
+ executeOperations(operations, (completed) => {
23
+ if (!completed) {
24
+ console.log(FAILED_REMOVE_ROOT_DIRECTORY_MESSAGE);
25
+
26
+ return;
27
+ }
28
+
29
+ console.log(SUCCESSFUL_REMOVE_ROOT_DIRECTORY_MESSAGE);
30
+ }, context);
31
+ }
32
+
33
+ module.exports = removeRootDirectoryPathAction;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ const { packageUtilities } = require("necessary");
4
+
5
+ const { FIND_CLI } = require("../constants");
6
+
7
+ const { getVersion } = packageUtilities;
8
+
9
+ function versionAction() {
10
+ const version = getVersion(); ///
11
+
12
+ console.log(`${FIND_CLI} version ${version}`);
13
+ }
14
+
15
+ module.exports = versionAction;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ const FIND_COMMAND = "find",
4
+ HELP_COMMAND = "help",
5
+ VERSION_COMMAND = "version",
6
+ INITIALISE_COMMAND = "initialise",
7
+ ADD_ROOT_DIRECTORY_PATH_COMMAND = "add-root-directory", ///
8
+ LIST_ROOT_DIRECTORY_PATHS_COMMAND = "list-root-directories", ///
9
+ REMOVE_ROOT_DIRECTORY_PATH_COMMAND = "remove-root-directory"; ///
10
+
11
+ module.exports = {
12
+ FIND_COMMAND,
13
+ HELP_COMMAND,
14
+ VERSION_COMMAND,
15
+ INITIALISE_COMMAND,
16
+ ADD_ROOT_DIRECTORY_PATH_COMMAND,
17
+ LIST_ROOT_DIRECTORY_PATHS_COMMAND,
18
+ REMOVE_ROOT_DIRECTORY_PATH_COMMAND
19
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ const { VERSION_1_1 } = require("../versions");
4
+
5
+ function migrateConfigurationToVersion_1_1(configuration) {
6
+ const version = VERSION_1_1;
7
+
8
+ const ignoredFilePaths = [],
9
+ permittedFilePaths = [],
10
+ ignoredDirectoryPaths = [],
11
+ permittedDirectoryPaths = [];
12
+
13
+ configuration = Object.assign(configuration, {
14
+ version,
15
+ ignoredFilePaths,
16
+ permittedFilePaths,
17
+ ignoredDirectoryPaths,
18
+ permittedDirectoryPaths
19
+ });
20
+
21
+ return configuration;
22
+ }
23
+
24
+ module.exports = {
25
+ migrateConfigurationToVersion_1_1
26
+ };
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ const StringRule = require("../rule/string");
4
+
5
+ const { VERSION_1_2 } = require("../versions");
6
+
7
+ function migrateConfigurationToVersion_1_2(configuration) {
8
+ const version = VERSION_1_2;
9
+
10
+ const { ignoredFilePaths, permittedFilePaths, ignoredDirectoryPaths, permittedDirectoryPaths } = configuration,
11
+ ignoredFilePathMatchers = matchersFromPaths(ignoredFilePaths),
12
+ permittedFilePathMatchers = matchersFromPaths(permittedFilePaths),
13
+ ignoredDirectoryPathMatchers = matchersFromPaths(ignoredDirectoryPaths),
14
+ permittedDirectoryPathMatchers = matchersFromPaths(permittedDirectoryPaths);
15
+
16
+ configuration = {
17
+ version,
18
+ ignoredFilePathMatchers,
19
+ permittedFilePathMatchers,
20
+ ignoredDirectoryPathMatchers,
21
+ permittedDirectoryPathMatchers
22
+ };
23
+
24
+ return configuration;
25
+ }
26
+
27
+ module.exports = {
28
+ migrateConfigurationToVersion_1_2
29
+ };
30
+
31
+ function matchersFromPaths(paths) {
32
+ const matchers = paths.map((path) => {
33
+ let matcher;
34
+
35
+ const string = path, ///
36
+ stringRule = StringRule.fromString(string);
37
+
38
+ matcher = stringRule; ///
39
+
40
+ const json = matcher.toJSON();
41
+
42
+ matcher = json; ///
43
+
44
+ return matcher;
45
+ });
46
+
47
+ return matchers;
48
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ const { VERSION_1_3 } = require("../versions"),
4
+ { ROOT_DIRECTORY_PATH } = require("../constants");
5
+
6
+ function migrateConfigurationToVersion_1_3(configuration) {
7
+ const version = VERSION_1_3,
8
+ rootDirectoryPaths = [
9
+ ROOT_DIRECTORY_PATH
10
+ ];
11
+
12
+ Object.assign(configuration, {
13
+ version,
14
+ rootDirectoryPaths
15
+ });
16
+
17
+ return configuration;
18
+ }
19
+
20
+ module.exports = {
21
+ migrateConfigurationToVersion_1_3
22
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ const { VERSION_1_4 } = require("../versions"),
4
+ { ROOT_DIRECTORY_PATH } = require("../constants");
5
+
6
+ function migrateConfigurationToVersion_1_4(configuration) {
7
+ const { ignoredFilePathMatchers,
8
+ permittedFilePathMatchers,
9
+ ignoredDirectoryPathMatchers,
10
+ permittedDirectoryPathMatchers } = configuration;
11
+
12
+ delete configuration.ignoredFilePathMatchers;
13
+ delete configuration.permittedFilePathMatchers;
14
+ delete configuration.ignoredDirectoryPathMatchers;
15
+ delete configuration.permittedDirectoryPathMatchers;
16
+
17
+ const version = VERSION_1_4,
18
+ ignoredFilePathRules = ignoredFilePathMatchers, ///
19
+ permittedFilePathRules = permittedFilePathMatchers, ///
20
+ ignoredDirectoryPathRules = ignoredDirectoryPathMatchers, ///
21
+ permittedDirectoryPathRules = permittedDirectoryPathMatchers; ///
22
+
23
+ Object.assign(configuration, {
24
+ version,
25
+ ignoredFilePathRules,
26
+ permittedFilePathRules,
27
+ ignoredDirectoryPathRules,
28
+ permittedDirectoryPathRules
29
+ });
30
+
31
+ return configuration;
32
+ }
33
+
34
+ function createConfiguration() {
35
+ const version = VERSION_1_4, ///
36
+ rootDirectoryPaths = [
37
+ ROOT_DIRECTORY_PATH
38
+ ],
39
+ ignoredFilePathRules = [],
40
+ permittedFilePathRules = [],
41
+ ignoredDirectoryPathRules = [],
42
+ permittedDirectoryPathRules = [],
43
+ configuration = {
44
+ version,
45
+ rootDirectoryPaths,
46
+ ignoredFilePathRules,
47
+ permittedFilePathRules,
48
+ ignoredDirectoryPathRules,
49
+ permittedDirectoryPathRules
50
+ };
51
+
52
+ return configuration;
53
+ }
54
+
55
+ module.exports = {
56
+ createConfiguration,
57
+ migrateConfigurationToVersion_1_4
58
+ };