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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { asynchronousUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { whilst } = asynchronousUtilities;
|
|
6
|
+
|
|
7
|
+
function executeOperations(operations, callback, context) {
|
|
8
|
+
let completed = true;
|
|
9
|
+
|
|
10
|
+
const operationsLength = operations.length,
|
|
11
|
+
lastIndex = operationsLength - 1;
|
|
12
|
+
|
|
13
|
+
whilst((next, done, context, index) => {
|
|
14
|
+
if (index > lastIndex) {
|
|
15
|
+
done();
|
|
16
|
+
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const operation = operations[index],
|
|
21
|
+
proceed = next, ///
|
|
22
|
+
abort = () => {
|
|
23
|
+
completed = false;
|
|
24
|
+
|
|
25
|
+
done();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
operation(proceed, abort, context);
|
|
29
|
+
}, done, context);
|
|
30
|
+
|
|
31
|
+
function done() {
|
|
32
|
+
callback(completed);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = {
|
|
37
|
+
executeOperations
|
|
38
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { pathUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { CURRENT_DIRECTORY_PATH } = require("../constants");
|
|
6
|
+
|
|
7
|
+
const { concatenatePaths } = pathUtilities;
|
|
8
|
+
|
|
9
|
+
function stripRootDirectoryFromPath(path, context) {
|
|
10
|
+
const { rootDirectoryPaths } = context;
|
|
11
|
+
|
|
12
|
+
rootDirectoryPaths.some((rootDirectoryPath) => {
|
|
13
|
+
const pathStartsWithRootDirectoryPath = path.startsWith(rootDirectoryPath);
|
|
14
|
+
|
|
15
|
+
if (pathStartsWithRootDirectoryPath) {
|
|
16
|
+
const length = rootDirectoryPath.length,
|
|
17
|
+
start = length;
|
|
18
|
+
|
|
19
|
+
path = path.substring(start); ///
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return path;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isDirectoryPathRootDirectoryPath(directoryPath, context) {
|
|
29
|
+
const { rootDirectoryPaths } = context,
|
|
30
|
+
rootDirectoryPathsIncludesDirectoryPath = rootDirectoryPaths.includes(directoryPath),
|
|
31
|
+
directoryPathRootDirectoryPath = rootDirectoryPathsIncludesDirectoryPath; ///
|
|
32
|
+
|
|
33
|
+
return directoryPathRootDirectoryPath;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function entryPathsFromEntryNamesAndDirectoryPath(entryNames, directoryPath) {
|
|
37
|
+
const entryPaths = entryNames.map((entryName) => {
|
|
38
|
+
const entryPath = entryPathFromEntryNameAndDirectoryPath(entryName, directoryPath);
|
|
39
|
+
|
|
40
|
+
return entryPath
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return entryPaths;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
stripRootDirectoryFromPath,
|
|
48
|
+
isDirectoryPathRootDirectoryPath,
|
|
49
|
+
entryPathsFromEntryNamesAndDirectoryPath
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function entryPathFromEntryNameAndDirectoryPath(entryName, directoryPath) {
|
|
53
|
+
const entryPath = (directoryPath === CURRENT_DIRECTORY_PATH) ?
|
|
54
|
+
entryName : ///
|
|
55
|
+
concatenatePaths(directoryPath, entryName);
|
|
56
|
+
|
|
57
|
+
return entryPath;
|
|
58
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const GlobRule = require("../rule/glob"),
|
|
4
|
+
RegexRule = require("../rule/regex"),
|
|
5
|
+
StringRule = require("../rule/string");
|
|
6
|
+
|
|
7
|
+
function ruleFromStringAnchoredAndDirectory(string, anchored, directory) {
|
|
8
|
+
const globRule = GlobRule.fromStringAnchoredAndDirectory(string, anchored, directory),
|
|
9
|
+
regexRule = RegexRule.fromStringAnchoredAndDirectory(string, anchored, directory),
|
|
10
|
+
stringRule = StringRule.fromStringAnchoredAndDirectory(string, anchored, directory),
|
|
11
|
+
rule = (globRule || regexRule || stringRule);
|
|
12
|
+
|
|
13
|
+
return rule;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
ruleFromStringAnchoredAndDirectory
|
|
18
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { EMPTY_STRING } = require("../constants");
|
|
4
|
+
|
|
5
|
+
function addAnchors(string) { return `^${string}$`; }
|
|
6
|
+
|
|
7
|
+
function removeAnchors(string) { return string.replace(/(^\^|\$$)/g, EMPTY_STRING); }
|
|
8
|
+
|
|
9
|
+
function addDoubleQuotes(string) { return `"${string}"`; }
|
|
10
|
+
|
|
11
|
+
function addForwardSlashes(string) { return `/${string}/`; }
|
|
12
|
+
|
|
13
|
+
function removeDoubleQuotes(string) { return string.replace(/(^"|"$)/g, EMPTY_STRING); }
|
|
14
|
+
|
|
15
|
+
function removeForwardSlashes(string) { return string.replace(/(^\/|\/$)/g, EMPTY_STRING); }
|
|
16
|
+
|
|
17
|
+
function addTrailingForwardSlash(string) { return `${string}\/`; }
|
|
18
|
+
|
|
19
|
+
function removeTrailingForwardSlash(string) { return string.replace(/(\/$)/, EMPTY_STRING); }
|
|
20
|
+
|
|
21
|
+
function addTrailingEscapedForwardSlash(string) { return `${string}\\\/`; }
|
|
22
|
+
|
|
23
|
+
function removeTrailingEscapedForwardSlash(string) { return string.replace(/(\\\/$)/, EMPTY_STRING); }
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
addAnchors,
|
|
27
|
+
removeAnchors,
|
|
28
|
+
addDoubleQuotes,
|
|
29
|
+
addForwardSlashes,
|
|
30
|
+
removeDoubleQuotes,
|
|
31
|
+
removeForwardSlashes,
|
|
32
|
+
addTrailingForwardSlash,
|
|
33
|
+
removeTrailingForwardSlash,
|
|
34
|
+
addTrailingEscapedForwardSlash,
|
|
35
|
+
removeTrailingEscapedForwardSlash
|
|
36
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { ruleFromStringAnchoredAndDirectory } = require("../utilities/rule");
|
|
4
|
+
|
|
5
|
+
function validateIndex(answer, lastIndex) {
|
|
6
|
+
let valid = true;
|
|
7
|
+
|
|
8
|
+
if (valid) {
|
|
9
|
+
valid = /^[1-9][0-9]*$/.test(answer);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (valid) {
|
|
13
|
+
const index = Number(answer);
|
|
14
|
+
|
|
15
|
+
valid = (index <= lastIndex);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return valid;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function validateIgnoreOrPermit(answer) { return /^(:?ignore|permit|i|p)$/i.test(answer); }
|
|
22
|
+
|
|
23
|
+
function validateRootDirectoryPath(answer) {
|
|
24
|
+
let valid = true;
|
|
25
|
+
|
|
26
|
+
if (valid) {
|
|
27
|
+
valid = /^\.\.\/(?:[^/]*\/)+$/i.test(answer);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (valid) {
|
|
31
|
+
const directory = true,
|
|
32
|
+
glob = globFromAnswerAndDirectory(answer, directory);
|
|
33
|
+
|
|
34
|
+
if (glob === null) {
|
|
35
|
+
valid = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return valid;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function validateGlobStringOrPattern(answer, directory) {
|
|
43
|
+
const string = answer, ///
|
|
44
|
+
anchored = false,
|
|
45
|
+
rule = ruleFromStringAnchoredAndDirectory(string, anchored, directory),
|
|
46
|
+
valid = (rule !== null)
|
|
47
|
+
|
|
48
|
+
return valid;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
validateIndex,
|
|
53
|
+
validateIgnoreOrPermit,
|
|
54
|
+
validateRootDirectoryPath,
|
|
55
|
+
validateGlobStringOrPattern
|
|
56
|
+
};
|
package/bin/versions.js
ADDED
package/find.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { parseArgv } = require("argumentative"),
|
|
4
|
+
{ arrayUtilities } = require("necessary");
|
|
5
|
+
|
|
6
|
+
const main = require("./bin/main"),
|
|
7
|
+
prepare = require("./bin/prepare"),
|
|
8
|
+
abbreviations = require("./bin/abbreviations");
|
|
9
|
+
|
|
10
|
+
const { first, second } = arrayUtilities;
|
|
11
|
+
|
|
12
|
+
const { commands, options } = parseArgv(process.argv, abbreviations),
|
|
13
|
+
firstCommand = first(commands),
|
|
14
|
+
secondCommand = second(commands),
|
|
15
|
+
command = firstCommand || null, ///
|
|
16
|
+
argument = secondCommand || null; ///
|
|
17
|
+
|
|
18
|
+
prepare(command, argument, options, main);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "find-cli",
|
|
3
3
|
"author": "James Smith",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.4.3",
|
|
5
5
|
"license": "MIT, Anti-996",
|
|
6
6
|
"homepage": "https://github.com/djalbat/find-cli",
|
|
7
7
|
"description": "An alternative to grep.",
|
|
@@ -9,9 +9,12 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "https://github.com/djalbat/find-cli"
|
|
11
11
|
},
|
|
12
|
+
"bin": {
|
|
13
|
+
"find": "./find.js"
|
|
14
|
+
},
|
|
12
15
|
"dependencies": {
|
|
13
16
|
"argumentative": "^2.0.32",
|
|
14
|
-
"necessary": "^14.2.
|
|
17
|
+
"necessary": "^14.2.3"
|
|
15
18
|
},
|
|
16
19
|
"scripts": {}
|
|
17
20
|
}
|