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/README.md
CHANGED
|
@@ -1,21 +1,59 @@
|
|
|
1
1
|
# Find-CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Find...
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
You can install
|
|
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
|
|
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
|
-
...
|
|
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,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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const ruleOperation = require("../operation/rule"),
|
|
4
|
+
findOperation = require("../operation/find"),
|
|
5
|
+
readConfigurationOperation = require("../operation/readConfiguration");
|
|
6
|
+
|
|
7
|
+
const { executeOperations } = require("../utilities/operation"),
|
|
8
|
+
{ FAILED_FIND_MESSAGE, SUCCESSFUL_FIND_MESSAGE } = require("../messages");
|
|
9
|
+
|
|
10
|
+
function findAction(string, dryRun, quietly) {
|
|
11
|
+
const operations = [
|
|
12
|
+
ruleOperation,
|
|
13
|
+
readConfigurationOperation,
|
|
14
|
+
findOperation
|
|
15
|
+
],
|
|
16
|
+
rule = null,
|
|
17
|
+
totalLines = 0,
|
|
18
|
+
totalFiles = 0,
|
|
19
|
+
totalDirectories = 0,
|
|
20
|
+
context = {
|
|
21
|
+
string,
|
|
22
|
+
dryRun,
|
|
23
|
+
quietly,
|
|
24
|
+
rule,
|
|
25
|
+
totalLines,
|
|
26
|
+
totalFiles,
|
|
27
|
+
totalDirectories
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
executeOperations(operations, (completed) => {
|
|
31
|
+
const { totalLines, totalFiles, totalDirectories } = context,
|
|
32
|
+
message = `A total of ${totalDirectories} directories, ${totalFiles} files and ${totalLines} lines searched.`;
|
|
33
|
+
|
|
34
|
+
console.log(message);
|
|
35
|
+
|
|
36
|
+
if (!completed) {
|
|
37
|
+
console.log(FAILED_FIND_MESSAGE);
|
|
38
|
+
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
console.log(SUCCESSFUL_FIND_MESSAGE);
|
|
43
|
+
}, context);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = findAction;
|
|
@@ -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;
|
package/bin/commands.js
ADDED
|
@@ -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
|
+
};
|
|
@@ -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
|
+
}
|