@jakubmazanec/cli 0.2.1-unstable.f940d9d → 0.3.0-next.6fd9f2b
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 +1 -1
- package/build/constants.js +8 -0
- package/build/constants.js.map +7 -0
- package/build/main.js +4 -0
- package/build/main.js.map +7 -0
- package/{dist → build}/program/Command.d.ts +1 -1
- package/build/program/Command.js +70 -0
- package/build/program/Command.js.map +7 -0
- package/{dist → build}/program/CommandAction.d.ts +1 -1
- package/build/program/CommandAction.js +2 -0
- package/build/program/CommandAction.js.map +7 -0
- package/build/program/CommandArguments.js +2 -0
- package/build/program/CommandArguments.js.map +7 -0
- package/build/program/CommandOptions.js +2 -0
- package/build/program/CommandOptions.js.map +7 -0
- package/{dist → build}/program/Program.d.ts +1 -1
- package/build/program/Program.js +191 -0
- package/build/program/Program.js.map +7 -0
- package/build/program/ProgramCreateOptions.js +2 -0
- package/build/program/ProgramCreateOptions.js.map +7 -0
- package/build/program/ProgramDetail.js +2 -0
- package/build/program/ProgramDetail.js.map +7 -0
- package/{dist → build}/program/ProgramError.d.ts +1 -1
- package/build/program/ProgramError.js +6 -0
- package/build/program/ProgramError.js.map +7 -0
- package/build/program/ProgramOptions.js +2 -0
- package/build/program/ProgramOptions.js.map +7 -0
- package/build/program/ProgramStreams.js +2 -0
- package/build/program/ProgramStreams.js.map +7 -0
- package/build/program/getProgramDetail.js +25 -0
- package/build/program/getProgramDetail.js.map +7 -0
- package/build/program.js +13 -0
- package/build/program.js.map +7 -0
- package/build/ui/ErrorDetail.js +2 -0
- package/build/ui/ErrorDetail.js.map +7 -0
- package/build/ui/Failure.js +20 -0
- package/build/ui/Failure.js.map +7 -0
- package/build/ui/Header.js +19 -0
- package/build/ui/Header.js.map +7 -0
- package/build/ui/Help.js +38 -0
- package/build/ui/Help.js.map +7 -0
- package/build/ui/Spinner.js +24 -0
- package/build/ui/Spinner.js.map +7 -0
- package/build/ui/colors.js +12 -0
- package/build/ui/colors.js.map +7 -0
- package/build/ui/form/Form.js +2 -0
- package/build/ui/form/Form.js.map +7 -0
- package/build/ui/form/FormConfig.js +2 -0
- package/build/ui/form/FormConfig.js.map +7 -0
- package/build/ui/form/FormProps.js +2 -0
- package/build/ui/form/FormProps.js.map +7 -0
- package/build/ui/form/FormResult.js +2 -0
- package/build/ui/form/FormResult.js.map +7 -0
- package/build/ui/form/FormRow.js +71 -0
- package/build/ui/form/FormRow.js.map +7 -0
- package/build/ui/form/FormRowConfig.js +2 -0
- package/build/ui/form/FormRowConfig.js.map +7 -0
- package/build/ui/form/FormRowsConfig.js +2 -0
- package/build/ui/form/FormRowsConfig.js.map +7 -0
- package/build/ui/form/FormValue.js +2 -0
- package/build/ui/form/FormValue.js.map +7 -0
- package/build/ui/form/FormValues.js +2 -0
- package/build/ui/form/FormValues.js.map +7 -0
- package/{dist → build}/ui/form/SelectInput.d.ts +1 -1
- package/build/ui/form/SelectInput.js +86 -0
- package/build/ui/form/SelectInput.js.map +7 -0
- package/build/ui/form/SelectInputItem.js +2 -0
- package/build/ui/form/SelectInputItem.js.map +7 -0
- package/build/ui/form/TextInput.js +129 -0
- package/build/ui/form/TextInput.js.map +7 -0
- package/build/ui/form/createForm.js +73 -0
- package/build/ui/form/createForm.js.map +7 -0
- package/build/ui/form.js +15 -0
- package/build/ui/form.js.map +7 -0
- package/build/ui/getErrorDetail.js +65 -0
- package/build/ui/getErrorDetail.js.map +7 -0
- package/build/ui/icons.js +13 -0
- package/build/ui/icons.js.map +7 -0
- package/build/ui/internals/Wrapper.js +48 -0
- package/build/ui/internals/Wrapper.js.map +7 -0
- package/build/ui/internals/programContext.js +4 -0
- package/build/ui/internals/programContext.js.map +7 -0
- package/build/ui/internals/rotate.js +6 -0
- package/build/ui/internals/rotate.js.map +7 -0
- package/build/ui/internals.js +5 -0
- package/build/ui/internals.js.map +7 -0
- package/build/ui/useProgram.js +20 -0
- package/build/ui/useProgram.js.map +7 -0
- package/build/ui.js +12 -0
- package/build/ui.js.map +7 -0
- package/package.json +37 -32
- package/{src → source}/program/CommandAction.ts +1 -1
- package/{src → source}/program/Program.ts +4 -4
- package/{src → source}/ui/Failure.tsx +9 -9
- package/{src → source}/ui/Header.tsx +8 -4
- package/{src → source}/ui/Help.tsx +4 -4
- package/{src → source}/ui/Spinner.tsx +1 -1
- package/{src → source}/ui/form/FormProps.ts +12 -18
- package/{src → source}/ui/form/FormRow.tsx +9 -9
- package/{src → source}/ui/form/FormValue.ts +3 -4
- package/{src → source}/ui/form/SelectInput.tsx +11 -15
- package/{src → source}/ui/form/TextInput.tsx +13 -10
- package/{src → source}/ui/getErrorDetail.ts +1 -1
- package/{src → source}/ui/internals/Wrapper.tsx +4 -4
- package/dist/constants.js +0 -8
- package/dist/constants.js.map +0 -1
- package/dist/main.js +0 -4
- package/dist/main.js.map +0 -1
- package/dist/program/Command.js +0 -63
- package/dist/program/Command.js.map +0 -1
- package/dist/program/CommandAction.js +0 -3
- package/dist/program/CommandAction.js.map +0 -1
- package/dist/program/CommandArguments.js +0 -3
- package/dist/program/CommandArguments.js.map +0 -1
- package/dist/program/CommandOptions.js +0 -3
- package/dist/program/CommandOptions.js.map +0 -1
- package/dist/program/Program.js +0 -168
- package/dist/program/Program.js.map +0 -1
- package/dist/program/ProgramCreateOptions.js +0 -3
- package/dist/program/ProgramCreateOptions.js.map +0 -1
- package/dist/program/ProgramDetail.js +0 -5
- package/dist/program/ProgramDetail.js.map +0 -1
- package/dist/program/ProgramError.js +0 -8
- package/dist/program/ProgramError.js.map +0 -1
- package/dist/program/ProgramOptions.js +0 -3
- package/dist/program/ProgramOptions.js.map +0 -1
- package/dist/program/ProgramStreams.js +0 -5
- package/dist/program/ProgramStreams.js.map +0 -1
- package/dist/program/getProgramDetail.js +0 -27
- package/dist/program/getProgramDetail.js.map +0 -1
- package/dist/program.js +0 -13
- package/dist/program.js.map +0 -1
- package/dist/ui/ErrorDetail.js +0 -5
- package/dist/ui/ErrorDetail.js.map +0 -1
- package/dist/ui/Failure.js +0 -65
- package/dist/ui/Failure.js.map +0 -1
- package/dist/ui/Header.js +0 -26
- package/dist/ui/Header.js.map +0 -1
- package/dist/ui/Help.js +0 -64
- package/dist/ui/Help.js.map +0 -1
- package/dist/ui/Spinner.js +0 -39
- package/dist/ui/Spinner.js.map +0 -1
- package/dist/ui/colors.js +0 -12
- package/dist/ui/colors.js.map +0 -1
- package/dist/ui/form/Form.js +0 -3
- package/dist/ui/form/Form.js.map +0 -1
- package/dist/ui/form/FormConfig.js +0 -3
- package/dist/ui/form/FormConfig.js.map +0 -1
- package/dist/ui/form/FormProps.js +0 -3
- package/dist/ui/form/FormProps.js.map +0 -1
- package/dist/ui/form/FormResult.js +0 -3
- package/dist/ui/form/FormResult.js.map +0 -1
- package/dist/ui/form/FormRow.js +0 -59
- package/dist/ui/form/FormRow.js.map +0 -1
- package/dist/ui/form/FormRowConfig.js +0 -5
- package/dist/ui/form/FormRowConfig.js.map +0 -1
- package/dist/ui/form/FormRowsConfig.js +0 -3
- package/dist/ui/form/FormRowsConfig.js.map +0 -1
- package/dist/ui/form/FormValue.js +0 -3
- package/dist/ui/form/FormValue.js.map +0 -1
- package/dist/ui/form/FormValues.js +0 -3
- package/dist/ui/form/FormValues.js.map +0 -1
- package/dist/ui/form/SelectInput.js +0 -113
- package/dist/ui/form/SelectInput.js.map +0 -1
- package/dist/ui/form/SelectInputItem.js +0 -5
- package/dist/ui/form/SelectInputItem.js.map +0 -1
- package/dist/ui/form/TextInput.js +0 -152
- package/dist/ui/form/TextInput.js.map +0 -1
- package/dist/ui/form/createForm.js +0 -72
- package/dist/ui/form/createForm.js.map +0 -1
- package/dist/ui/form.js +0 -15
- package/dist/ui/form.js.map +0 -1
- package/dist/ui/getErrorDetail.js +0 -72
- package/dist/ui/getErrorDetail.js.map +0 -1
- package/dist/ui/icons.js +0 -13
- package/dist/ui/icons.js.map +0 -1
- package/dist/ui/internals/Wrapper.js +0 -66
- package/dist/ui/internals/Wrapper.js.map +0 -1
- package/dist/ui/internals/programContext.js +0 -6
- package/dist/ui/internals/programContext.js.map +0 -1
- package/dist/ui/internals/rotate.js +0 -17
- package/dist/ui/internals/rotate.js.map +0 -1
- package/dist/ui/internals.js +0 -5
- package/dist/ui/internals.js.map +0 -1
- package/dist/ui/useProgram.js +0 -25
- package/dist/ui/useProgram.js.map +0 -1
- package/dist/ui.js +0 -12
- package/dist/ui.js.map +0 -1
- package/{dist → build}/constants.d.ts +0 -0
- package/{dist → build}/main.d.ts +0 -0
- package/{dist → build}/program/CommandArguments.d.ts +0 -0
- package/{dist → build}/program/CommandOptions.d.ts +0 -0
- package/{dist → build}/program/ProgramCreateOptions.d.ts +0 -0
- package/{dist → build}/program/ProgramDetail.d.ts +0 -0
- package/{dist → build}/program/ProgramOptions.d.ts +0 -0
- package/{dist → build}/program/ProgramStreams.d.ts +0 -0
- package/{dist → build}/program/getProgramDetail.d.ts +0 -0
- package/{dist → build}/program.d.ts +0 -0
- package/{dist → build}/ui/ErrorDetail.d.ts +0 -0
- package/{dist → build}/ui/Failure.d.ts +0 -0
- package/{dist → build}/ui/Header.d.ts +0 -0
- package/{dist → build}/ui/Help.d.ts +0 -0
- package/{dist → build}/ui/Spinner.d.ts +0 -0
- package/{dist → build}/ui/colors.d.ts +0 -0
- package/{dist → build}/ui/form/Form.d.ts +0 -0
- package/{dist → build}/ui/form/FormConfig.d.ts +0 -0
- package/{dist → build}/ui/form/FormProps.d.ts +0 -0
- package/{dist → build}/ui/form/FormResult.d.ts +0 -0
- package/{dist → build}/ui/form/FormRow.d.ts +0 -0
- package/{dist → build}/ui/form/FormRowConfig.d.ts +0 -0
- package/{dist → build}/ui/form/FormRowsConfig.d.ts +0 -0
- package/{dist → build}/ui/form/FormValue.d.ts +0 -0
- package/{dist → build}/ui/form/FormValues.d.ts +0 -0
- package/{dist → build}/ui/form/SelectInputItem.d.ts +0 -0
- package/{dist → build}/ui/form/TextInput.d.ts +0 -0
- package/{dist → build}/ui/form/createForm.d.ts +0 -0
- package/{dist → build}/ui/form.d.ts +3 -3
- package/{dist → build}/ui/getErrorDetail.d.ts +0 -0
- package/{dist → build}/ui/icons.d.ts +0 -0
- package/{dist → build}/ui/internals/Wrapper.d.ts +0 -0
- package/{dist → build}/ui/internals/programContext.d.ts +0 -0
- package/{dist → build}/ui/internals/rotate.d.ts +0 -0
- package/{dist → build}/ui/internals.d.ts +0 -0
- package/{dist → build}/ui/useProgram.d.ts +0 -0
- package/{dist → build}/ui.d.ts +3 -3
- package/{src → source}/constants.ts +0 -0
- package/{src → source}/main.ts +0 -0
- package/{src → source}/program/Command.ts +2 -2
- package/{src → source}/program/CommandArguments.ts +0 -0
- package/{src → source}/program/CommandOptions.ts +0 -0
- package/{src → source}/program/ProgramCreateOptions.ts +0 -0
- package/{src → source}/program/ProgramDetail.ts +0 -0
- package/{src → source}/program/ProgramError.ts +0 -0
- package/{src → source}/program/ProgramOptions.ts +0 -0
- package/{src → source}/program/ProgramStreams.ts +0 -0
- package/{src → source}/program/getProgramDetail.ts +0 -0
- package/{src → source}/program.ts +0 -0
- package/{src → source}/ui/ErrorDetail.ts +0 -0
- package/{src → source}/ui/colors.ts +0 -0
- package/{src → source}/ui/form/Form.ts +0 -0
- package/{src → source}/ui/form/FormConfig.ts +0 -0
- package/{src → source}/ui/form/FormResult.ts +0 -0
- package/{src → source}/ui/form/FormRowConfig.ts +0 -0
- package/{src → source}/ui/form/FormRowsConfig.ts +0 -0
- package/{src → source}/ui/form/FormValues.ts +0 -0
- package/{src → source}/ui/form/SelectInputItem.ts +0 -0
- package/{src → source}/ui/form/createForm.tsx +0 -0
- package/{src → source}/ui/form.ts +3 -3
- package/{src → source}/ui/icons.ts +0 -0
- package/{src → source}/ui/internals/programContext.ts +0 -0
- package/{src → source}/ui/internals/rotate.ts +0 -0
- package/{src → source}/ui/internals.ts +0 -0
- package/{src → source}/ui/useProgram.ts +0 -0
- package/{src → source}/ui.ts +3 -3
package/README.md
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import url from "node:url";
|
|
4
|
+
let directory = path.dirname(url.fileURLToPath(import.meta.url));
|
|
5
|
+
export const PACKAGE_PATH = path.resolve(directory, "..");
|
|
6
|
+
export const CACHE_PATH = path.resolve(PACKAGE_PATH, "node_modules/.cache");
|
|
7
|
+
export const DELIMITER = "$ ";
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../source/constants.ts"],
|
|
4
|
+
"sourcesContent": ["import path from 'node:path';\nimport url from 'node:url';\n\nlet directory = path.dirname(url.fileURLToPath(import.meta.url));\n\nexport const PACKAGE_PATH = path.resolve(directory, '..');\nexport const CACHE_PATH = path.resolve(PACKAGE_PATH, 'node_modules/.cache');\n\nexport const DELIMITER = '$ ';\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB,OAAO,SAAS;AAEhB,IAAI,YAAY,KAAK,QAAQ,IAAI,cAAc,YAAY,GAAG,CAAC;AAExD,aAAM,eAAe,KAAK,QAAQ,WAAW,IAAI;AACjD,aAAM,aAAa,KAAK,QAAQ,cAAc,qBAAqB;AAEnE,aAAM,YAAY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/main.js
ADDED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Arguments, type Argv, type OptionsConfig, type ParametersConfig } from '@jakubmazanec/args';
|
|
2
2
|
import { type CommandAction } from './CommandAction.js';
|
|
3
3
|
import { type CommandOptions } from './CommandOptions.js';
|
|
4
4
|
import { type Program } from './Program.js';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import {
|
|
3
|
+
parseArguments
|
|
4
|
+
} from "@jakubmazanec/args";
|
|
5
|
+
export class Command {
|
|
6
|
+
name;
|
|
7
|
+
description;
|
|
8
|
+
parameters;
|
|
9
|
+
options;
|
|
10
|
+
allowUnknownOptions;
|
|
11
|
+
allowUnknownParameters;
|
|
12
|
+
action;
|
|
13
|
+
/**
|
|
14
|
+
* @param name Command name, ie. space-separated words consisting only of letters, numbers (but not at the start of the word) or dashes.
|
|
15
|
+
* @param action Function that runs when command is executed.
|
|
16
|
+
* @param options Additionl command options.
|
|
17
|
+
*/
|
|
18
|
+
constructor(name, action, {
|
|
19
|
+
description,
|
|
20
|
+
parameters,
|
|
21
|
+
options,
|
|
22
|
+
allowUnknownOptions,
|
|
23
|
+
allowUnknownParameters
|
|
24
|
+
}) {
|
|
25
|
+
this.name = name;
|
|
26
|
+
this.action = action;
|
|
27
|
+
if (description) {
|
|
28
|
+
this.description = description;
|
|
29
|
+
}
|
|
30
|
+
if (parameters) {
|
|
31
|
+
this.parameters = parameters;
|
|
32
|
+
} else {
|
|
33
|
+
this.parameters = null;
|
|
34
|
+
}
|
|
35
|
+
if (options) {
|
|
36
|
+
this.options = options;
|
|
37
|
+
} else {
|
|
38
|
+
this.options = null;
|
|
39
|
+
}
|
|
40
|
+
if (allowUnknownOptions) {
|
|
41
|
+
this.allowUnknownOptions = allowUnknownOptions;
|
|
42
|
+
} else {
|
|
43
|
+
this.allowUnknownOptions = false;
|
|
44
|
+
}
|
|
45
|
+
if (allowUnknownParameters) {
|
|
46
|
+
this.allowUnknownParameters = allowUnknownParameters;
|
|
47
|
+
} else {
|
|
48
|
+
this.allowUnknownParameters = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parses a list of command line arguments into an arguments object. Parser is pre-configured based on this command.
|
|
53
|
+
*/
|
|
54
|
+
parseArguments(argv) {
|
|
55
|
+
return parseArguments(argv, {
|
|
56
|
+
commands: [this.name],
|
|
57
|
+
parameters: this.parameters ?? void 0,
|
|
58
|
+
options: this.options ?? void 0,
|
|
59
|
+
allowUnknownOptions: this.allowUnknownOptions,
|
|
60
|
+
allowUnknownParameters: this.allowUnknownParameters
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Executes command action with provided parsed arguments and {@link Program} instance.
|
|
65
|
+
*/
|
|
66
|
+
async run(parsedArgs, program) {
|
|
67
|
+
await this.action(parsedArgs, program);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=Command.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/program/Command.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n type Arguments,\n type Argv,\n type OptionsConfig,\n type ParametersConfig,\n parseArguments,\n} from '@jakubmazanec/args';\n\nimport {type CommandAction} from './CommandAction.js';\nimport {type CommandOptions} from './CommandOptions.js';\nimport {type Program} from './Program.js';\n\n/**\n * Command encapsulates piece of a CLI's logic and is executed when {@link Program} instance parses that command from the command line arguments.\n */\nexport class Command<\n A extends string,\n const B extends ParametersConfig | undefined = undefined,\n const C extends OptionsConfig | undefined = undefined,\n D extends boolean = false,\n E extends boolean = false,\n> {\n readonly name: A;\n readonly description?: string;\n readonly parameters: B extends ParametersConfig ? B : null;\n readonly options: C extends OptionsConfig ? C : null;\n readonly allowUnknownOptions: D;\n readonly allowUnknownParameters: E;\n private readonly action: CommandAction<A, B, C, D, E>;\n\n /**\n * @param name Command name, ie. space-separated words consisting only of letters, numbers (but not at the start of the word) or dashes.\n * @param action Function that runs when command is executed.\n * @param options Additionl command options.\n */\n constructor(\n name: A,\n action: CommandAction<A, B, C, D, E>,\n {\n description,\n parameters,\n options,\n allowUnknownOptions,\n allowUnknownParameters,\n }: CommandOptions<NonNullable<B>, NonNullable<C>, D, E>,\n ) {\n this.name = name;\n this.action = action;\n\n if (description) {\n this.description = description;\n }\n\n if (parameters) {\n this.parameters = parameters as B extends ParametersConfig ? B : null;\n } else {\n this.parameters = null as B extends ParametersConfig ? B : null;\n }\n\n if (options) {\n this.options = options as C extends OptionsConfig ? C : null;\n } else {\n this.options = null as C extends OptionsConfig ? C : null;\n }\n\n if (allowUnknownOptions) {\n this.allowUnknownOptions = allowUnknownOptions;\n } else {\n this.allowUnknownOptions = false as D;\n }\n\n if (allowUnknownParameters) {\n this.allowUnknownParameters = allowUnknownParameters;\n } else {\n this.allowUnknownParameters = false as E;\n }\n }\n\n /**\n * Parses a list of command line arguments into an arguments object. Parser is pre-configured based on this command.\n */\n parseArguments(argv: Argv): Arguments<{\n commands: readonly [A];\n parameters: B;\n options: C;\n allowUnknownOptions: D;\n allowUnknownParameters: E;\n }> {\n return parseArguments(argv, {\n commands: [this.name],\n parameters: this.parameters ?? undefined,\n options: this.options ?? undefined,\n allowUnknownOptions: this.allowUnknownOptions,\n allowUnknownParameters: this.allowUnknownParameters,\n } as {\n commands: readonly [A];\n parameters: B;\n options: C;\n allowUnknownOptions: D;\n allowUnknownParameters: E;\n });\n }\n\n /**\n * Executes command action with provided parsed arguments and {@link Program} instance.\n */\n async run(\n parsedArgs: Arguments<{\n commands: readonly [A];\n parameters: B;\n options: C;\n allowUnknownOptions: D;\n allowUnknownParameters: E;\n }>,\n program: Program,\n ): Promise<void> {\n await this.action(parsedArgs, program);\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EAKE;AAAA,OACK;AASA,aAAM,QAMX;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjB,YACE,MACA,QACA;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GACA;AACA,SAAK,OAAO;AACZ,SAAK,SAAS;AAEd,QAAI,aAAa;AACf,WAAK,cAAc;AAAA,IACrB;AAEA,QAAI,YAAY;AACd,WAAK,aAAa;AAAA,IACpB,OAAO;AACL,WAAK,aAAa;AAAA,IACpB;AAEA,QAAI,SAAS;AACX,WAAK,UAAU;AAAA,IACjB,OAAO;AACL,WAAK,UAAU;AAAA,IACjB;AAEA,QAAI,qBAAqB;AACvB,WAAK,sBAAsB;AAAA,IAC7B,OAAO;AACL,WAAK,sBAAsB;AAAA,IAC7B;AAEA,QAAI,wBAAwB;AAC1B,WAAK,yBAAyB;AAAA,IAChC,OAAO;AACL,WAAK,yBAAyB;AAAA,IAChC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,eAAe,MAMZ;AACD,WAAO,eAAe,MAAM;AAAA,MAC1B,UAAU,CAAC,KAAK,IAAI;AAAA,MACpB,YAAY,KAAK,cAAc;AAAA,MAC/B,SAAS,KAAK,WAAW;AAAA,MACzB,qBAAqB,KAAK;AAAA,MAC1B,wBAAwB,KAAK;AAAA,IAC/B,CAMC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,IACJ,YAOA,SACe;AACf,UAAM,KAAK,OAAO,YAAY,OAAO;AAAA,EACvC;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Argv, type OptionsConfig, type ParametersConfig } from '@jakubmazanec/args';
|
|
2
2
|
import { type ComponentType } from 'react';
|
|
3
3
|
import { type FallbackProps } from 'react-error-boundary';
|
|
4
4
|
import { type Command } from './Command.js';
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import fetchLatestVersion from "latest-version";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { CACHE_PATH } from "../constants.js";
|
|
6
|
+
import { Failure, Help } from "../ui.js";
|
|
7
|
+
import { Wrapper } from "../ui/internals.js";
|
|
8
|
+
import { ProgramError } from "./ProgramError.js";
|
|
9
|
+
export class Program {
|
|
10
|
+
/** Program name. */
|
|
11
|
+
name;
|
|
12
|
+
/** More readable program name. */
|
|
13
|
+
displayName;
|
|
14
|
+
/** Program version. */
|
|
15
|
+
version;
|
|
16
|
+
/** Program latest version. */
|
|
17
|
+
latestVersion;
|
|
18
|
+
/** Program description. */
|
|
19
|
+
description;
|
|
20
|
+
/** Program executable name. */
|
|
21
|
+
bin;
|
|
22
|
+
/** Program commands */
|
|
23
|
+
commands = [];
|
|
24
|
+
isRendering = false;
|
|
25
|
+
streams = {
|
|
26
|
+
stderr: process.stderr,
|
|
27
|
+
stdin: process.stdin,
|
|
28
|
+
stdout: process.stdout
|
|
29
|
+
};
|
|
30
|
+
/** Custom error boundary fallback component */
|
|
31
|
+
ErrorBoundaryFallbackComponent;
|
|
32
|
+
constructor({
|
|
33
|
+
name,
|
|
34
|
+
displayName,
|
|
35
|
+
version,
|
|
36
|
+
latestVersion,
|
|
37
|
+
description,
|
|
38
|
+
bin,
|
|
39
|
+
ErrorBoundaryFallbackComponent
|
|
40
|
+
}) {
|
|
41
|
+
if (name) {
|
|
42
|
+
this.name = name;
|
|
43
|
+
}
|
|
44
|
+
if (displayName) {
|
|
45
|
+
this.displayName = displayName;
|
|
46
|
+
}
|
|
47
|
+
if (version) {
|
|
48
|
+
this.version = version;
|
|
49
|
+
}
|
|
50
|
+
if (latestVersion) {
|
|
51
|
+
this.latestVersion = latestVersion;
|
|
52
|
+
}
|
|
53
|
+
if (description) {
|
|
54
|
+
this.description = description;
|
|
55
|
+
}
|
|
56
|
+
if (bin) {
|
|
57
|
+
this.bin = bin;
|
|
58
|
+
}
|
|
59
|
+
if (ErrorBoundaryFallbackComponent) {
|
|
60
|
+
this.ErrorBoundaryFallbackComponent = ErrorBoundaryFallbackComponent;
|
|
61
|
+
} else {
|
|
62
|
+
this.ErrorBoundaryFallbackComponent = Failure;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
static async create({
|
|
66
|
+
name,
|
|
67
|
+
version,
|
|
68
|
+
description,
|
|
69
|
+
bin,
|
|
70
|
+
ErrorBoundaryFallbackComponent,
|
|
71
|
+
checkForUpdate
|
|
72
|
+
}) {
|
|
73
|
+
let latestVersion;
|
|
74
|
+
if (checkForUpdate && name) {
|
|
75
|
+
let cachePath = path.join(CACHE_PATH, name, "latest-version.json");
|
|
76
|
+
let cachedLatestVersion;
|
|
77
|
+
try {
|
|
78
|
+
cachedLatestVersion = await fs.readJson(cachePath);
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
if (!cachedLatestVersion || Date.now() - cachedLatestVersion.datetime > 864e4) {
|
|
82
|
+
latestVersion = await fetchLatestVersion(name);
|
|
83
|
+
await fs.ensureFile(cachePath);
|
|
84
|
+
await fs.writeJson(cachePath, {
|
|
85
|
+
value: latestVersion,
|
|
86
|
+
datetime: Date.now()
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return new this({
|
|
91
|
+
name,
|
|
92
|
+
version,
|
|
93
|
+
latestVersion,
|
|
94
|
+
description,
|
|
95
|
+
bin,
|
|
96
|
+
ErrorBoundaryFallbackComponent
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Adds command to the program.
|
|
101
|
+
*
|
|
102
|
+
* @param command Command to add.
|
|
103
|
+
* @returns Program instance.
|
|
104
|
+
*/
|
|
105
|
+
addCommand(command) {
|
|
106
|
+
this.commands.push(command);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Renders a React element using Ink and outputs to the configured streams.
|
|
111
|
+
*
|
|
112
|
+
* @param element The React element to render.
|
|
113
|
+
*/
|
|
114
|
+
async renderElement(element) {
|
|
115
|
+
if (this.isRendering) {
|
|
116
|
+
throw new ProgramError("NO_NESTED_RENDER");
|
|
117
|
+
} else {
|
|
118
|
+
this.isRendering = true;
|
|
119
|
+
}
|
|
120
|
+
let { render } = await import("ink");
|
|
121
|
+
let { createElement } = await import("react");
|
|
122
|
+
let { stdin, stdout, stderr } = this.streams;
|
|
123
|
+
try {
|
|
124
|
+
render(createElement(Wrapper, { program: this }, element), {
|
|
125
|
+
exitOnCtrlC: true,
|
|
126
|
+
patchConsole: true,
|
|
127
|
+
stderr,
|
|
128
|
+
stdin,
|
|
129
|
+
stdout
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof Error) {
|
|
133
|
+
await this.renderElement(
|
|
134
|
+
createElement(this.ErrorBoundaryFallbackComponent, { error, resetErrorBoundary: () => {
|
|
135
|
+
} })
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
} finally {
|
|
139
|
+
this.isRendering = false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Runs the program.
|
|
144
|
+
*
|
|
145
|
+
* @param argv Unparsed command line arguments.
|
|
146
|
+
*/
|
|
147
|
+
async run(argv) {
|
|
148
|
+
let hasCommandRun = false;
|
|
149
|
+
for (let command of this.commands) {
|
|
150
|
+
let parsedArgs = command.parseArguments(argv);
|
|
151
|
+
if (parsedArgs.command) {
|
|
152
|
+
hasCommandRun = true;
|
|
153
|
+
if (parsedArgs.errors.length) {
|
|
154
|
+
let { createElement } = await import("react");
|
|
155
|
+
for (let error of parsedArgs.errors) {
|
|
156
|
+
process.exitCode = 1;
|
|
157
|
+
await this.renderElement(
|
|
158
|
+
createElement(this.ErrorBoundaryFallbackComponent, {
|
|
159
|
+
error,
|
|
160
|
+
resetErrorBoundary: () => {
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
try {
|
|
167
|
+
await command.run(parsedArgs, this);
|
|
168
|
+
} catch (error) {
|
|
169
|
+
let { createElement } = await import("react");
|
|
170
|
+
if (error instanceof Error) {
|
|
171
|
+
process.exitCode = 1;
|
|
172
|
+
await this.renderElement(
|
|
173
|
+
createElement(this.ErrorBoundaryFallbackComponent, {
|
|
174
|
+
error,
|
|
175
|
+
resetErrorBoundary: () => {
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!hasCommandRun) {
|
|
186
|
+
let { createElement } = await import("react");
|
|
187
|
+
await this.renderElement(createElement(Help, { program: this }));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=Program.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/program/Program.ts"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any -- needed */\nimport {type Argv, type OptionsConfig, type ParametersConfig} from '@jakubmazanec/args';\nimport fs from 'fs-extra';\nimport fetchLatestVersion from 'latest-version';\nimport path from 'path';\nimport {type ComponentType} from 'react';\nimport {type FallbackProps} from 'react-error-boundary';\n\nimport {CACHE_PATH} from '../constants.js';\nimport {Failure, Help} from '../ui.js';\nimport {Wrapper} from '../ui/internals.js';\nimport {type Command} from './Command.js';\nimport {type ProgramCreateOptions} from './ProgramCreateOptions.js';\nimport {ProgramError} from './ProgramError.js';\nimport {type ProgramOptions} from './ProgramOptions.js';\nimport {type ProgramStreams} from './ProgramStreams.js';\n\n/**\n * Program manages and executes {@link Command} instances attached to it based on parsing command line arguments.\n */\nexport class Program {\n /** Program name. */\n readonly name?: string;\n\n /** More readable program name. */\n readonly displayName?: string;\n\n /** Program version. */\n readonly version?: string;\n\n /** Program latest version. */\n readonly latestVersion?: string;\n\n /** Program description. */\n readonly description?: string;\n\n /** Program executable name. */\n readonly bin?: string;\n\n /** Program commands */\n readonly commands: Array<\n Command<string, ParametersConfig | undefined, OptionsConfig | undefined, boolean, boolean>\n > = [];\n\n protected isRendering = false;\n\n readonly streams: ProgramStreams = {\n stderr: process.stderr,\n stdin: process.stdin,\n stdout: process.stdout,\n };\n\n /** Custom error boundary fallback component */\n ErrorBoundaryFallbackComponent: ComponentType<FallbackProps>;\n\n private constructor({\n name,\n displayName,\n version,\n latestVersion,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n }: ProgramOptions) {\n if (name) {\n this.name = name;\n }\n\n if (displayName) {\n this.displayName = displayName;\n }\n\n if (version) {\n this.version = version;\n }\n\n if (latestVersion) {\n this.latestVersion = latestVersion;\n }\n\n if (description) {\n this.description = description;\n }\n\n if (bin) {\n this.bin = bin;\n }\n\n if (ErrorBoundaryFallbackComponent) {\n this.ErrorBoundaryFallbackComponent = ErrorBoundaryFallbackComponent;\n } else {\n this.ErrorBoundaryFallbackComponent = Failure;\n }\n }\n\n static async create({\n name,\n version,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n checkForUpdate,\n }: ProgramCreateOptions) {\n let latestVersion: string | undefined;\n\n if (checkForUpdate && name) {\n // first we try to read the cached latest version\n type CachedLatestVersion = {\n value: string;\n datetime: number;\n };\n\n let cachePath = path.join(CACHE_PATH, name, 'latest-version.json');\n let cachedLatestVersion: CachedLatestVersion | undefined;\n\n try {\n cachedLatestVersion = (await fs.readJson(cachePath)) as CachedLatestVersion;\n } catch {\n // no-op\n }\n\n // if there is no cache or the cached value is old, refetch and recache\n if (!cachedLatestVersion || Date.now() - cachedLatestVersion.datetime > 86_400_00) {\n latestVersion = await fetchLatestVersion(name);\n\n await fs.ensureFile(cachePath);\n await fs.writeJson(cachePath, {\n value: latestVersion,\n datetime: Date.now(),\n });\n }\n }\n\n return new this({\n name,\n version,\n latestVersion,\n description,\n bin,\n ErrorBoundaryFallbackComponent,\n });\n }\n\n /**\n * Adds command to the program.\n *\n * @param command Command to add.\n * @returns Program instance.\n */\n addCommand(command: Command<any, any, any, any, any>): this {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- it doesn't matter here; `any` is used to make TypeScript happy in this method, but isn't propagated further.\n this.commands.push(command);\n\n return this;\n }\n\n /**\n * Renders a React element using Ink and outputs to the configured streams.\n *\n * @param element The React element to render.\n */\n async renderElement(element: React.ReactElement): Promise<void> {\n if (this.isRendering) {\n throw new ProgramError('NO_NESTED_RENDER');\n } else {\n this.isRendering = true;\n }\n\n let {render} = await import('ink');\n let {createElement} = await import('react');\n let {stdin, stdout, stderr} = this.streams;\n\n try {\n render(createElement(Wrapper, {program: this}, element), {\n exitOnCtrlC: true,\n patchConsole: true,\n stderr,\n stdin,\n stdout,\n });\n } catch (error: unknown) {\n if (error instanceof Error) {\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {error, resetErrorBoundary: () => {}}),\n );\n }\n } finally {\n this.isRendering = false;\n }\n }\n\n /**\n * Runs the program.\n *\n * @param argv Unparsed command line arguments.\n */\n async run(argv: Argv): Promise<void> {\n let hasCommandRun = false;\n\n for (let command of this.commands) {\n let parsedArgs = command.parseArguments(argv);\n\n if (parsedArgs.command) {\n hasCommandRun = true;\n\n if (parsedArgs.errors.length) {\n let {createElement} = await import('react');\n\n for (let error of parsedArgs.errors) {\n process.exitCode = 1;\n\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {\n error,\n resetErrorBoundary: () => {},\n }),\n );\n }\n } else {\n try {\n await command.run(parsedArgs, this);\n } catch (error: unknown) {\n let {createElement} = await import('react');\n\n if (error instanceof Error) {\n process.exitCode = 1;\n\n await this.renderElement(\n createElement(this.ErrorBoundaryFallbackComponent, {\n error,\n resetErrorBoundary: () => {},\n }),\n );\n }\n }\n\n break;\n }\n }\n }\n\n if (!hasCommandRun) {\n let {createElement} = await import('react');\n\n await this.renderElement(createElement(Help, {program: this}));\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A subclass of `Error` that indicates a program failure.
|
|
3
3
|
*/
|
|
4
|
-
export declare const ProgramError: new (code: "NO_NESTED_RENDER", options?: import("@jakubmazanec/error").CustomErrorOptions | undefined) => import("@jakubmazanec/error").CustomError<"
|
|
4
|
+
export declare const ProgramError: new (code: "NO_NESTED_RENDER", options?: import("@jakubmazanec/error").CustomErrorOptions | undefined) => import("@jakubmazanec/error").CustomError<"UNKNOWN_ERROR" | "NO_NESTED_RENDER">;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { createCustomError } from "@jakubmazanec/error";
|
|
3
|
+
export const ProgramError = createCustomError("ProgramError", {
|
|
4
|
+
NO_NESTED_RENDER: "A React render process already exists. This usually occurs by triggering nested render calls."
|
|
5
|
+
});
|
|
6
|
+
//# sourceMappingURL=ProgramError.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/program/ProgramError.ts"],
|
|
4
|
+
"sourcesContent": ["import {createCustomError} from '@jakubmazanec/error';\n\n/**\n * A subclass of `Error` that indicates a program failure.\n */\nexport const ProgramError = createCustomError('ProgramError', {\n NO_NESTED_RENDER:\n 'A React render process already exists. This usually occurs by triggering nested render calls.',\n});\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAQ,yBAAwB;AAKzB,aAAM,eAAe,kBAAkB,gBAAgB;AAAA,EAC5D,kBACE;AACJ,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export function getProgramDetail(packageJson) {
|
|
3
|
+
let programDetail = {};
|
|
4
|
+
if (packageJson.name) {
|
|
5
|
+
programDetail.name = packageJson.name;
|
|
6
|
+
}
|
|
7
|
+
if (packageJson.version) {
|
|
8
|
+
programDetail.version = packageJson.version;
|
|
9
|
+
}
|
|
10
|
+
if (packageJson.description) {
|
|
11
|
+
programDetail.description = packageJson.description;
|
|
12
|
+
}
|
|
13
|
+
if (packageJson.bin && typeof packageJson.bin !== "string") {
|
|
14
|
+
let bins = Object.entries(packageJson.bin);
|
|
15
|
+
if (bins.length === 1) {
|
|
16
|
+
let firstBin = bins[0];
|
|
17
|
+
[programDetail.bin] = firstBin;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (typeof packageJson.bin === "string" && packageJson.name) {
|
|
21
|
+
programDetail.bin = packageJson.name;
|
|
22
|
+
}
|
|
23
|
+
return programDetail;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=getProgramDetail.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/program/getProgramDetail.ts"],
|
|
4
|
+
"sourcesContent": ["import {type PackageJson} from '@jakubmazanec/zod-utils';\n\nimport {type ProgramDetail} from './ProgramDetail.js';\n\n/**\n * Creates detailed information about a {@lincode Program}.\n */\nexport function getProgramDetail(packageJson: PackageJson) {\n let programDetail: ProgramDetail = {};\n\n if (packageJson.name) {\n programDetail.name = packageJson.name;\n }\n\n if (packageJson.version) {\n programDetail.version = packageJson.version;\n }\n\n if (packageJson.description) {\n programDetail.description = packageJson.description;\n }\n\n if (packageJson.bin && typeof packageJson.bin !== 'string') {\n let bins = Object.entries(packageJson.bin);\n\n if (bins.length === 1) {\n let firstBin = bins[0] as [string, string];\n\n [programDetail.bin] = firstBin;\n }\n }\n\n if (typeof packageJson.bin === 'string' && packageJson.name) {\n programDetail.bin = packageJson.name;\n }\n\n return programDetail;\n}\n"],
|
|
5
|
+
"mappings": ";AAOO,gBAAS,iBAAiB,aAA0B;AACzD,MAAI,gBAA+B,CAAC;AAEpC,MAAI,YAAY,MAAM;AACpB,kBAAc,OAAO,YAAY;AAAA,EACnC;AAEA,MAAI,YAAY,SAAS;AACvB,kBAAc,UAAU,YAAY;AAAA,EACtC;AAEA,MAAI,YAAY,aAAa;AAC3B,kBAAc,cAAc,YAAY;AAAA,EAC1C;AAEA,MAAI,YAAY,OAAO,OAAO,YAAY,QAAQ,UAAU;AAC1D,QAAI,OAAO,OAAO,QAAQ,YAAY,GAAG;AAEzC,QAAI,KAAK,WAAW,GAAG;AACrB,UAAI,WAAW,KAAK,CAAC;AAErB,OAAC,cAAc,GAAG,IAAI;AAAA,IACxB;AAAA,EACF;AAEA,MAAI,OAAO,YAAY,QAAQ,YAAY,YAAY,MAAM;AAC3D,kBAAc,MAAM,YAAY;AAAA,EAClC;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/program.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export * from "./program/Command.js";
|
|
3
|
+
export * from "./program/CommandAction.js";
|
|
4
|
+
export * from "./program/CommandArguments.js";
|
|
5
|
+
export * from "./program/CommandOptions.js";
|
|
6
|
+
export * from "./program/getProgramDetail.js";
|
|
7
|
+
export * from "./program/Program.js";
|
|
8
|
+
export * from "./program/ProgramCreateOptions.js";
|
|
9
|
+
export * from "./program/ProgramDetail.js";
|
|
10
|
+
export * from "./program/ProgramError.js";
|
|
11
|
+
export * from "./program/ProgramOptions.js";
|
|
12
|
+
export * from "./program/ProgramStreams.js";
|
|
13
|
+
//# sourceMappingURL=program.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../source/program.ts"],
|
|
4
|
+
"sourcesContent": ["export * from './program/Command.js';\nexport * from './program/CommandAction.js';\nexport * from './program/CommandArguments.js';\nexport * from './program/CommandOptions.js';\nexport * from './program/getProgramDetail.js';\nexport * from './program/Program.js';\nexport * from './program/ProgramCreateOptions.js';\nexport * from './program/ProgramDetail.js';\nexport * from './program/ProgramError.js';\nexport * from './program/ProgramOptions.js';\nexport * from './program/ProgramStreams.js';\n"],
|
|
5
|
+
"mappings": ";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box, Text } from "ink";
|
|
4
|
+
import * as colors from "./colors.js";
|
|
5
|
+
import { getErrorDetail } from "./getErrorDetail.js";
|
|
6
|
+
import { Header } from "./Header.js";
|
|
7
|
+
import * as icons from "./icons.js";
|
|
8
|
+
export function Failure({ error, errorDetail, ...boxProps }) {
|
|
9
|
+
let { label, description, stack, cause } = errorDetail ?? getErrorDetail(error);
|
|
10
|
+
return /* @__PURE__ */ jsxs(Box, { ...boxProps, flexDirection: "column", children: [
|
|
11
|
+
/* @__PURE__ */ jsx(Header, { icon: icons.error, children: /* @__PURE__ */ jsx(Text, { color: colors.highlighted, children: label }) }),
|
|
12
|
+
description ? /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: colors.failure, children: description }) }) : null,
|
|
13
|
+
stack ? /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: colors.muted, children: stack }) }) : null,
|
|
14
|
+
cause ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
15
|
+
/* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: colors.muted, children: cause.description }) }),
|
|
16
|
+
cause.stack ? /* @__PURE__ */ jsx(Box, { flexDirection: "column", marginTop: 1, marginLeft: 2, children: /* @__PURE__ */ jsx(Text, { color: colors.muted, children: cause.stack }) }) : null
|
|
17
|
+
] }) : null
|
|
18
|
+
] });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=Failure.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/ui/Failure.tsx"],
|
|
4
|
+
"sourcesContent": ["import {Box, type BoxProps, Text} from 'ink';\n\nimport * as colors from './colors.js';\nimport {type ErrorDetail} from './ErrorDetail.js';\nimport {getErrorDetail} from './getErrorDetail.js';\nimport {Header} from './Header.js';\nimport * as icons from './icons.js';\n\n/**\n * {@link Failure} component props.\n */\nexport type FailureProps = BoxProps & {\n /** Error that describes a failure state. Function {@link getErrorDetail} is used for getting all the information from the error; you can use it to implement own retrieval logic and pass the result as `errorDetail` prop. */\n error: Error;\n\n /** Information about the failure state. Overrides information retireved from `error` prop. */\n errorDetail?: ErrorDetail;\n};\n\n/**\n * A component that renders a failure state.\n */\nexport function Failure({error, errorDetail, ...boxProps}: FailureProps) {\n let {label, description, stack, cause} = errorDetail ?? getErrorDetail(error);\n\n return (\n <Box {...boxProps} flexDirection=\"column\">\n <Header icon={icons.error}>\n <Text color={colors.highlighted}>{label}</Text>\n </Header>\n\n {description ?\n <Box flexDirection=\"column\" marginLeft={2}>\n <Text color={colors.failure}>{description}</Text>\n </Box>\n : null}\n\n {stack ?\n <Box flexDirection=\"column\" marginTop={1} marginLeft={2}>\n <Text color={colors.muted}>{stack}</Text>\n </Box>\n : null}\n\n {cause ?\n <>\n <Box flexDirection=\"column\" marginTop={1} marginLeft={2}>\n <Text color={colors.muted}>{cause.description}</Text>\n </Box>\n\n {cause.stack ?\n <Box flexDirection=\"column\" marginTop={1} marginLeft={2}>\n <Text color={colors.muted}>{cause.stack}</Text>\n </Box>\n : null}\n </>\n : null}\n </Box>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AA4BQ,SAgBA,UAhBA,KAgBA,YAhBA;AA5BR,SAAQ,KAAoB,YAAW;AAEvC,YAAY,YAAY;AAExB,SAAQ,sBAAqB;AAC7B,SAAQ,cAAa;AACrB,YAAY,WAAW;AAgBhB,gBAAS,QAAQ,EAAC,OAAO,aAAa,GAAG,SAAQ,GAAiB;AACvE,MAAI,EAAC,OAAO,aAAa,OAAO,MAAK,IAAI,eAAe,eAAe,KAAK;AAE5E,SACE,qBAAC,OAAK,GAAG,UAAU,eAAc,UAC/B;AAAA,wBAAC,UAAO,MAAM,MAAM,OAClB,8BAAC,QAAK,OAAO,OAAO,aAAc,iBAAM,GAC1C;AAAA,IAEC,cACC,oBAAC,OAAI,eAAc,UAAS,YAAY,GACtC,8BAAC,QAAK,OAAO,OAAO,SAAU,uBAAY,GAC5C,IACA;AAAA,IAED,QACC,oBAAC,OAAI,eAAc,UAAS,WAAW,GAAG,YAAY,GACpD,8BAAC,QAAK,OAAO,OAAO,OAAQ,iBAAM,GACpC,IACA;AAAA,IAED,QACC,iCACE;AAAA,0BAAC,OAAI,eAAc,UAAS,WAAW,GAAG,YAAY,GACpD,8BAAC,QAAK,OAAO,OAAO,OAAQ,gBAAM,aAAY,GAChD;AAAA,MAEC,MAAM,QACL,oBAAC,OAAI,eAAc,UAAS,WAAW,GAAG,YAAY,GACpD,8BAAC,QAAK,OAAO,OAAO,OAAQ,gBAAM,OAAM,GAC1C,IACA;AAAA,OACJ,IACA;AAAA,KACJ;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box, Text } from "ink";
|
|
4
|
+
import { Spinner } from "./Spinner.js";
|
|
5
|
+
export function Header({
|
|
6
|
+
children,
|
|
7
|
+
icon,
|
|
8
|
+
showSpinner = false,
|
|
9
|
+
...boxProps
|
|
10
|
+
}) {
|
|
11
|
+
return /* @__PURE__ */ jsxs(Box, { ...boxProps, children: [
|
|
12
|
+
icon || showSpinner ? /* @__PURE__ */ jsxs(Box, { marginRight: 1, children: [
|
|
13
|
+
showSpinner ? /* @__PURE__ */ jsx(Spinner, {}) : null,
|
|
14
|
+
!showSpinner && icon ? /* @__PURE__ */ jsx(Text, { children: icon }) : null
|
|
15
|
+
] }) : null,
|
|
16
|
+
/* @__PURE__ */ jsx(Box, { children })
|
|
17
|
+
] });
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Header.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../source/ui/Header.tsx"],
|
|
4
|
+
"sourcesContent": ["import {Box, type BoxProps, Text} from 'ink';\nimport {type PropsWithChildren} from 'react';\n\nimport {Spinner} from './Spinner.js';\n\n/**\n * {@link Header} component props.\n */\nexport type HeaderProps = BoxProps & {\n /** Icon (recommended is 1 character) to render before the header itself. */\n icon?: string;\n\n /** Show spinner instead of the icon. */\n showSpinner?: boolean;\n};\n\n/**\n * Header component.\n */\nexport function Header({\n children,\n icon,\n showSpinner = false,\n ...boxProps\n}: PropsWithChildren<HeaderProps>) {\n return (\n <Box {...boxProps}>\n {icon || showSpinner ?\n <Box marginRight={1}>\n {showSpinner ?\n <Spinner />\n : null}\n {!showSpinner && icon ?\n <Text>{icon}</Text>\n : null}\n </Box>\n : null}\n <Box>{children}</Box>\n </Box>\n );\n}\n"],
|
|
5
|
+
"mappings": ";AA4BQ,SAEI,KAFJ;AA5BR,SAAQ,KAAoB,YAAW;AAGvC,SAAQ,eAAc;AAgBf,gBAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA,cAAc;AAAA,EACd,GAAG;AACL,GAAmC;AACjC,SACE,qBAAC,OAAK,GAAG,UACN;AAAA,YAAQ,cACP,qBAAC,OAAI,aAAa,GACf;AAAA,oBACC,oBAAC,WAAQ,IACT;AAAA,MACD,CAAC,eAAe,OACf,oBAAC,QAAM,gBAAK,IACZ;AAAA,OACJ,IACA;AAAA,IACF,oBAAC,OAAK,UAAS;AAAA,KACjB;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|