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/bin/constants.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const FIND = "find",
|
|
4
|
+
FILE = "file",
|
|
5
|
+
G_FLAG = "g",
|
|
6
|
+
FIND_CLI = "Find-CLI",
|
|
7
|
+
DIRECTORY = "directory",
|
|
8
|
+
EMPTY_STRING = "",
|
|
9
|
+
ROOT_DIRECTORY_PATH = "./";
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
FIND,
|
|
13
|
+
FILE,
|
|
14
|
+
G_FLAG,
|
|
15
|
+
FIND_CLI,
|
|
16
|
+
DIRECTORY,
|
|
17
|
+
EMPTY_STRING,
|
|
18
|
+
ROOT_DIRECTORY_PATH
|
|
19
|
+
};
|
|
@@ -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;
|
package/bin/converter.js
ADDED
|
@@ -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;
|
package/bin/defaults.js
ADDED
|
@@ -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,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { arrayUtilities, fileSystemUtilities } = require("necessary");
|
|
4
|
+
|
|
5
|
+
const { grey, blue } = require("./utilities/log"),
|
|
6
|
+
{ EMPTY_STRING } = require("./constants");
|
|
7
|
+
|
|
8
|
+
const { readFile } = fileSystemUtilities,
|
|
9
|
+
{ backwardsForEach } = arrayUtilities;
|
|
10
|
+
|
|
11
|
+
function find(filePath, context) {
|
|
12
|
+
const { rule } = context,
|
|
13
|
+
content = readFile(filePath),
|
|
14
|
+
lines = linesFromContent(content);
|
|
15
|
+
|
|
16
|
+
let { totalLines } = context;
|
|
17
|
+
|
|
18
|
+
lines.forEach((line, index) => {
|
|
19
|
+
const string = line, ///
|
|
20
|
+
occurrences = rule.find(string),
|
|
21
|
+
length = occurrences.length;
|
|
22
|
+
|
|
23
|
+
if (length > 0) {
|
|
24
|
+
const gaps = [],
|
|
25
|
+
matches = [];
|
|
26
|
+
|
|
27
|
+
gapsAndMatchesFromLineAndOccurrences(line, occurrences, gaps, matches);
|
|
28
|
+
|
|
29
|
+
line = lineFromGapsAndMatches(gaps, matches); ///
|
|
30
|
+
|
|
31
|
+
console.log(filePath, index, line);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
totalLines++;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
Object.assign(context, {
|
|
38
|
+
totalLines
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = find;
|
|
43
|
+
|
|
44
|
+
function linesFromContent(content) {
|
|
45
|
+
const contents = content.split(/(\r\n|\r|\n)/),
|
|
46
|
+
lines = contents.map((content) => {
|
|
47
|
+
const line = content.replace(/(\r\n|\r|\n)$/, EMPTY_STRING);
|
|
48
|
+
|
|
49
|
+
return line;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return lines;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function lineFromGapsAndMatches(gaps, matches) {
|
|
56
|
+
let line = EMPTY_STRING;
|
|
57
|
+
|
|
58
|
+
gaps = [ ...gaps ]; ///
|
|
59
|
+
|
|
60
|
+
let gap = gaps.pop(); ///
|
|
61
|
+
|
|
62
|
+
gaps.forEach((gap, index) => {
|
|
63
|
+
let match = matches[index];
|
|
64
|
+
|
|
65
|
+
gap = grey(gap); ///
|
|
66
|
+
|
|
67
|
+
match = blue(match); ///
|
|
68
|
+
|
|
69
|
+
line = `${line}${gap}${match}`;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
gap = grey(gap); ///
|
|
73
|
+
|
|
74
|
+
line = `${line}${gap}`;
|
|
75
|
+
|
|
76
|
+
return line;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function gapsAndMatchesFromLineAndOccurrences(line, occurrences, gaps, matches) {
|
|
80
|
+
let end,
|
|
81
|
+
start;
|
|
82
|
+
|
|
83
|
+
backwardsForEach(occurrences, (occurrence) => {
|
|
84
|
+
end = occurrence.getEnd();
|
|
85
|
+
|
|
86
|
+
start = end; ///
|
|
87
|
+
|
|
88
|
+
end = Infinity;
|
|
89
|
+
|
|
90
|
+
const gap = line.substring(start, end);
|
|
91
|
+
|
|
92
|
+
gaps.unshift(gap);
|
|
93
|
+
|
|
94
|
+
end = occurrence.getEnd();
|
|
95
|
+
|
|
96
|
+
start = 0;
|
|
97
|
+
|
|
98
|
+
line = line.substring(start, end);
|
|
99
|
+
|
|
100
|
+
start = occurrence.getStart();
|
|
101
|
+
|
|
102
|
+
end = Infinity;
|
|
103
|
+
|
|
104
|
+
const match = line.substring(start, end);
|
|
105
|
+
|
|
106
|
+
matches.unshift(match);
|
|
107
|
+
|
|
108
|
+
end = start; ///
|
|
109
|
+
|
|
110
|
+
start = 0;
|
|
111
|
+
|
|
112
|
+
line = line.substring(start, end); ///
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const gap = line; ///
|
|
116
|
+
|
|
117
|
+
gaps.unshift(gap);
|
|
118
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const rulePromptOperation = require("../operation/prompt/rule"),
|
|
4
|
+
updatePathRulesOperation = require("../operation/updatePatRules"),
|
|
5
|
+
ignoreOrPermitPathPromptOperation = require("../operation/prompt/ignoreOrPermitPath");
|
|
6
|
+
|
|
7
|
+
const { executeOperations } = require("../utilities/operation"),
|
|
8
|
+
{ stripRootDirectoryFromPath } = require("../utilities/path");
|
|
9
|
+
|
|
10
|
+
function asynchronousIsFilePathIgnored(filePath, context, callback) {
|
|
11
|
+
filePath = stripRootDirectoryFromPath(filePath, context); ///
|
|
12
|
+
|
|
13
|
+
const path = filePath, ///
|
|
14
|
+
directory = false;
|
|
15
|
+
|
|
16
|
+
asynchronousIsPathIgnored(path, directory, context, callback);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function asynchronousIsDirectoryPathIgnored(directoryPath, context, callback) {
|
|
20
|
+
directoryPath = stripRootDirectoryFromPath(directoryPath, context); ///
|
|
21
|
+
|
|
22
|
+
const path = directoryPath, ///
|
|
23
|
+
directory = true;
|
|
24
|
+
|
|
25
|
+
asynchronousIsPathIgnored(path, directory, context, callback);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
asynchronousIsFilePathIgnored,
|
|
30
|
+
asynchronousIsDirectoryPathIgnored
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function asynchronousIsPathIgnored(path, directory, context, callback) {
|
|
34
|
+
const operations = [
|
|
35
|
+
ignoreOrPermitPathPromptOperation,
|
|
36
|
+
rulePromptOperation,
|
|
37
|
+
updatePathRulesOperation
|
|
38
|
+
],
|
|
39
|
+
rule = null,
|
|
40
|
+
pathIgnored = null;
|
|
41
|
+
|
|
42
|
+
Object.assign(context, {
|
|
43
|
+
rule,
|
|
44
|
+
path,
|
|
45
|
+
directory,
|
|
46
|
+
pathIgnored
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
executeOperations(operations, (completed) => {
|
|
50
|
+
const { pathIgnored } = context;
|
|
51
|
+
|
|
52
|
+
delete context.rule;
|
|
53
|
+
delete context.path;
|
|
54
|
+
delete context.directory;
|
|
55
|
+
delete context.pathIgnored;
|
|
56
|
+
|
|
57
|
+
callback(pathIgnored);
|
|
58
|
+
}, context);
|
|
59
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { EMPTY_STRING } = require("../constants"),
|
|
4
|
+
{ addTrailingForwardSlash } = require("../utilities/string"),
|
|
5
|
+
{ stripRootDirectoryFromPath } = require("../utilities/path");
|
|
6
|
+
|
|
7
|
+
function synchronousIsFilePathIgnored(filePath, context) {
|
|
8
|
+
let filePathIgnored = null;
|
|
9
|
+
|
|
10
|
+
filePath = stripRootDirectoryFromPath(filePath, context); ///
|
|
11
|
+
|
|
12
|
+
const { ignoredFilePathRules, permittedFilePathRules } = context,
|
|
13
|
+
string = filePath; ///
|
|
14
|
+
|
|
15
|
+
ignoredFilePathRules.some((ignoredFilePathRule) => {
|
|
16
|
+
const matches = ignoredFilePathRule.match(string);
|
|
17
|
+
|
|
18
|
+
if (matches) {
|
|
19
|
+
const rule = ignoredFilePathRule, ///
|
|
20
|
+
ruleString = rule.asString();
|
|
21
|
+
|
|
22
|
+
Object.assign(context, {
|
|
23
|
+
ruleString
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
filePathIgnored = true;
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
permittedFilePathRules.some((permittedFilePathRule) => {
|
|
33
|
+
const matches = permittedFilePathRule.match(string);
|
|
34
|
+
|
|
35
|
+
if (matches) {
|
|
36
|
+
const rule = permittedFilePathRule, ///
|
|
37
|
+
ruleString = rule.asString();
|
|
38
|
+
|
|
39
|
+
Object.assign(context, {
|
|
40
|
+
ruleString
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
filePathIgnored = false;
|
|
44
|
+
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return filePathIgnored;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function synchronousIsDirectoryPathIgnored(directoryPath, context) {
|
|
53
|
+
let directoryPathIgnored = null;
|
|
54
|
+
|
|
55
|
+
directoryPath = stripRootDirectoryFromPath(directoryPath, context); ///
|
|
56
|
+
|
|
57
|
+
if (directoryPath === EMPTY_STRING) {
|
|
58
|
+
directoryPathIgnored = false;
|
|
59
|
+
} else {
|
|
60
|
+
const { ignoredDirectoryPathRules, permittedDirectoryPathRules } = context,
|
|
61
|
+
string = addTrailingForwardSlash(directoryPath); ///
|
|
62
|
+
|
|
63
|
+
ignoredDirectoryPathRules.some((ignoredDirectoryPathRule) => {
|
|
64
|
+
const matches = ignoredDirectoryPathRule.match(string);
|
|
65
|
+
|
|
66
|
+
if (matches) {
|
|
67
|
+
const rule = ignoredDirectoryPathRule, ///
|
|
68
|
+
ruleString = rule.asString();
|
|
69
|
+
|
|
70
|
+
Object.assign(context, {
|
|
71
|
+
ruleString
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
directoryPathIgnored = true;
|
|
75
|
+
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
permittedDirectoryPathRules.some((permittedDirectoryPathRule) => {
|
|
81
|
+
const matches = permittedDirectoryPathRule.match(string);
|
|
82
|
+
|
|
83
|
+
if (matches) {
|
|
84
|
+
const rule = permittedDirectoryPathRule, ///
|
|
85
|
+
ruleString = rule.asString();
|
|
86
|
+
|
|
87
|
+
Object.assign(context, {
|
|
88
|
+
ruleString
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
directoryPathIgnored = false;
|
|
92
|
+
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return directoryPathIgnored;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
synchronousIsFilePathIgnored,
|
|
103
|
+
synchronousIsDirectoryPathIgnored
|
|
104
|
+
};
|