view-ignored 0.1.1 → 0.2.1
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 +107 -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 +21 -15
- 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
|
@@ -1,55 +1,80 @@
|
|
|
1
|
-
import { stdout } from "process";
|
|
2
1
|
import { default as tree } from "treeify";
|
|
3
2
|
import jsonifyPaths from "jsonify-paths";
|
|
4
3
|
import path from "path";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import boxen from "boxen";
|
|
5
|
+
import { stripVTControlCharacters } from "util";
|
|
6
|
+
/**
|
|
7
|
+
* @returns Prints a readable file list. Here is '\n' ending.
|
|
8
|
+
*/
|
|
9
|
+
export function formatFiles(files, options) {
|
|
10
|
+
const { showSources = false, chalk, decor = "normal", style } = options ?? {};
|
|
11
|
+
const isPaths = style === "paths";
|
|
12
|
+
const paths = files.map(f => f.toString({ fileIcon: decor, usePrefix: true, chalk: chalk, source: showSources, entire: isPaths }));
|
|
13
|
+
if (isPaths) {
|
|
14
|
+
return paths.join('\n') + '\n';
|
|
15
|
+
}
|
|
16
|
+
// isTree
|
|
17
|
+
const pathsAsObject = jsonifyPaths.from(paths, { delimiter: "/" });
|
|
8
18
|
const pathsAsTree = tree.asTree(pathsAsObject, true, true);
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
return pathsAsTree;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Contains all style names.
|
|
23
|
+
*/
|
|
24
|
+
export const styleNameList = ['tree', 'paths'];
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the value is the {@link StyleName}.
|
|
27
|
+
*/
|
|
28
|
+
export function isStyleName(value) {
|
|
29
|
+
return typeof value === "string" && styleNameList.includes(value);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Contains all decor names.
|
|
33
|
+
*/
|
|
34
|
+
export const decorNameList = ['normal', 'emoji', 'nerdfonts'];
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the value is the {@link DecorName}.
|
|
37
|
+
*/
|
|
38
|
+
export function isDecorName(value) {
|
|
39
|
+
return typeof value === "string" && decorNameList.includes(value);
|
|
40
|
+
}
|
|
20
41
|
/**
|
|
21
42
|
* Formats the string for specific style types.
|
|
22
|
-
* @param
|
|
43
|
+
* @param decor The decor name.
|
|
23
44
|
* @param condition Formatting options.
|
|
24
45
|
*/
|
|
25
|
-
export function
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const isNerd = styleName.toLowerCase().includes('nerd');
|
|
31
|
-
const isEmoji = styleName.toLowerCase().includes('emoji');
|
|
32
|
-
let result = '';
|
|
33
|
-
if (isEmoji) {
|
|
34
|
-
result = (_a = condition.ifEmoji) !== null && _a !== void 0 ? _a : result;
|
|
35
|
-
}
|
|
36
|
-
else if (isNerd) {
|
|
37
|
-
result = (_b = condition.ifNerd) !== null && _b !== void 0 ? _b : result;
|
|
46
|
+
export function decorCondition(decor, condition) {
|
|
47
|
+
let result = condition.ifNormal ?? '';
|
|
48
|
+
if (decor === 'emoji') {
|
|
49
|
+
result = condition.ifEmoji ?? result;
|
|
38
50
|
}
|
|
39
|
-
else {
|
|
40
|
-
result =
|
|
51
|
+
else if (decor === 'nerdfonts') {
|
|
52
|
+
result = condition.ifNerd ?? result;
|
|
41
53
|
}
|
|
42
54
|
if (result !== '') {
|
|
43
|
-
result = (
|
|
55
|
+
result = (condition.prefix ?? '') + result + (condition.postfix ?? '');
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
export function boxError(message, options) {
|
|
60
|
+
let result = ('\n' + boxen(message, {
|
|
61
|
+
titleAlignment: "left",
|
|
62
|
+
padding: { left: 2, right: 2 },
|
|
63
|
+
borderColor: "redBright",
|
|
64
|
+
borderStyle: "round",
|
|
65
|
+
...options,
|
|
66
|
+
}));
|
|
67
|
+
if (options?.noColor) {
|
|
68
|
+
result = stripVTControlCharacters(result);
|
|
44
69
|
}
|
|
45
70
|
return result;
|
|
46
71
|
}
|
|
47
72
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
73
|
+
* Returns file icon for the file name & extension.
|
|
74
|
+
* @param decor The decor name.
|
|
50
75
|
* @param filePath The full file path.
|
|
51
76
|
*/
|
|
52
|
-
export function
|
|
77
|
+
export function decorFile(decor, filePath) {
|
|
53
78
|
const parsed = path.parse(filePath);
|
|
54
79
|
let icon = '';
|
|
55
80
|
switch (parsed.ext.toLocaleLowerCase()) {
|
|
@@ -117,10 +142,12 @@ export function styleConditionFile(styleName, filePath) {
|
|
|
117
142
|
default:
|
|
118
143
|
break;
|
|
119
144
|
}
|
|
120
|
-
|
|
145
|
+
if (!decor) {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
return decorCondition(decor, {
|
|
121
149
|
ifEmoji: '📄',
|
|
122
150
|
ifNerd: icon,
|
|
123
151
|
postfix: ' '
|
|
124
152
|
});
|
|
125
153
|
}
|
|
126
|
-
//# sourceMappingURL=styling.js.map
|
package/out/src/cli.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ChalkInstance, ColorSupportLevel } from "chalk";
|
|
2
|
+
import { Argument, Option, Command } from "commander";
|
|
3
|
+
import * as Config from "./config.js";
|
|
4
|
+
import { DecorName, StyleName } from "./browser/styling.js";
|
|
5
|
+
import { SortName } from "./browser/sorting.js";
|
|
6
|
+
import { FilterName } from "./lib.js";
|
|
7
|
+
import { BoxOptions } from "./styling.js";
|
|
8
|
+
export declare const version: string;
|
|
9
|
+
export declare function logError(message: string, options?: BoxOptions): void;
|
|
10
|
+
/**
|
|
11
|
+
* Use it instead of {@link program}.parse()
|
|
12
|
+
*/
|
|
13
|
+
export declare function programInit(): Promise<void>;
|
|
14
|
+
/** Chalk, but configured by view-ignored cli. */
|
|
15
|
+
export declare function getColorLevel(flags: ProgramFlags): ColorSupportLevel;
|
|
16
|
+
/** Chalk, but configured by view-ignored cli. */
|
|
17
|
+
export declare function getChalk(flags: ProgramFlags): ChalkInstance;
|
|
18
|
+
/**
|
|
19
|
+
* Command-line entire program flags.
|
|
20
|
+
*/
|
|
21
|
+
export interface ProgramFlags {
|
|
22
|
+
plugins: string[];
|
|
23
|
+
noColor: boolean;
|
|
24
|
+
color: string;
|
|
25
|
+
decor: DecorName;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Command-line 'scan' command flags.
|
|
29
|
+
*/
|
|
30
|
+
export interface ScanFlags {
|
|
31
|
+
target: string;
|
|
32
|
+
filter: FilterName;
|
|
33
|
+
sort: SortName;
|
|
34
|
+
style: StyleName;
|
|
35
|
+
showSources: boolean;
|
|
36
|
+
depth: number;
|
|
37
|
+
parsable: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Command-line 'cfg get' command flags.
|
|
41
|
+
*/
|
|
42
|
+
export interface ConfigGetFlags {
|
|
43
|
+
real: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* `view-ignored` command-line programl
|
|
47
|
+
*/
|
|
48
|
+
export declare const program: Command;
|
|
49
|
+
/**
|
|
50
|
+
* Command-line 'scan' command.
|
|
51
|
+
*/
|
|
52
|
+
export declare const scanProgram: Command;
|
|
53
|
+
/**
|
|
54
|
+
* Command-line 'config' command.
|
|
55
|
+
*/
|
|
56
|
+
export declare const cfgProgram: Command;
|
|
57
|
+
/**
|
|
58
|
+
* Command-line argument: key=value pair.
|
|
59
|
+
* @see {@link parseArgKeyVal}
|
|
60
|
+
*/
|
|
61
|
+
export declare const argConfigKeyVal: Argument;
|
|
62
|
+
/**
|
|
63
|
+
* Command-line argument: config property.
|
|
64
|
+
* @see {@link Config.configKeyList}
|
|
65
|
+
*/
|
|
66
|
+
export declare const argConfigKey: Argument;
|
|
67
|
+
export declare const cfgGetOption: Option;
|
|
68
|
+
export declare function parseArgArrStr(arg: string): string[];
|
|
69
|
+
export declare function parseArgBool(arg: string): boolean;
|
|
70
|
+
export declare function parseArgInt(arg: string): number;
|
|
71
|
+
export declare function parseArgKey(key: string): Config.ConfigKey;
|
|
72
|
+
export declare function parseArgKeyVal(pair: string): Config.ConfigPair;
|
|
73
|
+
/**
|
|
74
|
+
* Command-line 'scan' command action.
|
|
75
|
+
*/
|
|
76
|
+
export declare function actionScan(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Command-line 'config path' command action.
|
|
79
|
+
*/
|
|
80
|
+
export declare function actionCfgPath(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Command-line 'config set' command action
|
|
83
|
+
*/
|
|
84
|
+
export declare function actionCfgSet(pair?: Config.ConfigPair): void;
|
|
85
|
+
/**
|
|
86
|
+
* Command-line 'config unset' command action
|
|
87
|
+
*/
|
|
88
|
+
export declare function actionCfgUnset(key: Config.ConfigKey | undefined): void;
|
|
89
|
+
/**
|
|
90
|
+
* Command-line 'config unset' command action
|
|
91
|
+
*/
|
|
92
|
+
export declare function actionCfgGet(key: Config.ConfigKey | undefined, options: ConfigGetFlags): void;
|
package/out/src/cli.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { Chalk } from "chalk";
|
|
3
|
+
import { Argument, InvalidArgumentError, Option, Command } from "commander";
|
|
4
|
+
import * as Config from "./config.js";
|
|
5
|
+
import { BuiltIns, loadPluginsQueue, targetGet } from "./browser/binds/index.js";
|
|
6
|
+
import { decorCondition, formatFiles } from "./browser/styling.js";
|
|
7
|
+
import { ErrorNoSources, scanProject, Sorting } from "./lib.js";
|
|
8
|
+
import { boxError, formatConfigConflicts } from "./styling.js";
|
|
9
|
+
import ora from "ora";
|
|
10
|
+
import packageJSON from "../package.json" with { type: "json" };
|
|
11
|
+
import { format } from "util";
|
|
12
|
+
export const { version } = packageJSON;
|
|
13
|
+
export function logError(message, options) {
|
|
14
|
+
console.log(boxError(message, { noColor: getColorLevel(program.opts()) === 0, ...options }));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Use it instead of {@link program}.parse()
|
|
18
|
+
*/
|
|
19
|
+
export async function programInit() {
|
|
20
|
+
Config.configManager.load();
|
|
21
|
+
program.version('v' + version, '-v');
|
|
22
|
+
program.addOption(new Option("--no-color", 'force disable colors').default(false));
|
|
23
|
+
Config.configValueLinkCliOption("plugins", program, new Option('--plugins <modules...>', 'import modules to modify behavior'), parseArgArrStr);
|
|
24
|
+
Config.configValueLinkCliOption("color", program, new Option("--color <level>", 'the interface color level'), parseArgInt);
|
|
25
|
+
Config.configValueLinkCliOption("decor", program, new Option("--decor <decor>", "the interface decorations"));
|
|
26
|
+
Config.configValueLinkCliOption("parsable", scanProgram, new Option('-p, --parsable [parsable]', "print parsable text"), parseArgBool);
|
|
27
|
+
Config.configValueLinkCliOption("target", scanProgram, new Option("-t, --target <ignorer>", 'the scan target'));
|
|
28
|
+
Config.configValueLinkCliOption("filter", scanProgram, new Option("--filter <filter>", 'filter results'));
|
|
29
|
+
Config.configValueLinkCliOption("sort", scanProgram, new Option("--sort <sorter>", 'sort results'));
|
|
30
|
+
Config.configValueLinkCliOption("style", scanProgram, new Option("--style <style>", 'results view mode'));
|
|
31
|
+
Config.configValueLinkCliOption("depth", scanProgram, new Option("--depth <depth>", 'the max results depth'), parseArgInt);
|
|
32
|
+
Config.configValueLinkCliOption("showSources", scanProgram, new Option("--show-sources [show]", 'show scan sources'), parseArgBool);
|
|
33
|
+
program.parseOptions(process.argv);
|
|
34
|
+
const flags = program.opts();
|
|
35
|
+
const chalk = getChalk(flags);
|
|
36
|
+
try {
|
|
37
|
+
Config.configManager.load();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
formatConfigConflicts(chalk, flags.decor, error);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await BuiltIns;
|
|
45
|
+
const configPlugins = Config.configManager.get('plugins');
|
|
46
|
+
const loaded = await loadPluginsQueue(flags.plugins);
|
|
47
|
+
for (const load of loaded) {
|
|
48
|
+
if (!load.isLoaded) {
|
|
49
|
+
logError(format(load.exports), {
|
|
50
|
+
title: `Unable to load plugin '${load.moduleName}' ` + (configPlugins.includes(load.moduleName)
|
|
51
|
+
? '(imported by ' + Config.configManager.filePath + ')'
|
|
52
|
+
: '(imported by --plugins option)')
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (reason) {
|
|
58
|
+
logError(format(reason));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
program.parse();
|
|
62
|
+
}
|
|
63
|
+
/** Chalk, but configured by view-ignored cli. */
|
|
64
|
+
export function getColorLevel(flags) {
|
|
65
|
+
const colorLevel = (flags.noColor ? 0 : Math.max(0, Math.min(Number(flags.color ?? 3), 3)));
|
|
66
|
+
return colorLevel;
|
|
67
|
+
}
|
|
68
|
+
/** Chalk, but configured by view-ignored cli. */
|
|
69
|
+
export function getChalk(flags) {
|
|
70
|
+
const chalk = new Chalk({ level: getColorLevel(flags) });
|
|
71
|
+
return chalk;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* `view-ignored` command-line programl
|
|
75
|
+
*/
|
|
76
|
+
export const program = new Command();
|
|
77
|
+
/**
|
|
78
|
+
* Command-line 'scan' command.
|
|
79
|
+
*/
|
|
80
|
+
export const scanProgram = program
|
|
81
|
+
.command("scan")
|
|
82
|
+
.aliases(['sc'])
|
|
83
|
+
.description('get ignored/included paths')
|
|
84
|
+
.action(actionScan);
|
|
85
|
+
/**
|
|
86
|
+
* Command-line 'config' command.
|
|
87
|
+
*/
|
|
88
|
+
export const cfgProgram = program
|
|
89
|
+
.command("config")
|
|
90
|
+
.alias('cfg')
|
|
91
|
+
.description('cli config manipulation');
|
|
92
|
+
/**
|
|
93
|
+
* Command-line argument: key=value pair.
|
|
94
|
+
* @see {@link parseArgKeyVal}
|
|
95
|
+
*/
|
|
96
|
+
export const argConfigKeyVal = new Argument('[pair]', "the configuration entry key=value'").argParser(parseArgKeyVal);
|
|
97
|
+
/**
|
|
98
|
+
* Command-line argument: config property.
|
|
99
|
+
* @see {@link Config.configKeyList}
|
|
100
|
+
*/
|
|
101
|
+
export const argConfigKey = new Argument('[key]', 'the configuration setting name').choices(Config.configKeyList);
|
|
102
|
+
export const cfgGetOption = new Option('--real', 'use default value(s) as fallback').default(false);
|
|
103
|
+
cfgProgram
|
|
104
|
+
.command('path').description('print the config file path')
|
|
105
|
+
.action(actionCfgPath);
|
|
106
|
+
cfgProgram
|
|
107
|
+
.command('set').description("set config property using syntax 'key=value'")
|
|
108
|
+
.addArgument(argConfigKeyVal)
|
|
109
|
+
.action(actionCfgSet);
|
|
110
|
+
cfgProgram
|
|
111
|
+
.command('unset').description("delete configuration value if cpecified, otherwise delete entire config")
|
|
112
|
+
.addArgument(argConfigKey)
|
|
113
|
+
.action(actionCfgUnset);
|
|
114
|
+
cfgProgram
|
|
115
|
+
.command('get').description('print configuration value(s). You can use --real option to view real values')
|
|
116
|
+
.addOption(cfgGetOption)
|
|
117
|
+
.addArgument(argConfigKey)
|
|
118
|
+
.action(actionCfgGet);
|
|
119
|
+
export function parseArgArrStr(arg) {
|
|
120
|
+
return arg.split(/[ ,|]/).filter(Boolean);
|
|
121
|
+
}
|
|
122
|
+
export function parseArgBool(arg) {
|
|
123
|
+
if (!Config.boolValues.includes(arg)) {
|
|
124
|
+
throw new InvalidArgumentError(`Got invalid value '${arg}'. Should be a boolean.`);
|
|
125
|
+
}
|
|
126
|
+
return Config.trueValues.includes(arg);
|
|
127
|
+
}
|
|
128
|
+
export function parseArgInt(arg) {
|
|
129
|
+
const num = parseInt(arg);
|
|
130
|
+
if (!Number.isInteger(num)) {
|
|
131
|
+
throw new InvalidArgumentError(`Got invalid value '${num}'. Should be an integer.`);
|
|
132
|
+
}
|
|
133
|
+
return num;
|
|
134
|
+
}
|
|
135
|
+
export function parseArgKey(key) {
|
|
136
|
+
if (!Config.isConfigKey(key)) {
|
|
137
|
+
throw new InvalidArgumentError(`Got invalid key '${key}'. Allowed config keys are ${Config.configKeyList.join(', ')}.`);
|
|
138
|
+
}
|
|
139
|
+
return key;
|
|
140
|
+
}
|
|
141
|
+
export function parseArgKeyVal(pair) {
|
|
142
|
+
const result = pair.split('=');
|
|
143
|
+
const [key] = result;
|
|
144
|
+
if (result.length !== 2) {
|
|
145
|
+
throw new InvalidArgumentError(`Expected 'key=value'.`);
|
|
146
|
+
}
|
|
147
|
+
if (!Config.isConfigKey(key)) {
|
|
148
|
+
throw new InvalidArgumentError(`Got invalid key '${key}'. Allowed config keys are ${Config.configKeyList.join(', ')}.`);
|
|
149
|
+
}
|
|
150
|
+
const option = Config.configValueGetCliOption(key);
|
|
151
|
+
const val = option.parseArg?.(result[1], undefined) ?? result[1];
|
|
152
|
+
if (!Config.isConfigValue(key, val)) {
|
|
153
|
+
const list = Config.configValueList(key);
|
|
154
|
+
if (list === undefined) {
|
|
155
|
+
throw new InvalidArgumentError(`Invalid value '${val}' for the key '${key}'.`);
|
|
156
|
+
}
|
|
157
|
+
if (Array.isArray(list)) {
|
|
158
|
+
throw new InvalidArgumentError(`Invalid value '${val}' for the key '${key}'. Allowed config values are ${list.join(', ')}`);
|
|
159
|
+
}
|
|
160
|
+
throw new InvalidArgumentError(`Invalid value '${val}' for the key '${key}'. ${list}`);
|
|
161
|
+
}
|
|
162
|
+
return [key, val];
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Command-line 'scan' command action.
|
|
166
|
+
*/
|
|
167
|
+
export async function actionScan() {
|
|
168
|
+
const flagsGlobal = scanProgram.optsWithGlobals();
|
|
169
|
+
const cwd = process.cwd();
|
|
170
|
+
const start = Date.now();
|
|
171
|
+
const chalk = getChalk(program.opts());
|
|
172
|
+
const fileInfoListP = scanProject(flagsGlobal.target, { filter: flagsGlobal.filter, maxDepth: flagsGlobal.depth })
|
|
173
|
+
.catch((error) => {
|
|
174
|
+
spinner.stop();
|
|
175
|
+
spinner.clear();
|
|
176
|
+
if (!(error instanceof ErrorNoSources)) {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
console.error(`Bad sources for ${flagsGlobal.target}: ${ErrorNoSources.walk(flagsGlobal.target)}`);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
});
|
|
182
|
+
if (flagsGlobal.parsable) {
|
|
183
|
+
console.log((await fileInfoListP).map(fi => fi.filePath + (flagsGlobal.showSources ? '<' + fi.source.sourcePath : '')).join('|'));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const spinner = ora({ text: cwd, color: 'white' });
|
|
187
|
+
spinner.start();
|
|
188
|
+
spinner.suffixText = "Generating...";
|
|
189
|
+
const fileInfoList = await fileInfoListP;
|
|
190
|
+
const sorter = Sorting[flagsGlobal.sort];
|
|
191
|
+
const cache = new Map(fileInfoList.map(String).map(filePath => [filePath, fs.statSync(filePath).mtime.getTime()]));
|
|
192
|
+
const lookedSorted = fileInfoList.sort((a, b) => sorter(a.toString(), b.toString(), cache));
|
|
193
|
+
const files = formatFiles(lookedSorted, { chalk, style: flagsGlobal.style, decor: flagsGlobal.decor, showSources: flagsGlobal.showSources });
|
|
194
|
+
const checkSymbol = decorCondition(flagsGlobal.decor, { ifEmoji: '✅', ifNerd: '\uf00c', postfix: ' ' });
|
|
195
|
+
const fastSymbol = decorCondition(flagsGlobal.decor, { ifEmoji: '⚡', ifNerd: '\udb85\udc0c' });
|
|
196
|
+
const bind = targetGet(flagsGlobal.target);
|
|
197
|
+
const name = typeof bind.name === "string" ? bind.name : decorCondition(flagsGlobal.decor, bind.name);
|
|
198
|
+
const infoSymbol = decorCondition(flagsGlobal.decor, { ifEmoji: 'ℹ️', ifNerd: '\ue66a', postfix: ' ' });
|
|
199
|
+
const time = Date.now() - start;
|
|
200
|
+
let message = '';
|
|
201
|
+
message += files;
|
|
202
|
+
message += '\n';
|
|
203
|
+
message += `${chalk.green(checkSymbol)}Done in ${time < 400 ? chalk.yellow(fastSymbol) : ''}${time}ms.`;
|
|
204
|
+
message += '\n';
|
|
205
|
+
message += `${fileInfoList.length} files listed for ${name} (${flagsGlobal.filter}).`;
|
|
206
|
+
message += '\n';
|
|
207
|
+
if (bind.testCommand) {
|
|
208
|
+
message += '\n';
|
|
209
|
+
message += `${chalk.blue(infoSymbol)}You can use '${chalk.magenta(bind.testCommand)}' to check if the list is valid.`;
|
|
210
|
+
}
|
|
211
|
+
message += '\n';
|
|
212
|
+
spinner.stop();
|
|
213
|
+
spinner.clear();
|
|
214
|
+
console.log(cwd + '\n' + message);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Command-line 'config path' command action.
|
|
218
|
+
*/
|
|
219
|
+
export function actionCfgPath() {
|
|
220
|
+
console.log(Config.configFilePath);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Command-line 'config set' command action
|
|
224
|
+
*/
|
|
225
|
+
export function actionCfgSet(pair) {
|
|
226
|
+
if (pair === undefined) {
|
|
227
|
+
console.log(`Allowed config keys are ${Config.configKeyList.join(', ')}.`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const [key, val] = pair;
|
|
231
|
+
Config.configManager.set(key, val).save();
|
|
232
|
+
console.log(Config.configManager.getPairString(key));
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Command-line 'config unset' command action
|
|
236
|
+
*/
|
|
237
|
+
export function actionCfgUnset(key) {
|
|
238
|
+
if (key === undefined) {
|
|
239
|
+
console.log('Configuration file has been completely deleted.');
|
|
240
|
+
}
|
|
241
|
+
Config.configManager.unset(key).save();
|
|
242
|
+
console.log(Config.configManager.getPairString(key));
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Command-line 'config unset' command action
|
|
246
|
+
*/
|
|
247
|
+
export function actionCfgGet(key, options) {
|
|
248
|
+
console.log(Config.configManager.getPairString(key, options.real));
|
|
249
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ColorSupportLevel } from "chalk";
|
|
2
|
+
import { FilterName, Sorting, Styling } from "./browser/index.js";
|
|
3
|
+
import { Command, Option } from "commander";
|
|
4
|
+
/**
|
|
5
|
+
* Contains all color level names.
|
|
6
|
+
*/
|
|
7
|
+
export declare const colorTypeList: readonly [0, 1, 2, 3];
|
|
8
|
+
/**
|
|
9
|
+
* Contains all color level names as a type.
|
|
10
|
+
*/
|
|
11
|
+
export type ColorType = ColorSupportLevel;
|
|
12
|
+
/**
|
|
13
|
+
* Checks if the value is the {@link ColorType}.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isColorType(value: unknown): value is ColorType;
|
|
16
|
+
/**
|
|
17
|
+
* The full config file name - `".view-ignored"`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const configFileName = ".view-ignored";
|
|
20
|
+
/**
|
|
21
|
+
* The user's home directory + the config file name.
|
|
22
|
+
* @see {@link os.homedir}
|
|
23
|
+
*/
|
|
24
|
+
export declare const configFilePath: string;
|
|
25
|
+
/**
|
|
26
|
+
* Command-line configuration property list.
|
|
27
|
+
*/
|
|
28
|
+
export declare const configKeyList: readonly ["color", "target", "filter", "sort", "style", "decor", "depth", "showSources", "plugins", "parsable"];
|
|
29
|
+
/**
|
|
30
|
+
* Command-line configuration's key type.
|
|
31
|
+
*/
|
|
32
|
+
export type ConfigKey = typeof configKeyList[number] & keyof Config;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the value is the {@link ConfigKey}.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isConfigKey(value: unknown): value is ConfigKey;
|
|
37
|
+
export type ConfigValue<KeyT extends ConfigKey = ConfigKey> = Config[KeyT];
|
|
38
|
+
export type ShowSourcesType = boolean;
|
|
39
|
+
export declare function isShowSources(value: unknown): value is ShowSourcesType;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if the value is the {@link Config} value for the specific {@link ConfigKey}.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isConfigValue<T extends ConfigKey>(key: T, value: unknown): value is Config[T];
|
|
44
|
+
/**
|
|
45
|
+
* Represents array with the key nad the value.
|
|
46
|
+
*/
|
|
47
|
+
export type ConfigPair<KeyT extends ConfigKey = ConfigKey> = [key: KeyT, value: ConfigValue<KeyT>];
|
|
48
|
+
/**
|
|
49
|
+
* Command-line configuration structure.
|
|
50
|
+
* @see {@link configKeyList} Before adding new properties.
|
|
51
|
+
*/
|
|
52
|
+
export type Config = {
|
|
53
|
+
parsable: boolean;
|
|
54
|
+
plugins: string[];
|
|
55
|
+
color: ColorType;
|
|
56
|
+
target: string;
|
|
57
|
+
filter: FilterName;
|
|
58
|
+
sort: Sorting.SortName;
|
|
59
|
+
style: Styling.StyleName;
|
|
60
|
+
decor: Styling.DecorName;
|
|
61
|
+
depth: number;
|
|
62
|
+
showSources: ShowSourcesType;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Command-line default config values.
|
|
66
|
+
*/
|
|
67
|
+
export declare const configDefault: Readonly<Config>;
|
|
68
|
+
/**
|
|
69
|
+
* @returns `true`, if the value can be used as a configuration.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isConfigPartial(cfg: unknown): cfg is Partial<Config>;
|
|
72
|
+
export declare const trueValues: string[];
|
|
73
|
+
export declare const falseValues: string[];
|
|
74
|
+
export declare const boolValues: string[];
|
|
75
|
+
/**
|
|
76
|
+
* @returns available values or requirement message for the specified property.
|
|
77
|
+
* @param key The config property.
|
|
78
|
+
* @param fallbackDefault If `true`, the default value will be used when the value is `undefined`. Default `true`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function configValueList<T extends ConfigKey>(key: T): readonly string[] | string;
|
|
81
|
+
export declare function configValueLinkCliOption<T extends ConfigKey>(key: T, command: Command, option: Option, parseArg?: (arg: string) => unknown): Option;
|
|
82
|
+
export declare function configValueGetCliOption<T extends ConfigKey>(key: T): Option | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* File-specific actions container.
|
|
85
|
+
*/
|
|
86
|
+
export declare class ConfigManager {
|
|
87
|
+
readonly filePath: string;
|
|
88
|
+
constructor(filePath: string);
|
|
89
|
+
/**
|
|
90
|
+
* Do not change this value directly.
|
|
91
|
+
* @see {@link configManager}.
|
|
92
|
+
*/
|
|
93
|
+
private data;
|
|
94
|
+
dataRaw(): unknown;
|
|
95
|
+
entries(): [string, any][] | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Loads the config from the file to {@link configManager.data}. If the data is not valid, throws an error without loading.
|
|
98
|
+
* @returns `undefined` if the config file does not exist.
|
|
99
|
+
*/
|
|
100
|
+
load(): this | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Saves the partial config to the file. If there are no settings, the file will be deleted, if exists.
|
|
103
|
+
*/
|
|
104
|
+
save(): this;
|
|
105
|
+
/**
|
|
106
|
+
* Sets a new value for the specified config property.
|
|
107
|
+
* Expects a valid value.
|
|
108
|
+
* @param key The name of the config property.
|
|
109
|
+
* @param value The new value for the config property.
|
|
110
|
+
*/
|
|
111
|
+
set<T extends ConfigKey>(key: T, value: Config[T]): this;
|
|
112
|
+
/**
|
|
113
|
+
* Deletes the specified property from the config.
|
|
114
|
+
* If the property is not specified, then all properties will be deleted.
|
|
115
|
+
* @param key The config property.
|
|
116
|
+
*/
|
|
117
|
+
unset<T extends ConfigKey>(key?: T): this;
|
|
118
|
+
/**
|
|
119
|
+
* @returns An array of properties which defined in the configuration file.
|
|
120
|
+
*/
|
|
121
|
+
definedKeys(): ConfigKey[];
|
|
122
|
+
/**
|
|
123
|
+
* @param key The config property.
|
|
124
|
+
* @param defs If `true`, the default value will be used when the value is `undefined`. Default `true`.
|
|
125
|
+
* @returns The value for the specified property.
|
|
126
|
+
*/
|
|
127
|
+
get<KeyT extends ConfigKey>(key: KeyT, defs: false): ConfigValue<KeyT> | undefined;
|
|
128
|
+
get<KeyT extends ConfigKey>(key: KeyT, defs?: true): ConfigValue<KeyT>;
|
|
129
|
+
get<KeyT extends ConfigKey>(key: KeyT, defs: boolean): ConfigValue<KeyT> | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* @param key The config property.
|
|
132
|
+
* @param defs If `true`, the default value will be used when the value is `undefined`. Default `true`.
|
|
133
|
+
* @returns A string in the `"key=value"` format, if the property is specified.
|
|
134
|
+
* Otherwise in format `"key=value\nkey=value\n..."` without the '\n' ending.
|
|
135
|
+
*/
|
|
136
|
+
getPairString<KeyT extends ConfigKey>(key?: KeyT, defs?: boolean): string;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* File-specific actions container. Contains get, set, unset, save, load and other configuration actions.
|
|
140
|
+
*/
|
|
141
|
+
export declare const configManager: ConfigManager;
|