view-ignored 0.1.1 → 0.2.0
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 +37 -54
- package/bin/viewig +2 -2
- package/out/src/bin.d.ts +2 -0
- package/out/src/bin.js +3 -0
- package/out/src/browser/binds/index.d.ts +45 -0
- package/out/src/browser/binds/index.js +78 -0
- package/out/src/browser/binds/plugins/git.d.ts +3 -0
- package/out/src/browser/binds/plugins/git.js +24 -0
- package/out/src/browser/binds/plugins/npm.d.ts +11 -0
- package/out/src/browser/binds/plugins/npm.js +71 -0
- package/out/src/browser/binds/plugins/vsce.d.ts +9 -0
- package/out/src/browser/binds/plugins/vsce.js +21 -0
- package/out/src/browser/binds/plugins/yarn.d.ts +16 -0
- package/out/src/browser/binds/plugins/yarn.js +78 -0
- package/out/src/browser/binds/targets.d.ts +64 -0
- package/out/src/browser/binds/targets.js +56 -0
- package/out/src/browser/errors.d.ts +10 -0
- package/out/src/browser/errors.js +20 -0
- package/out/src/browser/fileinfo.d.ts +82 -0
- package/out/src/browser/fileinfo.js +78 -0
- package/{lib → out/src/browser}/index.d.ts +0 -1
- package/{lib → out/src}/browser/index.js +0 -1
- package/out/src/browser/lib.d.ts +141 -0
- package/out/src/browser/lib.js +126 -0
- package/out/src/browser/scanner.d.ts +103 -0
- package/out/src/browser/scanner.js +161 -0
- package/out/src/browser/sorting.d.ts +41 -0
- package/out/src/browser/sorting.js +133 -0
- package/out/src/browser/sourceinfo.d.ts +62 -0
- package/out/src/browser/sourceinfo.js +105 -0
- package/out/src/browser/styling.d.ts +90 -0
- package/{lib → out/src}/browser/styling.js +64 -37
- package/out/src/cli.d.ts +92 -0
- package/out/src/cli.js +249 -0
- package/out/src/config.d.ts +141 -0
- package/out/src/config.js +257 -0
- package/{lib/browser → out/src}/index.d.ts +0 -1
- package/{lib → out/src}/index.js +0 -1
- package/{lib → out/src}/lib.d.ts +1 -2
- package/{lib → out/src}/lib.js +1 -2
- package/out/src/styling.d.ts +4 -0
- package/out/src/styling.js +40 -0
- package/package.json +20 -14
- package/lib/bin.d.ts +0 -3
- package/lib/bin.d.ts.map +0 -1
- package/lib/bin.js +0 -4
- package/lib/bin.js.map +0 -1
- package/lib/browser/binds/index.d.ts +0 -2
- package/lib/browser/binds/index.d.ts.map +0 -1
- package/lib/browser/binds/index.js +0 -2
- package/lib/browser/binds/index.js.map +0 -1
- package/lib/browser/binds/targets.d.ts +0 -52
- package/lib/browser/binds/targets.d.ts.map +0 -1
- package/lib/browser/binds/targets.js +0 -43
- package/lib/browser/binds/targets.js.map +0 -1
- package/lib/browser/binds.d.ts +0 -22
- package/lib/browser/binds.d.ts.map +0 -1
- package/lib/browser/binds.js +0 -14
- package/lib/browser/binds.js.map +0 -1
- package/lib/browser/fileinfo.d.ts +0 -72
- package/lib/browser/fileinfo.d.ts.map +0 -1
- package/lib/browser/fileinfo.js +0 -72
- package/lib/browser/fileinfo.js.map +0 -1
- package/lib/browser/index.d.ts.map +0 -1
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/lib.d.ts +0 -141
- package/lib/browser/lib.d.ts.map +0 -1
- package/lib/browser/lib.js +0 -116
- package/lib/browser/lib.js.map +0 -1
- package/lib/browser/looker.d.ts +0 -79
- package/lib/browser/looker.d.ts.map +0 -1
- package/lib/browser/looker.js +0 -89
- package/lib/browser/looker.js.map +0 -1
- package/lib/browser/plugins/git.d.ts +0 -10
- package/lib/browser/plugins/git.d.ts.map +0 -1
- package/lib/browser/plugins/git.js +0 -23
- package/lib/browser/plugins/git.js.map +0 -1
- package/lib/browser/plugins/npm.d.ts +0 -12
- package/lib/browser/plugins/npm.d.ts.map +0 -1
- package/lib/browser/plugins/npm.js +0 -70
- package/lib/browser/plugins/npm.js.map +0 -1
- package/lib/browser/plugins/vsce.d.ts +0 -10
- package/lib/browser/plugins/vsce.d.ts.map +0 -1
- package/lib/browser/plugins/vsce.js +0 -23
- package/lib/browser/plugins/vsce.js.map +0 -1
- package/lib/browser/plugins/yarn.d.ts +0 -15
- package/lib/browser/plugins/yarn.d.ts.map +0 -1
- package/lib/browser/plugins/yarn.js +0 -46
- package/lib/browser/plugins/yarn.js.map +0 -1
- package/lib/browser/sorting.d.ts +0 -31
- package/lib/browser/sorting.d.ts.map +0 -1
- package/lib/browser/sorting.js +0 -121
- package/lib/browser/sorting.js.map +0 -1
- package/lib/browser/sourcepattern.d.ts +0 -35
- package/lib/browser/sourcepattern.d.ts.map +0 -1
- package/lib/browser/sourcepattern.js +0 -56
- package/lib/browser/sourcepattern.js.map +0 -1
- package/lib/browser/styling.d.ts +0 -47
- package/lib/browser/styling.d.ts.map +0 -1
- package/lib/browser/styling.js.map +0 -1
- package/lib/browser/tools/index.d.ts +0 -3
- package/lib/browser/tools/index.d.ts.map +0 -1
- package/lib/browser/tools/index.js +0 -3
- package/lib/browser/tools/index.js.map +0 -1
- package/lib/browser/tools/sorting.d.ts +0 -31
- package/lib/browser/tools/sorting.d.ts.map +0 -1
- package/lib/browser/tools/sorting.js +0 -121
- package/lib/browser/tools/sorting.js.map +0 -1
- package/lib/browser/tools/styles.d.ts +0 -16
- package/lib/browser/tools/styles.d.ts.map +0 -1
- package/lib/browser/tools/styles.js +0 -116
- package/lib/browser/tools/styles.js.map +0 -1
- package/lib/cli.d.ts +0 -61
- package/lib/cli.d.ts.map +0 -1
- package/lib/cli.js +0 -165
- package/lib/cli.js.map +0 -1
- package/lib/config.d.ts +0 -134
- package/lib/config.d.ts.map +0 -1
- package/lib/config.js +0 -142
- package/lib/config.js.map +0 -1
- package/lib/git.d.ts +0 -13
- package/lib/git.d.ts.map +0 -1
- package/lib/git.js +0 -37
- package/lib/git.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/lib.d.ts.map +0 -1
- package/lib/lib.js.map +0 -1
- package/lib/plugins/git.d.ts +0 -9
- package/lib/plugins/git.js +0 -22
- package/lib/plugins/git.js.map +0 -1
- package/lib/plugins/npm.d.ts +0 -12
- package/lib/plugins/npm.js +0 -74
- package/lib/plugins/npm.js.map +0 -1
- package/lib/plugins/vsce.d.ts +0 -9
- package/lib/plugins/vsce.js +0 -22
- package/lib/plugins/vsce.js.map +0 -1
- package/lib/plugins/yarn.d.ts +0 -15
- package/lib/plugins/yarn.js +0 -50
- package/lib/plugins/yarn.js.map +0 -1
- package/lib/tools/index.d.ts +0 -3
- package/lib/tools/index.js +0 -4
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/methods.d.ts +0 -16
- package/lib/tools/methods.js +0 -81
- package/lib/tools/methods.js.map +0 -1
- package/lib/tools/sorting.d.ts +0 -30
- package/lib/tools/sorting.js +0 -121
- package/lib/tools/sorting.js.map +0 -1
- package/lib/tools/styles.d.ts +0 -15
- package/lib/tools/styles.js +0 -123
- package/lib/tools/styles.js.map +0 -1
- package/lib/util/index.d.ts +0 -3
- package/lib/util/index.js +0 -4
- package/lib/util/index.js.map +0 -1
- package/lib/util/presets.d.ts +0 -24
- package/lib/util/presets.js +0 -129
- package/lib/util/presets.js.map +0 -1
- package/lib/util/sorting.d.ts +0 -30
- package/lib/util/sorting.js +0 -121
- package/lib/util/sorting.js.map +0 -1
- package/lib/util/styles.d.ts +0 -8
- package/lib/util/styles.js +0 -52
- package/lib/util/styles.js.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ChalkInstance } from "chalk";
|
|
2
|
+
import { DecorName } from "./styling.js";
|
|
3
|
+
import { FilterName, Scanner, SourceInfo } from "./lib.js";
|
|
4
|
+
/**
|
|
5
|
+
* @see {@link FileInfo.prototype.toString}
|
|
6
|
+
*/
|
|
7
|
+
export interface FileInfoToStringOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The appearance behavior of the file icon.
|
|
10
|
+
* @default undefined
|
|
11
|
+
*/
|
|
12
|
+
fileIcon?: DecorName;
|
|
13
|
+
/**
|
|
14
|
+
* Show the scanner's source after the file path.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
source?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The appearance behavior of the prefix.
|
|
20
|
+
* `"+"` for included, `"!"` for excluded.
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
usePrefix?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The behavior of colors.
|
|
26
|
+
* @default undefined
|
|
27
|
+
*/
|
|
28
|
+
chalk?: ChalkInstance;
|
|
29
|
+
/**
|
|
30
|
+
* Determines if the path's base or the entire path should be formatted.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
entire?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The result of the file path scan.
|
|
37
|
+
*/
|
|
38
|
+
export declare class FileInfo {
|
|
39
|
+
/**
|
|
40
|
+
* Relative path to the file.
|
|
41
|
+
*/
|
|
42
|
+
readonly filePath: string;
|
|
43
|
+
/**
|
|
44
|
+
* Source of patterns, used by {@link scanner}.
|
|
45
|
+
*/
|
|
46
|
+
readonly source: SourceInfo;
|
|
47
|
+
/**
|
|
48
|
+
* The pattern parser.
|
|
49
|
+
*/
|
|
50
|
+
readonly scanner: Scanner;
|
|
51
|
+
constructor(
|
|
52
|
+
/**
|
|
53
|
+
* Relative path to the file.
|
|
54
|
+
*/
|
|
55
|
+
filePath: string,
|
|
56
|
+
/**
|
|
57
|
+
* Source of patterns, used by {@link scanner}.
|
|
58
|
+
*/
|
|
59
|
+
source: SourceInfo);
|
|
60
|
+
/**
|
|
61
|
+
* Determines if ignored file is ignored or not.
|
|
62
|
+
*/
|
|
63
|
+
isIgnored(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Creates new {@link FileInfo} from each file path.
|
|
66
|
+
*/
|
|
67
|
+
static from(filePathList: string[], sourceInfo: SourceInfo): FileInfo[];
|
|
68
|
+
/**
|
|
69
|
+
* Creates new {@link FileInfo} from the file path.
|
|
70
|
+
*/
|
|
71
|
+
static from(filePath: string, sourceInfo: SourceInfo): FileInfo;
|
|
72
|
+
/**
|
|
73
|
+
* @param options Styling options.
|
|
74
|
+
* @returns Relative file path. Optionally formatted.
|
|
75
|
+
*/
|
|
76
|
+
toString(options?: FileInfoToStringOptions): string;
|
|
77
|
+
/**
|
|
78
|
+
* @param filter The group name. Default: `"all"`
|
|
79
|
+
* @returns `true`, if the file is contained by the filter.
|
|
80
|
+
*/
|
|
81
|
+
isIncludedBy(filter?: FilterName | ((fileInfo: FileInfo) => boolean)): boolean;
|
|
82
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { decorFile } from "./styling.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
/**
|
|
4
|
+
* The result of the file path scan.
|
|
5
|
+
*/
|
|
6
|
+
export class FileInfo {
|
|
7
|
+
filePath;
|
|
8
|
+
source;
|
|
9
|
+
/**
|
|
10
|
+
* The pattern parser.
|
|
11
|
+
*/
|
|
12
|
+
scanner;
|
|
13
|
+
constructor(
|
|
14
|
+
/**
|
|
15
|
+
* Relative path to the file.
|
|
16
|
+
*/
|
|
17
|
+
filePath,
|
|
18
|
+
/**
|
|
19
|
+
* Source of patterns, used by {@link scanner}.
|
|
20
|
+
*/
|
|
21
|
+
source) {
|
|
22
|
+
this.filePath = filePath;
|
|
23
|
+
this.source = source;
|
|
24
|
+
this.scanner = this.source.scanner;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Determines if ignored file is ignored or not.
|
|
28
|
+
*/
|
|
29
|
+
isIgnored() {
|
|
30
|
+
return this.scanner.matches(this.filePath);
|
|
31
|
+
}
|
|
32
|
+
static from(arg, sourceInfo) {
|
|
33
|
+
if (Array.isArray(arg)) {
|
|
34
|
+
return arg.map(path => FileInfo.from(path, sourceInfo));
|
|
35
|
+
}
|
|
36
|
+
return new FileInfo(arg, sourceInfo);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @param options Styling options.
|
|
40
|
+
* @returns Relative file path. Optionally formatted.
|
|
41
|
+
*/
|
|
42
|
+
toString(options) {
|
|
43
|
+
const { fileIcon, chalk, usePrefix = false, source: useSource = false, entire = true } = options ?? {};
|
|
44
|
+
const parsed = path.parse(this.filePath);
|
|
45
|
+
const fIcon = decorFile(fileIcon, this.filePath);
|
|
46
|
+
const ignored = this.isIgnored();
|
|
47
|
+
let prefix = usePrefix ? (ignored ? '!' : '+') : '';
|
|
48
|
+
let postfix = useSource ? " << " + this.source.toString() : '';
|
|
49
|
+
if (chalk) {
|
|
50
|
+
prefix = chalk.dim(prefix);
|
|
51
|
+
postfix = chalk.dim(postfix);
|
|
52
|
+
const clr = chalk[ignored ? "red" : "green"];
|
|
53
|
+
if (entire) {
|
|
54
|
+
return fIcon + clr(prefix + this.filePath + postfix);
|
|
55
|
+
}
|
|
56
|
+
return parsed.dir + '/' + fIcon + clr(prefix + parsed.base + postfix);
|
|
57
|
+
}
|
|
58
|
+
if (entire) {
|
|
59
|
+
return prefix + this.filePath + postfix;
|
|
60
|
+
}
|
|
61
|
+
return parsed.dir + '/' + fIcon + prefix + parsed.base + postfix;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @param filter The group name. Default: `"all"`
|
|
65
|
+
* @returns `true`, if the file is contained by the filter.
|
|
66
|
+
*/
|
|
67
|
+
isIncludedBy(filter) {
|
|
68
|
+
if (typeof filter === "function") {
|
|
69
|
+
return filter(this);
|
|
70
|
+
}
|
|
71
|
+
filter ??= "all";
|
|
72
|
+
const filterIgnore = (filter === "ignored") && this.isIgnored();
|
|
73
|
+
const filterInclude = (filter === "included") && !this.isIgnored();
|
|
74
|
+
const filterAll = filter === "all";
|
|
75
|
+
const result = filterIgnore || filterInclude || filterAll;
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { PatternType } from "./scanner.js";
|
|
3
|
+
import { FSOption } from "glob";
|
|
4
|
+
import { FileInfo } from "./fileinfo.js";
|
|
5
|
+
import { SourceInfo } from "./sourceinfo.js";
|
|
6
|
+
import * as FS from "fs";
|
|
7
|
+
export * from "./errors.js";
|
|
8
|
+
export * from "./scanner.js";
|
|
9
|
+
export * from "./fileinfo.js";
|
|
10
|
+
export * from "./sourceinfo.js";
|
|
11
|
+
export * as Styling from "./styling.js";
|
|
12
|
+
export * as Sorting from "./sorting.js";
|
|
13
|
+
export * as Plugins from "./binds/index.js";
|
|
14
|
+
/**
|
|
15
|
+
* Contains all filter names.
|
|
16
|
+
*/
|
|
17
|
+
export declare const filterNameList: readonly ["ignored", "included", "all"];
|
|
18
|
+
/**
|
|
19
|
+
* Contains all filter names as a type.
|
|
20
|
+
*/
|
|
21
|
+
export type FilterName = typeof filterNameList[number];
|
|
22
|
+
/**
|
|
23
|
+
* Checks if the value is the {@link FilterName}.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isFilterName(value: unknown): value is FilterName;
|
|
26
|
+
/**
|
|
27
|
+
* Uses `readFileSync` and `readFile`.
|
|
28
|
+
* @extends glob.FileSystemAdapter
|
|
29
|
+
*/
|
|
30
|
+
export interface FileSystemAdapter extends FSOption {
|
|
31
|
+
readFileSync?: typeof FS.readFileSync;
|
|
32
|
+
readdirSync?: typeof FS.readdirSync;
|
|
33
|
+
statSync?: typeof FS.statSync;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Also can write rules to the {@link Scanner}.
|
|
37
|
+
* @returns `true`, if the given source is valid.
|
|
38
|
+
*/
|
|
39
|
+
export type ScanMethod = (sourceInfo: SourceInfo) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Represents the methodology for reading the target's source.
|
|
42
|
+
*/
|
|
43
|
+
export interface Methodology {
|
|
44
|
+
/**
|
|
45
|
+
* Git configuration property.
|
|
46
|
+
* @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
ignoreCase?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The parser for the patterns.
|
|
52
|
+
* @default "gitignore"
|
|
53
|
+
*/
|
|
54
|
+
matcher: PatternType;
|
|
55
|
+
/**
|
|
56
|
+
* Use the patterns for including instead of excluding/ignoring.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
matcherNegated?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Additional patterns for files, provided by the {@link pattern}.
|
|
62
|
+
*
|
|
63
|
+
* Example: You have the '.gitignore' file. You want to scan patterns from it and add additional patterns. Use this property.
|
|
64
|
+
* @default []
|
|
65
|
+
*/
|
|
66
|
+
matcherAdd?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Force ignore patterns.
|
|
69
|
+
* Takes precedence over {@link matcherAdd}.
|
|
70
|
+
* @default []
|
|
71
|
+
*/
|
|
72
|
+
matcherExclude?: string[];
|
|
73
|
+
/**
|
|
74
|
+
* Force include patterns.
|
|
75
|
+
* Takes precedence over {@link matcherExclude}.
|
|
76
|
+
* @default []
|
|
77
|
+
*/
|
|
78
|
+
matcherInclude?: string[];
|
|
79
|
+
/**
|
|
80
|
+
* First valid source will be used as {@link Scanner}.
|
|
81
|
+
*/
|
|
82
|
+
pattern: SourceInfo[] | string[] | SourceInfo | string;
|
|
83
|
+
/**
|
|
84
|
+
* Scanner function. Should return `true`, if the given source is valid and also add patterns to the {@link FileInfo.scanner}.
|
|
85
|
+
*/
|
|
86
|
+
scan: ScanMethod;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks if the value is the {@link Methodology}.
|
|
90
|
+
*/
|
|
91
|
+
export declare function isMethodology(value: unknown): value is Methodology;
|
|
92
|
+
/**
|
|
93
|
+
* File scanning options.
|
|
94
|
+
* @see {@link ScanFolderOptions}
|
|
95
|
+
*/
|
|
96
|
+
export interface ScanFileOptions {
|
|
97
|
+
/**
|
|
98
|
+
* Custom implementation of methods for working with the file system.
|
|
99
|
+
* @default import * as FS from "fs"
|
|
100
|
+
*/
|
|
101
|
+
fsa?: FileSystemAdapter;
|
|
102
|
+
/**
|
|
103
|
+
* The current working directory in which to search.
|
|
104
|
+
* @default process.cwd()
|
|
105
|
+
*/
|
|
106
|
+
cwd?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Specifies the maximum number of concurrent requests from a reader to read
|
|
109
|
+
* directories.
|
|
110
|
+
* @default os.cpus().length
|
|
111
|
+
*/
|
|
112
|
+
concurrency?: number;
|
|
113
|
+
/**
|
|
114
|
+
* Specifies the maximum depth of a read directory relative to the start
|
|
115
|
+
* directory.
|
|
116
|
+
* @default Infinity
|
|
117
|
+
*/
|
|
118
|
+
maxDepth?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Folder deep scanning options.
|
|
122
|
+
* @see {@link ScanFileOptions}
|
|
123
|
+
*/
|
|
124
|
+
export interface ScanFolderOptions extends ScanFileOptions {
|
|
125
|
+
/**
|
|
126
|
+
* Filter output.
|
|
127
|
+
* @default "included"
|
|
128
|
+
*/
|
|
129
|
+
filter?: FilterName | ((fileInfo: FileInfo) => boolean);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gets info about the file: it is ignored or not.
|
|
133
|
+
* @throws {ErrorNoSources} if the source is bad.
|
|
134
|
+
*/
|
|
135
|
+
export declare function scanFile(filePath: string, sources: Methodology[], options: ScanFileOptions): Promise<FileInfo>;
|
|
136
|
+
/**
|
|
137
|
+
* Scans project's directory paths to determine whether they are being ignored.
|
|
138
|
+
* @throws {ErrorNoSources} if the source is bad.
|
|
139
|
+
*/
|
|
140
|
+
export declare function scanProject(sources: Methodology[], options: ScanFolderOptions): Promise<FileInfo[]>;
|
|
141
|
+
export declare function scanProject(target: string, options: ScanFolderOptions): Promise<FileInfo[]>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Scanner, isPatternType } from "./scanner.js";
|
|
2
|
+
import { glob } from "glob";
|
|
3
|
+
import { FileInfo } from "./fileinfo.js";
|
|
4
|
+
import { SourceInfo } from "./sourceinfo.js";
|
|
5
|
+
import { targetGet } from "./binds/index.js";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { ErrorNoSources, ErrorTargetNotBound } from "./errors.js";
|
|
8
|
+
import * as FS from "fs";
|
|
9
|
+
export * from "./errors.js";
|
|
10
|
+
export * from "./scanner.js";
|
|
11
|
+
export * from "./fileinfo.js";
|
|
12
|
+
export * from "./sourceinfo.js";
|
|
13
|
+
export * as Styling from "./styling.js";
|
|
14
|
+
export * as Sorting from "./sorting.js";
|
|
15
|
+
export * as Plugins from "./binds/index.js";
|
|
16
|
+
/**
|
|
17
|
+
* Contains all filter names.
|
|
18
|
+
*/
|
|
19
|
+
export const filterNameList = ["ignored", "included", "all"];
|
|
20
|
+
/**
|
|
21
|
+
* Checks if the value is the {@link FilterName}.
|
|
22
|
+
*/
|
|
23
|
+
export function isFilterName(value) {
|
|
24
|
+
return typeof value === "string" && filterNameList.includes(value);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks if the value is the {@link Methodology}.
|
|
28
|
+
*/
|
|
29
|
+
export function isMethodology(value) {
|
|
30
|
+
if (value?.constructor !== Object) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const v = value;
|
|
34
|
+
return isPatternType(v.matcher)
|
|
35
|
+
&& (typeof v.pattern === "string")
|
|
36
|
+
&& (v.matcherAdd === undefined || Array.isArray(v.matcherAdd) && v.matcherAdd.every(p => Scanner.patternIsValid(p, { patternType: v.matcher })));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Gets info about the file: it is ignored or not.
|
|
40
|
+
* @throws {ErrorNoSources} if the source is bad.
|
|
41
|
+
*/
|
|
42
|
+
export async function scanFile(filePath, sources, options) {
|
|
43
|
+
const { fsa = FS, cwd = process.cwd() } = options ?? {};
|
|
44
|
+
for (const methodology of sources) {
|
|
45
|
+
const sourceInfoList = await SourceInfo.fromMethodology(methodology, options);
|
|
46
|
+
for (const sourceInfo of sourceInfoList) {
|
|
47
|
+
sourceInfo.readSync(cwd, fsa.readFileSync ?? FS.readFileSync);
|
|
48
|
+
const isGoodSource = methodology.scan(sourceInfo);
|
|
49
|
+
if (isGoodSource) {
|
|
50
|
+
return FileInfo.from(filePath, sourceInfo);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new ErrorNoSources(sources);
|
|
55
|
+
}
|
|
56
|
+
export async function scanProject(arg1, options) {
|
|
57
|
+
if (typeof arg1 === "string") {
|
|
58
|
+
const bind = targetGet(arg1);
|
|
59
|
+
if (bind === undefined) {
|
|
60
|
+
throw new ErrorTargetNotBound(arg1);
|
|
61
|
+
}
|
|
62
|
+
return scanProject(bind.methodology, Object.assign(options, bind.scanOptions));
|
|
63
|
+
}
|
|
64
|
+
// Find good source.
|
|
65
|
+
const { filter = "included", fsa = FS, cwd = process.cwd() } = options;
|
|
66
|
+
for (const methodology of arg1) {
|
|
67
|
+
const resultList = [];
|
|
68
|
+
const sourceInfoList = await SourceInfo.fromMethodology(methodology, options);
|
|
69
|
+
if (sourceInfoList.length < 1) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const allFilePaths = await glob("**", {
|
|
73
|
+
...options,
|
|
74
|
+
nodir: true,
|
|
75
|
+
dot: true,
|
|
76
|
+
posix: true,
|
|
77
|
+
});
|
|
78
|
+
const cache = new Set();
|
|
79
|
+
let noSource = false;
|
|
80
|
+
for (const filePath of allFilePaths) {
|
|
81
|
+
if (cache.has(filePath)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const sourceInfo = SourceInfo.hierarcy(filePath, sourceInfoList, {
|
|
85
|
+
closest: false,
|
|
86
|
+
filter(sourceInfo) {
|
|
87
|
+
if (!(sourceInfo instanceof SourceInfo)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (sourceInfo.content === undefined) {
|
|
91
|
+
sourceInfo.readSync(cwd, fsa.readFileSync ?? FS.readFileSync);
|
|
92
|
+
}
|
|
93
|
+
return methodology.scan(sourceInfo);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
if (sourceInfo === undefined) {
|
|
97
|
+
noSource = true;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
// also create cache for each file in the direcotry
|
|
101
|
+
const fileDir = path.dirname(filePath);
|
|
102
|
+
const fileDirAbsolute = path.join(cwd, fileDir);
|
|
103
|
+
const entryList = (fsa?.readdirSync ?? FS.readdirSync)(fileDirAbsolute);
|
|
104
|
+
for (const entry of entryList) {
|
|
105
|
+
const entryPath = path.join(fileDir, entry);
|
|
106
|
+
const entryPathNormal = fileDir !== '.' ? fileDir + '/' + entry : entry;
|
|
107
|
+
const entryPathAbsolute = path.join(cwd, entryPath);
|
|
108
|
+
const stat = (fsa?.statSync ?? FS.statSync)(entryPathAbsolute);
|
|
109
|
+
cache.add(entryPathNormal);
|
|
110
|
+
if (stat.isFile()) {
|
|
111
|
+
// push new FileInfo
|
|
112
|
+
const fileInfo = FileInfo.from(entryPathNormal, sourceInfo);
|
|
113
|
+
if (fileInfo.isIncludedBy(filter)) {
|
|
114
|
+
resultList.push(fileInfo);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} // forend
|
|
119
|
+
if (noSource) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
return resultList;
|
|
123
|
+
} // forend
|
|
124
|
+
throw new ErrorNoSources(arg1);
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported matchers/parsers by {@link Scanner}.
|
|
3
|
+
*/
|
|
4
|
+
export type PatternType = typeof patternTypeList[number];
|
|
5
|
+
export declare const patternTypeList: readonly ["gitignore", "minimatch"];
|
|
6
|
+
export declare function isPatternType(value: unknown): value is PatternType;
|
|
7
|
+
/**
|
|
8
|
+
* @see {@link Scanner}
|
|
9
|
+
*/
|
|
10
|
+
export interface ScannerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Use the patterns for including instead of excluding/ignoring.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
negated?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The parser for the patterns.
|
|
18
|
+
* @default "gitignore"
|
|
19
|
+
*/
|
|
20
|
+
patternType?: PatternType;
|
|
21
|
+
/**
|
|
22
|
+
* Git configuration property.
|
|
23
|
+
* @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
ignoreCase?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export type IsValidPatternOptions = Pick<ScannerOptions, "patternType">;
|
|
29
|
+
/**
|
|
30
|
+
* The Glob-like pattern of the specific matcher.
|
|
31
|
+
*/
|
|
32
|
+
export type ScannerPattern = string | string[];
|
|
33
|
+
/**
|
|
34
|
+
* The pattern parser. Can check if the file path is ignored.
|
|
35
|
+
*/
|
|
36
|
+
export declare class Scanner {
|
|
37
|
+
/**
|
|
38
|
+
* If `true`, when calling {@link Scanner.matches}, method will return `true` for ignored path.
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
readonly isNegated: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Defines way to check paths.
|
|
44
|
+
* @default "gitignore"
|
|
45
|
+
*/
|
|
46
|
+
readonly patternType: PatternType;
|
|
47
|
+
/**
|
|
48
|
+
* Git configuration property.
|
|
49
|
+
* @see {@link https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreignoreCase|git-config ignorecase}.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
readonly ignoreCase: boolean;
|
|
53
|
+
private patternList;
|
|
54
|
+
private patternListExclude;
|
|
55
|
+
private patternListInclude;
|
|
56
|
+
private ignoreInstance;
|
|
57
|
+
private ignoreInstanceExclude;
|
|
58
|
+
private ignoreInstanceInclude;
|
|
59
|
+
constructor(options?: ScannerOptions);
|
|
60
|
+
/**
|
|
61
|
+
* Adds new ignore rule.
|
|
62
|
+
* @param pattern .gitignore file specification pattern.
|
|
63
|
+
*/
|
|
64
|
+
add(pattern?: ScannerPattern): this;
|
|
65
|
+
/**
|
|
66
|
+
* Force ignore pattern.
|
|
67
|
+
* @param pattern .gitignore file specification pattern.
|
|
68
|
+
*/
|
|
69
|
+
addExclude(pattern?: ScannerPattern): this;
|
|
70
|
+
/**
|
|
71
|
+
* Force ignore pattern.
|
|
72
|
+
* @param pattern .gitignore file specification pattern.
|
|
73
|
+
*/
|
|
74
|
+
addInclude(pattern?: ScannerPattern): this;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if the scanner should ignore path.
|
|
77
|
+
* @see {@link Scanner.isNegated} can change the return value.
|
|
78
|
+
* @param path Dir entry, path.
|
|
79
|
+
*/
|
|
80
|
+
matches(path: string): boolean;
|
|
81
|
+
private matchesReal;
|
|
82
|
+
private static matchesGitignore;
|
|
83
|
+
private static matchesMinimatch;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if given pattern is valid.
|
|
86
|
+
* @param pattern Parser pattern.
|
|
87
|
+
*/
|
|
88
|
+
patternIsValid(pattern: unknown): pattern is ScannerPattern;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if given pattern is valid.
|
|
91
|
+
* @param pattern Parser pattern.
|
|
92
|
+
*/
|
|
93
|
+
static patternIsValid(pattern: unknown, options?: IsValidPatternOptions): pattern is ScannerPattern;
|
|
94
|
+
/**
|
|
95
|
+
* @returns New pattern array: `!pattern` for `pattern`, and `pattern` for `!pattern`.
|
|
96
|
+
*/
|
|
97
|
+
static patternToNegated(pattern: string[]): string[];
|
|
98
|
+
/**
|
|
99
|
+
* @returns New pattern: `!pattern` for `pattern`, and `pattern` for `!pattern`.
|
|
100
|
+
*/
|
|
101
|
+
static patternToNegated(pattern: string): string;
|
|
102
|
+
static patternIsNegated(pattern: string): boolean;
|
|
103
|
+
}
|