@visulima/cerebro 3.0.0-alpha.9 → 3.0.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/CHANGELOG.md +593 -0
- package/LICENSE.md +1295 -3950
- package/README.md +182 -2
- package/dist/commands/completion-command.d.ts +6 -5
- package/dist/commands/completion-command.js +5 -203
- package/dist/commands/help-command.d.ts +10 -9
- package/dist/commands/help-command.js +1 -3
- package/dist/commands/readme-command.d.ts +6 -5
- package/dist/commands/readme-command.js +32 -330
- package/dist/commands/version-command.d.ts +4 -3
- package/dist/commands/version-command.js +1 -18
- package/dist/index.d.ts +516 -95
- package/dist/index.js +1 -7
- package/dist/logger/create-pail-logger.d.ts +770 -8
- package/dist/logger/create-pail-logger.js +1 -34
- package/dist/packem_chunks/has-new-version.js +1 -259
- package/dist/packem_shared/Cerebro-Czc4t-75.js +4 -0
- package/dist/packem_shared/VERBOSITY_DEBUG-XPultrIA.js +1 -0
- package/dist/packem_shared/VisulimaError-C90oeIMu.js +76 -0
- package/dist/packem_shared/VisulimaError-DTMgXonA-CzaryRgZ.js +1 -0
- package/dist/packem_shared/cerebro-error-BjBcYVRO.js +1 -0
- package/dist/packem_shared/command.d-DbhtfXF4.d.ts +639 -0
- package/dist/packem_shared/index-DvVGK4kr.js +29 -0
- package/dist/packem_shared/index.d-BL4NtVR3.d.ts +127 -0
- package/dist/packem_shared/lazyNamed-DMUm8mZe.js +1 -0
- package/dist/packem_shared/renderError-B3ePOoBG-BmZlyMcr.js +25 -0
- package/dist/packem_shared/runtime-process-Dmz0vCJy.js +1 -0
- package/dist/packem_shared/split-by-case-Dbpgd7rf.js +1 -0
- package/dist/plugins/error-handler-plugin.d.ts +21 -19
- package/dist/plugins/error-handler-plugin.js +1 -636
- package/dist/plugins/runtime-version-check-plugin.d.ts +22 -20
- package/dist/plugins/runtime-version-check-plugin.js +1 -77
- package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +28 -8
- package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -517
- package/dist/util/general/compile-cache.d.ts +41 -0
- package/dist/util/general/compile-cache.js +1 -0
- package/dist/util/general/heap-tuning.d.ts +18 -0
- package/dist/util/general/heap-tuning.js +1 -0
- package/package.json +53 -48
- package/dist/cli.d.ts +0 -203
- package/dist/constants.d.ts +0 -29
- package/dist/default-env.d.ts +0 -7
- package/dist/default-options.d.ts +0 -3
- package/dist/empty-toolbox.d.ts +0 -15
- package/dist/errors/cerebro-error.d.ts +0 -10
- package/dist/errors/command-not-found-error.d.ts +0 -9
- package/dist/errors/command-validation-error.d.ts +0 -10
- package/dist/errors/completion-error.d.ts +0 -9
- package/dist/errors/conflicting-options-error.d.ts +0 -10
- package/dist/errors/plugin-error.d.ts +0 -9
- package/dist/errors/update-notifier-error.d.ts +0 -7
- package/dist/packem_shared/Cerebro-C2mnCyQf.js +0 -3313
- package/dist/packem_shared/VERBOSITY_QUIET-Dp46zlLW.js +0 -10
- package/dist/packem_shared/VisulimaError-DA7QsCxH.js +0 -34
- package/dist/packem_shared/cerebro-error-GmJ3jN7Q.js +0 -16
- package/dist/packem_shared/help-command-BY7rQUvM.js +0 -249
- package/dist/packem_shared/index-C2-8b3A4.js +0 -259
- package/dist/packem_shared/runtime-process-B6ZplyWn.js +0 -187
- package/dist/plugin-manager.d.ts +0 -53
- package/dist/plugins/update-notifier/cache.d.ts +0 -11
- package/dist/plugins/update-notifier/get-distribution-version.d.ts +0 -2
- package/dist/plugins/update-notifier/has-new-version.d.ts +0 -14
- package/dist/types/cli.d.ts +0 -102
- package/dist/types/command-line-usage.d.ts +0 -37
- package/dist/types/command.d.ts +0 -136
- package/dist/types/option-types.d.ts +0 -83
- package/dist/types/options.d.ts +0 -4
- package/dist/types/plugin.d.ts +0 -53
- package/dist/types/toolbox.d.ts +0 -96
- package/dist/util/arg-processing/get-boolean-values.d.ts +0 -7
- package/dist/util/arg-processing/get-parameter-option.d.ts +0 -7
- package/dist/util/arg-processing/map-option-type-label.d.ts +0 -3
- package/dist/util/arg-processing/option-is-boolean.d.ts +0 -9
- package/dist/util/arg-processing/remove-boolean-values.d.ts +0 -9
- package/dist/util/command-line-commands.d.ts +0 -10
- package/dist/util/command-line-usage/get-terminal-width.d.ts +0 -7
- package/dist/util/command-line-usage/index.d.ts +0 -3
- package/dist/util/command-line-usage/section/base-section.d.ts +0 -8
- package/dist/util/command-line-usage/section/content-section.d.ts +0 -65
- package/dist/util/command-line-usage/section/option-list-section.d.ts +0 -44
- package/dist/util/command-processing/command-processor.d.ts +0 -37
- package/dist/util/command-processing/command-validation.d.ts +0 -17
- package/dist/util/command-processing/nested-command-parser.d.ts +0 -25
- package/dist/util/command-processing/option-processor.d.ts +0 -44
- package/dist/util/data-processing/list-missing-arguments.d.ts +0 -15
- package/dist/util/data-processing/merge-arguments.d.ts +0 -7
- package/dist/util/general/find-alternatives.d.ts +0 -8
- package/dist/util/general/hide-bin.d.ts +0 -2
- package/dist/util/general/parse-raw-command.d.ts +0 -7
- package/dist/util/general/register-exception-handler.d.ts +0 -9
- package/dist/util/general/runtime-process.d.ts +0 -65
- package/dist/util/general/semver-gt.d.ts +0 -2
- package/dist/util/general/validate-input.d.ts +0 -24
- package/dist/util/process-env-variables.d.ts +0 -9
- package/dist/util/security.d.ts +0 -58
- package/dist/util/text-processing/template-format.d.ts +0 -5
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
const hasDeno = (global) => "Deno" in global;
|
|
2
|
-
const hasBun = (global) => "Bun" in global;
|
|
3
|
-
const getArgv = () => {
|
|
4
|
-
if (hasDeno(globalThis)) {
|
|
5
|
-
const deno = globalThis.Deno;
|
|
6
|
-
const execPath = deno.execPath();
|
|
7
|
-
let scriptPath = execPath;
|
|
8
|
-
try {
|
|
9
|
-
const { importMeta } = globalThis;
|
|
10
|
-
if (importMeta?.url) {
|
|
11
|
-
scriptPath = importMeta.url;
|
|
12
|
-
}
|
|
13
|
-
} catch {
|
|
14
|
-
}
|
|
15
|
-
return [execPath, scriptPath, ...deno.args];
|
|
16
|
-
}
|
|
17
|
-
if (hasBun(globalThis)) {
|
|
18
|
-
const bun = globalThis.Bun;
|
|
19
|
-
return bun.process.argv;
|
|
20
|
-
}
|
|
21
|
-
return process.argv;
|
|
22
|
-
};
|
|
23
|
-
const getCwd = () => {
|
|
24
|
-
if (hasDeno(globalThis)) {
|
|
25
|
-
const deno = globalThis.Deno;
|
|
26
|
-
return deno.cwd();
|
|
27
|
-
}
|
|
28
|
-
if (hasBun(globalThis)) {
|
|
29
|
-
const bun = globalThis.Bun;
|
|
30
|
-
return bun.process.cwd();
|
|
31
|
-
}
|
|
32
|
-
return process.cwd();
|
|
33
|
-
};
|
|
34
|
-
const getEnv = () => {
|
|
35
|
-
if (hasDeno(globalThis)) {
|
|
36
|
-
const deno = globalThis.Deno;
|
|
37
|
-
return /* @__PURE__ */ new Proxy(deno.env.toObject(), {
|
|
38
|
-
get: (target, prop) => {
|
|
39
|
-
if (typeof prop === "string") {
|
|
40
|
-
return deno.env.get(prop);
|
|
41
|
-
}
|
|
42
|
-
return target[prop];
|
|
43
|
-
},
|
|
44
|
-
has: (target, prop) => {
|
|
45
|
-
if (typeof prop === "string") {
|
|
46
|
-
return deno.env.has(prop);
|
|
47
|
-
}
|
|
48
|
-
return prop in target;
|
|
49
|
-
},
|
|
50
|
-
set: (_target, prop, value) => {
|
|
51
|
-
if (typeof prop === "string") {
|
|
52
|
-
if (value === void 0) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
deno.env.set(prop, value);
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (hasBun(globalThis)) {
|
|
63
|
-
const bun = globalThis.Bun;
|
|
64
|
-
return bun.process.env;
|
|
65
|
-
}
|
|
66
|
-
return process.env;
|
|
67
|
-
};
|
|
68
|
-
const getExecArgv = () => {
|
|
69
|
-
if (hasDeno(globalThis)) {
|
|
70
|
-
return [];
|
|
71
|
-
}
|
|
72
|
-
if (hasBun(globalThis)) {
|
|
73
|
-
const bun = globalThis.Bun;
|
|
74
|
-
return bun.process.execArgv;
|
|
75
|
-
}
|
|
76
|
-
return process.execArgv;
|
|
77
|
-
};
|
|
78
|
-
const getExecPath = () => {
|
|
79
|
-
if (hasDeno(globalThis)) {
|
|
80
|
-
const deno = globalThis.Deno;
|
|
81
|
-
return deno.execPath();
|
|
82
|
-
}
|
|
83
|
-
if (hasBun(globalThis)) {
|
|
84
|
-
const bun = globalThis.Bun;
|
|
85
|
-
return bun.process.execPath;
|
|
86
|
-
}
|
|
87
|
-
return process.execPath;
|
|
88
|
-
};
|
|
89
|
-
const getPlatform = () => {
|
|
90
|
-
if (hasDeno(globalThis)) {
|
|
91
|
-
const deno = globalThis.Deno;
|
|
92
|
-
const os = deno.build?.os ?? "unknown";
|
|
93
|
-
return os === "windows" ? "win32" : os;
|
|
94
|
-
}
|
|
95
|
-
if (hasBun(globalThis)) {
|
|
96
|
-
const bun = globalThis.Bun;
|
|
97
|
-
return bun.platform ?? "unknown";
|
|
98
|
-
}
|
|
99
|
-
return process.platform;
|
|
100
|
-
};
|
|
101
|
-
const getArch = () => {
|
|
102
|
-
if (hasDeno(globalThis)) {
|
|
103
|
-
const deno = globalThis.Deno;
|
|
104
|
-
const arch = deno.build?.arch ?? "unknown";
|
|
105
|
-
if (arch === "x86_64") {
|
|
106
|
-
return "x64";
|
|
107
|
-
}
|
|
108
|
-
if (arch === "aarch64") {
|
|
109
|
-
return "arm64";
|
|
110
|
-
}
|
|
111
|
-
return arch;
|
|
112
|
-
}
|
|
113
|
-
if (hasBun(globalThis)) {
|
|
114
|
-
const bun = globalThis.Bun;
|
|
115
|
-
return bun.process.arch;
|
|
116
|
-
}
|
|
117
|
-
return process.arch;
|
|
118
|
-
};
|
|
119
|
-
const getVersions = () => {
|
|
120
|
-
if (hasDeno(globalThis)) {
|
|
121
|
-
const deno = globalThis.Deno;
|
|
122
|
-
const versions = {};
|
|
123
|
-
if (deno.version?.deno) {
|
|
124
|
-
versions.deno = deno.version.deno;
|
|
125
|
-
}
|
|
126
|
-
if (deno.version?.v8) {
|
|
127
|
-
versions.v8 = deno.version.v8;
|
|
128
|
-
}
|
|
129
|
-
if (deno.version?.typescript) {
|
|
130
|
-
versions.typescript = deno.version.typescript;
|
|
131
|
-
}
|
|
132
|
-
return versions;
|
|
133
|
-
}
|
|
134
|
-
if (hasBun(globalThis)) {
|
|
135
|
-
const bun = globalThis.Bun;
|
|
136
|
-
const versions = { ...bun.process.versions };
|
|
137
|
-
if (bun.version) {
|
|
138
|
-
versions.bun = bun.version;
|
|
139
|
-
}
|
|
140
|
-
return versions;
|
|
141
|
-
}
|
|
142
|
-
return process.versions;
|
|
143
|
-
};
|
|
144
|
-
const exitProcess = (exitCode = 0) => {
|
|
145
|
-
if (hasDeno(globalThis)) {
|
|
146
|
-
const deno = globalThis.Deno;
|
|
147
|
-
deno.exit(exitCode);
|
|
148
|
-
throw new Error("Deno exit failed");
|
|
149
|
-
}
|
|
150
|
-
if (hasBun(globalThis)) {
|
|
151
|
-
const bun = globalThis.Bun;
|
|
152
|
-
bun.process.exit(exitCode);
|
|
153
|
-
throw new Error("Bun exit failed");
|
|
154
|
-
}
|
|
155
|
-
const nodeProcess = process;
|
|
156
|
-
nodeProcess.exit(exitCode);
|
|
157
|
-
return void 0;
|
|
158
|
-
};
|
|
159
|
-
const onProcessEvent = (event, handler) => {
|
|
160
|
-
if (hasDeno(globalThis)) {
|
|
161
|
-
return () => {
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if (hasBun(globalThis)) {
|
|
165
|
-
try {
|
|
166
|
-
const bun = globalThis.Bun;
|
|
167
|
-
if (bun.process?.on) {
|
|
168
|
-
bun.process.on(event, handler);
|
|
169
|
-
return () => {
|
|
170
|
-
if (bun.process?.removeListener) {
|
|
171
|
-
bun.process.removeListener(event, handler);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
} catch {
|
|
176
|
-
}
|
|
177
|
-
return () => {
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
const nodeProcess = process;
|
|
181
|
-
nodeProcess.on(event, handler);
|
|
182
|
-
return () => {
|
|
183
|
-
nodeProcess.removeListener(event, handler);
|
|
184
|
-
};
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export { getVersions as a, getPlatform as b, getArch as c, getEnv as d, exitProcess as e, getArgv as f, getCwd as g, getExecPath as h, getExecArgv as i, onProcessEvent as o };
|
package/dist/plugin-manager.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { Plugin, PluginContext } from "./types/plugin.d.ts";
|
|
2
|
-
import type { Toolbox } from "./types/toolbox.d.ts";
|
|
3
|
-
type Logger = Console;
|
|
4
|
-
/**
|
|
5
|
-
* Manages plugin lifecycle and execution
|
|
6
|
-
*/
|
|
7
|
-
declare class PluginManager<T extends Logger = Logger> {
|
|
8
|
-
private readonly logger;
|
|
9
|
-
private readonly plugins;
|
|
10
|
-
private initialized;
|
|
11
|
-
private cachedDependencyOrder;
|
|
12
|
-
constructor(logger: T);
|
|
13
|
-
/**
|
|
14
|
-
* Checks if any plugins are registered.
|
|
15
|
-
* @returns True if at least one plugin is registered
|
|
16
|
-
*/
|
|
17
|
-
hasPlugins(): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Registers a plugin.
|
|
20
|
-
* @param plugin The plugin to register
|
|
21
|
-
* @throws {Error} If plugin name is already registered or dependencies are invalid
|
|
22
|
-
*/
|
|
23
|
-
register(plugin: Plugin<T>): void;
|
|
24
|
-
/**
|
|
25
|
-
* Initializes all registered plugins.
|
|
26
|
-
* @param context The plugin context for initialization
|
|
27
|
-
*/
|
|
28
|
-
init(context: PluginContext<T>): Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Executes a specific lifecycle hook for all plugins.
|
|
31
|
-
* @param hook The lifecycle hook name
|
|
32
|
-
* @param toolbox The command toolbox (for command-specific hooks)
|
|
33
|
-
* @param result The command result (for afterCommand hook)
|
|
34
|
-
*/
|
|
35
|
-
executeLifecycle(hook: "beforeCommand" | "afterCommand" | "execute", toolbox: Toolbox<T>, result?: unknown): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Executes error handlers for all plugins.
|
|
38
|
-
* @param error The error that occurred
|
|
39
|
-
* @param toolbox The command toolbox
|
|
40
|
-
*/
|
|
41
|
-
executeErrorHandlers(error: Error, toolbox: Toolbox<T>): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Gets all registered plugins in dependency order.
|
|
44
|
-
* @returns Array of plugins sorted by dependencies
|
|
45
|
-
*/
|
|
46
|
-
getDependencyOrder(): Plugin<T>[];
|
|
47
|
-
/**
|
|
48
|
-
* Validates that all plugin dependencies exist.
|
|
49
|
-
* @throws {Error} If any dependencies are missing
|
|
50
|
-
*/
|
|
51
|
-
private validateDependencies;
|
|
52
|
-
}
|
|
53
|
-
export default PluginManager;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retrieves the last update check timestamp for the specified package.
|
|
3
|
-
* @param packageName
|
|
4
|
-
* @returns - The timestamp of the last update check, or undefined if the check failed.
|
|
5
|
-
*/
|
|
6
|
-
export declare const getLastUpdate: (packageName: string) => number | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Saves the last update time for a given package.
|
|
9
|
-
* @param packageName
|
|
10
|
-
*/
|
|
11
|
-
export declare const saveLastUpdate: (packageName: string) => void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
declare const hasNewVersion: ({ alwaysRun, debug, distTag: distributionTag, pkg, registryUrl, updateCheckInterval, }: UpdateNotifierOptions) => Promise<string | undefined>;
|
|
2
|
-
export type UpdateNotifierOptions = {
|
|
3
|
-
alwaysRun?: boolean;
|
|
4
|
-
debug?: boolean;
|
|
5
|
-
distTag?: string;
|
|
6
|
-
pkg: {
|
|
7
|
-
name: string;
|
|
8
|
-
version: string;
|
|
9
|
-
};
|
|
10
|
-
registryUrl?: string;
|
|
11
|
-
shouldNotifyInNpmScript?: boolean;
|
|
12
|
-
updateCheckInterval?: number;
|
|
13
|
-
};
|
|
14
|
-
export default hasNewVersion;
|
package/dist/types/cli.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type PluginManager from "../plugin-manager.d.ts";
|
|
2
|
-
import type { Command as ICommand, OptionDefinition } from "./command.d.ts";
|
|
3
|
-
import type { Plugin } from "./plugin.d.ts";
|
|
4
|
-
export type CommandSection = {
|
|
5
|
-
footer?: string;
|
|
6
|
-
header?: string;
|
|
7
|
-
};
|
|
8
|
-
export type CliRunOptions = {
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
/**
|
|
11
|
-
* Whether to automatically dispose/cleanup the CLI instance after execution
|
|
12
|
-
* @default true
|
|
13
|
-
*/
|
|
14
|
-
autoDispose?: boolean;
|
|
15
|
-
shouldExitProcess?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export type RunCommandOptions = {
|
|
18
|
-
/**
|
|
19
|
-
* Extra options to merge into the command's options.
|
|
20
|
-
* These will be merged with the command's default options and parsed arguments.
|
|
21
|
-
* Use this to override or add additional options programmatically.
|
|
22
|
-
* @default Empty object
|
|
23
|
-
*/
|
|
24
|
-
[key: string]: unknown;
|
|
25
|
-
/**
|
|
26
|
-
* Command-line arguments to pass to the command.
|
|
27
|
-
* If not provided, uses the default argv from the CLI instance.
|
|
28
|
-
* These arguments will be parsed and merged with the command's options.
|
|
29
|
-
* @default Empty array
|
|
30
|
-
*/
|
|
31
|
-
argv?: string[];
|
|
32
|
-
};
|
|
33
|
-
export interface Cli<T extends Console> {
|
|
34
|
-
/**
|
|
35
|
-
* Add an arbitrary command to the CLI.
|
|
36
|
-
* @param command The command to add.
|
|
37
|
-
* @returns self
|
|
38
|
-
*/
|
|
39
|
-
addCommand: <OD extends OptionDefinition<unknown> = OptionDefinition<unknown>>(command: ICommand<OD, T>) => this;
|
|
40
|
-
/**
|
|
41
|
-
* Add a plugin to extend the CLI functionality
|
|
42
|
-
* @param plugin The plugin to add.
|
|
43
|
-
* @returns self
|
|
44
|
-
*/
|
|
45
|
-
addPlugin: (plugin: Plugin<T>) => this;
|
|
46
|
-
/**
|
|
47
|
-
* Disposes the CLI instance and cleans up resources
|
|
48
|
-
* @returns void
|
|
49
|
-
*/
|
|
50
|
-
dispose: () => void;
|
|
51
|
-
getCliName: () => string;
|
|
52
|
-
getCommands: () => Map<string, ICommand<OptionDefinition<unknown>, T>>;
|
|
53
|
-
getCommandSection: () => CommandSection;
|
|
54
|
-
getCwd: () => string;
|
|
55
|
-
getPackageName: () => string | undefined;
|
|
56
|
-
getPackageVersion: () => string | undefined;
|
|
57
|
-
/**
|
|
58
|
-
* Get the plugin manager instance
|
|
59
|
-
* @returns The plugin manager
|
|
60
|
-
*/
|
|
61
|
-
getPluginManager: () => PluginManager<T>;
|
|
62
|
-
run: (extraOptions?: CliRunOptions) => Promise<void>;
|
|
63
|
-
/**
|
|
64
|
-
* Runs a command programmatically from within another command.
|
|
65
|
-
* This allows commands to call other commands during execution.
|
|
66
|
-
* @param commandName The name of the command to execute
|
|
67
|
-
* @param options Optional options including argv and other command options
|
|
68
|
-
* @returns A promise that resolves with the command's result (or void if command doesn't return a value)
|
|
69
|
-
* @throws {Error} If the specified command doesn't exist or command arguments are invalid
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* cli.addCommand({
|
|
73
|
-
* name: 'deploy',
|
|
74
|
-
* execute: async ({ runtime, logger }) => {
|
|
75
|
-
* logger.info('Building...');
|
|
76
|
-
* const buildResult = await runtime.runCommand('build', { argv: ['--production'] });
|
|
77
|
-
* // buildResult is the return value from the build command's execute function
|
|
78
|
-
*
|
|
79
|
-
* logger.info('Testing...');
|
|
80
|
-
* await runtime.runCommand('test', { argv: ['--coverage'] });
|
|
81
|
-
* }
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
runCommand: (commandName: string, options?: RunCommandOptions) => Promise<unknown>;
|
|
86
|
-
setCommandSection: (commandSection: CommandSection) => this;
|
|
87
|
-
/**
|
|
88
|
-
* Set a default command, to display a different command if cli is call without command.
|
|
89
|
-
* @param commandName
|
|
90
|
-
* @returns self
|
|
91
|
-
*/
|
|
92
|
-
setDefaultCommand: (commandName: string) => this;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Any of the output types [[OUTPUT_NORMAL]], [[OUTPUT_RAW]] and [[OUTPUT_PLAIN]].
|
|
96
|
-
*/
|
|
97
|
-
export type OutputType = 1 | 2 | 4;
|
|
98
|
-
/**
|
|
99
|
-
* Any of the verbosity types
|
|
100
|
-
* [[VERBOSITY_QUIET]], [[VERBOSITY_NORMAL]], [[VERBOSITY_VERBOSE]] and [[VERBOSITY_DEBUG]].
|
|
101
|
-
*/
|
|
102
|
-
export type VERBOSITY_LEVEL = 16 | 32 | 64 | 128 | 256;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { TableOptions } from "@visulima/tabular";
|
|
2
|
-
import type { ArgumentDefinition, OptionDefinition } from "./command.d.ts";
|
|
3
|
-
/** A Content section comprises a header and one or more lines of content. */
|
|
4
|
-
export interface Content {
|
|
5
|
-
/**
|
|
6
|
-
* Overloaded property, accepting data in one of four formats.
|
|
7
|
-
* 1. A single string (one line of text).
|
|
8
|
-
* 2. An array of strings (multiple lines of text).
|
|
9
|
-
* 3. An array of arrays (recordset-style data). In this case, the data will be rendered in table format.
|
|
10
|
-
* 4. An object with two properties - data and options. In this case, the data and options will be passed directly to the underlying table module for rendering.
|
|
11
|
-
*/
|
|
12
|
-
content?: string[] | string[][] | string | {
|
|
13
|
-
data: string[][];
|
|
14
|
-
options: TableOptions;
|
|
15
|
-
};
|
|
16
|
-
/** The section header, always bold and underlined. */
|
|
17
|
-
header?: string;
|
|
18
|
-
/** Set to true to avoid indentation and wrapping. Useful for banners. */
|
|
19
|
-
raw?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/** A OptionList section adds a table displaying details of the available options. */
|
|
22
|
-
export interface OptionList<O extends OptionDefinition<any> = any> {
|
|
23
|
-
/** If specified, only options from this particular group will be printed. */
|
|
24
|
-
group?: string[] | string;
|
|
25
|
-
header?: string | undefined;
|
|
26
|
-
/** The names of one of more option definitions to hide from the option list. */
|
|
27
|
-
hide?: string[] | string;
|
|
28
|
-
/** If specified, the -- prefix will be omitted from the option name. */
|
|
29
|
-
isArgument?: boolean;
|
|
30
|
-
/** An array of option definition objects. */
|
|
31
|
-
optionList?: (ArgumentDefinition | O | OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<string[]> | OptionDefinition<string>)[];
|
|
32
|
-
/** If true, the option alias will be displayed after the name, i.e. --verbose, -v instead of -v, --verbose). */
|
|
33
|
-
reverseNameOrder?: boolean;
|
|
34
|
-
/** An options object suitable for passing into table. */
|
|
35
|
-
tableOptions?: TableOptions;
|
|
36
|
-
}
|
|
37
|
-
export type Section = Content | OptionList;
|
package/dist/types/command.d.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import type { OptionDefinition as BaseOptionDefinition } from "@visulima/command-line-args";
|
|
2
|
-
import type { Content } from "./command-line-usage.d.ts";
|
|
3
|
-
import type { Toolbox as IToolbox } from "./toolbox.d.ts";
|
|
4
|
-
type TypeConstructor<T> = (value: unknown) => T extends (infer R)[] ? R | undefined : T | undefined;
|
|
5
|
-
/**
|
|
6
|
-
* Type constructor for environment variables.
|
|
7
|
-
* Environment variables are always strings (or undefined), so the transform function receives string | undefined.
|
|
8
|
-
*/
|
|
9
|
-
type EnvTypeConstructor<T> = (value: string | undefined) => T extends (infer R)[] ? R | undefined : T | undefined;
|
|
10
|
-
type MultiplePropertyOptions<T> = T extends ReadonlyArray<unknown> ? {
|
|
11
|
-
lazyMultiple: true;
|
|
12
|
-
} | {
|
|
13
|
-
multiple: true;
|
|
14
|
-
} : unknown;
|
|
15
|
-
export type OptionDefinition<T> = MultiplePropertyOptions<T> & Omit<BaseOptionDefinition, "type|defaultValue"> & {
|
|
16
|
-
__camelCaseName__?: string;
|
|
17
|
-
__negated__?: true;
|
|
18
|
-
/**
|
|
19
|
-
* A string or array of strings indicating the conflicting option(s).
|
|
20
|
-
* Note: The default value for an option does not cause a conflict.
|
|
21
|
-
*/
|
|
22
|
-
conflicts?: string[] | string;
|
|
23
|
-
/** An initial value for the option. */
|
|
24
|
-
defaultValue?: T | undefined;
|
|
25
|
-
/** A string describing the option. */
|
|
26
|
-
description?: string | undefined;
|
|
27
|
-
/** Option is hidden from help */
|
|
28
|
-
hidden?: boolean;
|
|
29
|
-
implies?: Record<string, unknown>;
|
|
30
|
-
/** Specifies whether the variable is required. */
|
|
31
|
-
required?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* A setter function (you receive the output from this) enabling you to be specific about the type and value received. Typical values
|
|
34
|
-
* are `String`, `Number` and `Boolean` but you can use a custom function.
|
|
35
|
-
*/
|
|
36
|
-
type?: TypeConstructor<T> | undefined;
|
|
37
|
-
/** A string to replace the default type string (e.g. <string>). It's often more useful to set a more descriptive type label, like <ms>, <files>, <command>, etc.. */
|
|
38
|
-
typeLabel?: string | undefined;
|
|
39
|
-
};
|
|
40
|
-
export type PossibleOptionDefinition<OD> = OD | OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<string[]> | OptionDefinition<string>;
|
|
41
|
-
export type ArgumentDefinition<T = unknown> = Omit<OptionDefinition<T>, "multiple|lazyMultiple|defaultOption|alias|group|defaultValue">;
|
|
42
|
-
/**
|
|
43
|
-
* Environment variable definition for commands.
|
|
44
|
-
* Used to document and provide type-safe access to environment variables a command supports.
|
|
45
|
-
* @template T The type of the environment variable value
|
|
46
|
-
*/
|
|
47
|
-
export interface EnvDefinition<T = string> {
|
|
48
|
-
/** Default value if the environment variable is not set */
|
|
49
|
-
defaultValue?: T | undefined;
|
|
50
|
-
/** A description of what the environment variable does */
|
|
51
|
-
description?: string | undefined;
|
|
52
|
-
/** Environment variable is hidden from help */
|
|
53
|
-
hidden?: boolean;
|
|
54
|
-
/** The name of the environment variable */
|
|
55
|
-
name: string;
|
|
56
|
-
/**
|
|
57
|
-
* A transform function to convert the string environment variable value to the desired type.
|
|
58
|
-
* Typical values are `String`, `Number`, `Boolean` or custom functions.
|
|
59
|
-
* The function receives `string | undefined` and should return the transformed value.
|
|
60
|
-
*/
|
|
61
|
-
type?: EnvTypeConstructor<T> | undefined;
|
|
62
|
-
/** A string to replace the default type string (e.g. <string>). Useful for more descriptive type labels. */
|
|
63
|
-
typeLabel?: string | undefined;
|
|
64
|
-
}
|
|
65
|
-
export type PossibleEnvDefinition = EnvDefinition<boolean> | EnvDefinition<number> | EnvDefinition<string>;
|
|
66
|
-
/**
|
|
67
|
-
* Command interface with type-safe options and environment variables.
|
|
68
|
-
* @template O - The option definition type
|
|
69
|
-
* @template TContext - The toolbox context type (allows custom typing for better autocomplete)
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* // Define your options type for autocomplete
|
|
73
|
-
* type BuildOptions = {
|
|
74
|
-
* output?: string;
|
|
75
|
-
* production?: boolean;
|
|
76
|
-
* watch?: boolean;
|
|
77
|
-
* };
|
|
78
|
-
*
|
|
79
|
-
* type BuildEnv = {
|
|
80
|
-
* apiKey?: string;
|
|
81
|
-
* debug?: boolean;
|
|
82
|
-
* };
|
|
83
|
-
*
|
|
84
|
-
* cli.addCommand({
|
|
85
|
-
* name: "build",
|
|
86
|
-
* options: [
|
|
87
|
-
* { name: "output", type: String, alias: "o" },
|
|
88
|
-
* { name: "production", type: Boolean },
|
|
89
|
-
* { name: "watch", type: Boolean }
|
|
90
|
-
* ],
|
|
91
|
-
* env: [
|
|
92
|
-
* { name: "API_KEY", type: String },
|
|
93
|
-
* { name: "DEBUG", type: Boolean }
|
|
94
|
-
* ],
|
|
95
|
-
* execute: ({ options, env }: Toolbox<Console, BuildOptions, BuildEnv>) => {
|
|
96
|
-
* // Full autocomplete on options and env!
|
|
97
|
-
* console.log(options.output, options.production, env.apiKey);
|
|
98
|
-
* }
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export interface Command<O extends OptionDefinition<unknown> = OptionDefinition<unknown>, TLogger extends Console = Console, TContext extends IToolbox<TLogger> = IToolbox<TLogger>> {
|
|
103
|
-
/**
|
|
104
|
-
* @internal
|
|
105
|
-
*/
|
|
106
|
-
__conflictingOptions__?: PossibleOptionDefinition<O>[];
|
|
107
|
-
/**
|
|
108
|
-
* @internal
|
|
109
|
-
*/
|
|
110
|
-
__requiredOptions__?: PossibleOptionDefinition<O>[];
|
|
111
|
-
/** Potential other names for this command */
|
|
112
|
-
alias?: string[] | string;
|
|
113
|
-
/** Positional argument */
|
|
114
|
-
argument?: ArgumentDefinition;
|
|
115
|
-
/** The command path, an array that describes how to get to this command */
|
|
116
|
-
commandPath?: string[];
|
|
117
|
-
/** A tweet-sized summary of your command */
|
|
118
|
-
description?: string;
|
|
119
|
-
/** Environment variables supported by this command */
|
|
120
|
-
env?: (EnvDefinition<boolean> | EnvDefinition<number> | EnvDefinition<string>)[];
|
|
121
|
-
/** The full command examples, can be multiple lines */
|
|
122
|
-
examples?: string[] | string[][];
|
|
123
|
-
/** The function for running your command, can be async */
|
|
124
|
-
execute: ((toolbox: TContext) => Promise<void>) | ((toolbox: TContext) => void);
|
|
125
|
-
/** The path to the file name for this command. */
|
|
126
|
-
file?: string;
|
|
127
|
-
/** Group commands together under a heading */
|
|
128
|
-
group?: string;
|
|
129
|
-
/** Should your command be shown in the listings */
|
|
130
|
-
hidden?: boolean;
|
|
131
|
-
/** The name of your command */
|
|
132
|
-
name: string;
|
|
133
|
-
options?: (O | OptionDefinition<boolean[]> | OptionDefinition<boolean> | OptionDefinition<number[]> | OptionDefinition<number> | OptionDefinition<string[]> | OptionDefinition<string>)[];
|
|
134
|
-
usage?: Content[];
|
|
135
|
-
}
|
|
136
|
-
export {};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper types for creating type-safe commands with autocomplete support.
|
|
3
|
-
* These types help you define your options and environment variables with full TypeScript autocomplete.
|
|
4
|
-
* Use these types to create type-safe Toolbox interfaces for your commands.
|
|
5
|
-
* @example
|
|
6
|
-
* ```typescript
|
|
7
|
-
* import { CreateOptions, CreateEnv, type Toolbox } from '@visulima/cerebro';
|
|
8
|
-
*
|
|
9
|
-
* // Define options with their original names (they'll be converted to camelCase)
|
|
10
|
-
* type BuildOptions = CreateOptions<{
|
|
11
|
-
* "output-dir": string | undefined;
|
|
12
|
-
* "verbose": boolean | undefined;
|
|
13
|
-
* "port": number | undefined;
|
|
14
|
-
* }>;
|
|
15
|
-
* // Result: { outputDir: string | undefined, verbose: boolean | undefined, port: number | undefined }
|
|
16
|
-
*
|
|
17
|
-
* // Define environment variables (UPPER_SNAKE_CASE -> camelCase)
|
|
18
|
-
* type BuildEnv = CreateEnv<{
|
|
19
|
-
* "API_KEY": string | undefined;
|
|
20
|
-
* "DEBUG": boolean | undefined;
|
|
21
|
-
* }>;
|
|
22
|
-
* // Result: { apiKey: string | undefined, debug: boolean | undefined }
|
|
23
|
-
*
|
|
24
|
-
* // Use in your command
|
|
25
|
-
* cli.addCommand({
|
|
26
|
-
* name: "build",
|
|
27
|
-
* options: [
|
|
28
|
-
* { name: "output-dir", type: String },
|
|
29
|
-
* { name: "verbose", type: Boolean },
|
|
30
|
-
* { name: "port", type: Number }
|
|
31
|
-
* ],
|
|
32
|
-
* env: [
|
|
33
|
-
* { name: "API_KEY", type: String },
|
|
34
|
-
* { name: "DEBUG", type: Boolean }
|
|
35
|
-
* ],
|
|
36
|
-
* execute: ({ options, env }: Toolbox<Console, BuildOptions, BuildEnv>) => {
|
|
37
|
-
* // Full autocomplete on options.outputDir, options.verbose, env.apiKey, etc.
|
|
38
|
-
* console.log(options.outputDir, options.verbose, env.apiKey);
|
|
39
|
-
* }
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
/**
|
|
44
|
-
* Converts option names to camelCase for the options object.
|
|
45
|
-
* Options like "output-dir" become "outputDir" in the toolbox.
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* // Option name: "output-dir" -> options.outputDir
|
|
49
|
-
* // Option name: "api_key" -> options.apiKey
|
|
50
|
-
* // Option name: "verbose" -> options.verbose
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export type OptionNameToCamelCase<T extends string> = T extends `${infer Start}-${infer Rest}` ? `${Lowercase<Start>}${Capitalize<OptionNameToCamelCase<Rest>>}` : T extends `${infer Start}_${infer Rest}` ? `${Lowercase<Start>}${Capitalize<OptionNameToCamelCase<Rest>>}` : Lowercase<T>;
|
|
54
|
-
/**
|
|
55
|
-
* Helper type to create a type-safe options object from option definitions.
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* type MyOptions = CreateOptions<{
|
|
59
|
-
* "output-dir": string | undefined;
|
|
60
|
-
* "verbose": boolean | undefined;
|
|
61
|
-
* "port": number | undefined;
|
|
62
|
-
* }>;
|
|
63
|
-
* // Result: { outputDir: string | undefined, verbose: boolean | undefined, port: number | undefined }
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export type CreateOptions<T extends Record<string, unknown>> = {
|
|
67
|
-
[K in keyof T as OptionNameToCamelCase<K & string>]: T[K];
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Helper type to create a type-safe environment variables object from env definitions.
|
|
71
|
-
* Environment variable names are converted from UPPER_SNAKE_CASE to camelCase.
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* type MyEnv = CreateEnv<{
|
|
75
|
-
* "API_KEY": string | undefined;
|
|
76
|
-
* "DEBUG": boolean | undefined;
|
|
77
|
-
* }>;
|
|
78
|
-
* // Result: { apiKey: string | undefined, debug: boolean | undefined }
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
export type CreateEnv<T extends Record<string, unknown>> = {
|
|
82
|
-
[K in keyof T as OptionNameToCamelCase<K & string>]: T[K];
|
|
83
|
-
};
|
package/dist/types/options.d.ts
DELETED