@jakubmazanec/cli 0.5.4-next.cad63bdb → 0.5.4-unstable.2468857d
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/build/_virtual/rolldown_runtime.js +18 -0
- package/build/constants.js +7 -5
- package/build/main.js +18 -4
- package/build/program/Command.js +54 -70
- package/build/program/Program.js +153 -188
- package/build/program/ProgramError.js +9 -5
- package/build/program/getProgramDetail.js +21 -24
- package/build/ui/Failure.js +61 -17
- package/build/ui/Header.js +18 -17
- package/build/ui/Help.js +44 -35
- package/build/ui/Spinner.js +35 -19
- package/build/ui/colors.js +28 -12
- package/build/ui/form/FormRow.js +42 -72
- package/build/ui/form/SelectInput.js +91 -83
- package/build/ui/form/TextInput.js +115 -126
- package/build/ui/form/createForm.js +57 -70
- package/build/ui/getErrorDetail.js +47 -62
- package/build/ui/icons.js +27 -12
- package/build/ui/internals/Wrapper.js +45 -44
- package/build/ui/internals/programContext.js +9 -3
- package/build/ui/internals/rotate.js +14 -5
- package/build/ui/useProgram.js +21 -16
- package/package.json +9 -9
- package/build/constants.js.map +0 -7
- package/build/main.js.map +0 -7
- package/build/program/Command.js.map +0 -7
- package/build/program/CommandAction.js +0 -2
- package/build/program/CommandAction.js.map +0 -7
- package/build/program/CommandArguments.js +0 -2
- package/build/program/CommandArguments.js.map +0 -7
- package/build/program/CommandOptions.js +0 -2
- package/build/program/CommandOptions.js.map +0 -7
- package/build/program/Program.js.map +0 -7
- package/build/program/ProgramCreateOptions.js +0 -2
- package/build/program/ProgramCreateOptions.js.map +0 -7
- package/build/program/ProgramDetail.js +0 -2
- package/build/program/ProgramDetail.js.map +0 -7
- package/build/program/ProgramError.js.map +0 -7
- package/build/program/ProgramOptions.js +0 -2
- package/build/program/ProgramOptions.js.map +0 -7
- package/build/program/ProgramStreams.js +0 -2
- package/build/program/ProgramStreams.js.map +0 -7
- package/build/program/getProgramDetail.js.map +0 -7
- package/build/program.js +0 -6
- package/build/program.js.map +0 -7
- package/build/ui/ErrorDetail.js +0 -2
- package/build/ui/ErrorDetail.js.map +0 -7
- package/build/ui/Failure.js.map +0 -7
- package/build/ui/Header.js.map +0 -7
- package/build/ui/Help.js.map +0 -7
- package/build/ui/Spinner.js.map +0 -7
- package/build/ui/colors.js.map +0 -7
- package/build/ui/form/Form.js +0 -2
- package/build/ui/form/Form.js.map +0 -7
- package/build/ui/form/FormConfig.js +0 -2
- package/build/ui/form/FormConfig.js.map +0 -7
- package/build/ui/form/FormProps.js +0 -2
- package/build/ui/form/FormProps.js.map +0 -7
- package/build/ui/form/FormResult.js +0 -2
- package/build/ui/form/FormResult.js.map +0 -7
- package/build/ui/form/FormRow.js.map +0 -7
- package/build/ui/form/FormRowConfig.js +0 -2
- package/build/ui/form/FormRowConfig.js.map +0 -7
- package/build/ui/form/FormRowsConfig.js +0 -2
- package/build/ui/form/FormRowsConfig.js.map +0 -7
- package/build/ui/form/FormValue.js +0 -2
- package/build/ui/form/FormValue.js.map +0 -7
- package/build/ui/form/FormValues.js +0 -2
- package/build/ui/form/FormValues.js.map +0 -7
- package/build/ui/form/SelectInput.js.map +0 -7
- package/build/ui/form/SelectInputItem.js +0 -2
- package/build/ui/form/SelectInputItem.js.map +0 -7
- package/build/ui/form/TextInput.js.map +0 -7
- package/build/ui/form/createForm.js.map +0 -7
- package/build/ui/form.js +0 -6
- package/build/ui/form.js.map +0 -7
- package/build/ui/getErrorDetail.js.map +0 -7
- package/build/ui/icons.js.map +0 -7
- package/build/ui/internals/Wrapper.js.map +0 -7
- package/build/ui/internals/programContext.js.map +0 -7
- package/build/ui/internals/rotate.js.map +0 -7
- package/build/ui/internals.js +0 -5
- package/build/ui/internals.js.map +0 -7
- package/build/ui/useProgram.js.map +0 -7
- package/build/ui.js +0 -11
- package/build/ui.js.map +0 -7
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (all, symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) {
|
|
6
|
+
__defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
if (symbols) {
|
|
12
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { __export };
|
package/build/constants.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import url from "node:url";
|
|
3
|
+
|
|
4
|
+
//#region source/constants.ts
|
|
4
5
|
let directory = path.dirname(url.fileURLToPath(import.meta.url));
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//#
|
|
6
|
+
const PACKAGE_PATH = path.resolve(directory, "..");
|
|
7
|
+
const CACHE_PATH = path.resolve(PACKAGE_PATH, "node_modules/.cache");
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CACHE_PATH };
|
package/build/main.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Command } from "./program/Command.js";
|
|
2
|
+
import { getProgramDetail } from "./program/getProgramDetail.js";
|
|
3
|
+
import { colors_exports } from "./ui/colors.js";
|
|
4
|
+
import { getErrorDetail } from "./ui/getErrorDetail.js";
|
|
5
|
+
import { Spinner } from "./ui/Spinner.js";
|
|
6
|
+
import { Header } from "./ui/Header.js";
|
|
7
|
+
import { icons_exports } from "./ui/icons.js";
|
|
8
|
+
import { Failure } from "./ui/Failure.js";
|
|
9
|
+
import { SelectInput } from "./ui/form/SelectInput.js";
|
|
10
|
+
import { TextInput } from "./ui/form/TextInput.js";
|
|
11
|
+
import { FormRow } from "./ui/form/FormRow.js";
|
|
12
|
+
import { createForm } from "./ui/form/createForm.js";
|
|
13
|
+
import { Help } from "./ui/Help.js";
|
|
14
|
+
import { useProgram } from "./ui/useProgram.js";
|
|
15
|
+
import { ProgramError } from "./program/ProgramError.js";
|
|
16
|
+
import { Program } from "./program/Program.js";
|
|
17
|
+
|
|
18
|
+
export { Command, Failure, FormRow, Header, Help, Program, ProgramError, SelectInput, Spinner, TextInput, colors_exports as colors, createForm, getErrorDetail, getProgramDetail, icons_exports as icons, useProgram };
|
package/build/program/Command.js
CHANGED
|
@@ -1,70 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
1
|
+
import { parseArguments } from "@jakubmazanec/args";
|
|
2
|
+
|
|
3
|
+
//#region source/program/Command.ts
|
|
4
|
+
/**
|
|
5
|
+
* Command encapsulates piece of a CLI's logic and is executed when {@link Program} instance parses that command from the command line arguments.
|
|
6
|
+
*/
|
|
7
|
+
var Command = class {
|
|
8
|
+
name;
|
|
9
|
+
description;
|
|
10
|
+
parameters;
|
|
11
|
+
options;
|
|
12
|
+
allowUnknownOptions;
|
|
13
|
+
allowUnknownParameters;
|
|
14
|
+
action;
|
|
15
|
+
/**
|
|
16
|
+
* @param name Command name, ie. space-separated words consisting only of letters, numbers (but not at the start of the word) or dashes.
|
|
17
|
+
* @param action Function that runs when command is executed.
|
|
18
|
+
* @param options Additionl command options.
|
|
19
|
+
*/
|
|
20
|
+
constructor(name, action, { description, parameters, options, allowUnknownOptions, allowUnknownParameters }) {
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.action = action;
|
|
23
|
+
if (description) this.description = description;
|
|
24
|
+
if (parameters) this.parameters = parameters;
|
|
25
|
+
else this.parameters = null;
|
|
26
|
+
if (options) this.options = options;
|
|
27
|
+
else this.options = null;
|
|
28
|
+
if (allowUnknownOptions) this.allowUnknownOptions = allowUnknownOptions;
|
|
29
|
+
else this.allowUnknownOptions = false;
|
|
30
|
+
if (allowUnknownParameters) this.allowUnknownParameters = allowUnknownParameters;
|
|
31
|
+
else this.allowUnknownParameters = false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parses a list of command line arguments into an arguments object. Parser is pre-configured based on this command.
|
|
35
|
+
*/
|
|
36
|
+
parseArguments(argv) {
|
|
37
|
+
return parseArguments(argv, {
|
|
38
|
+
commands: [this.name],
|
|
39
|
+
parameters: this.parameters ?? void 0,
|
|
40
|
+
options: this.options ?? void 0,
|
|
41
|
+
allowUnknownOptions: this.allowUnknownOptions,
|
|
42
|
+
allowUnknownParameters: this.allowUnknownParameters
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Executes command action with provided parsed arguments and {@link Program} instance.
|
|
47
|
+
*/
|
|
48
|
+
async run(parsedArgs, program) {
|
|
49
|
+
await this.action(parsedArgs, program);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { Command };
|
package/build/program/Program.js
CHANGED
|
@@ -1,191 +1,156 @@
|
|
|
1
|
-
|
|
1
|
+
import { CACHE_PATH } from "../constants.js";
|
|
2
|
+
import { Failure } from "../ui/Failure.js";
|
|
3
|
+
import { Wrapper } from "../ui/internals/Wrapper.js";
|
|
4
|
+
import { Help } from "../ui/Help.js";
|
|
5
|
+
import { ProgramError } from "./ProgramError.js";
|
|
2
6
|
import fs from "fs-extra";
|
|
3
7
|
import fetchLatestVersion from "latest-version";
|
|
4
8
|
import path from "node:path";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
|
9
|
+
|
|
10
|
+
//#region source/program/Program.ts
|
|
11
|
+
/**
|
|
12
|
+
* Program manages and executes {@link Command} instances attached to it based on parsing command line arguments.
|
|
13
|
+
*/
|
|
14
|
+
var Program = class {
|
|
15
|
+
/** Program name. */
|
|
16
|
+
name;
|
|
17
|
+
/** More readable program name. */
|
|
18
|
+
displayName;
|
|
19
|
+
/** Program version. */
|
|
20
|
+
version;
|
|
21
|
+
/** Program latest version. */
|
|
22
|
+
latestVersion;
|
|
23
|
+
/** Program description. */
|
|
24
|
+
description;
|
|
25
|
+
/** Program executable name. */
|
|
26
|
+
bin;
|
|
27
|
+
/** Program commands */
|
|
28
|
+
commands = [];
|
|
29
|
+
isRendering = false;
|
|
30
|
+
streams = {
|
|
31
|
+
stderr: process.stderr,
|
|
32
|
+
stdin: process.stdin,
|
|
33
|
+
stdout: process.stdout
|
|
34
|
+
};
|
|
35
|
+
/** Custom error boundary fallback component */
|
|
36
|
+
ErrorBoundaryFallbackComponent;
|
|
37
|
+
constructor({ name, displayName, version, latestVersion, description, bin, ErrorBoundaryFallbackComponent }) {
|
|
38
|
+
if (name) this.name = name;
|
|
39
|
+
if (displayName) this.displayName = displayName;
|
|
40
|
+
if (version) this.version = version;
|
|
41
|
+
if (latestVersion) this.latestVersion = latestVersion;
|
|
42
|
+
if (description) this.description = description;
|
|
43
|
+
if (bin) this.bin = bin;
|
|
44
|
+
if (ErrorBoundaryFallbackComponent) this.ErrorBoundaryFallbackComponent = ErrorBoundaryFallbackComponent;
|
|
45
|
+
else this.ErrorBoundaryFallbackComponent = Failure;
|
|
46
|
+
}
|
|
47
|
+
static async create({ name, version, description, bin, ErrorBoundaryFallbackComponent, checkForUpdate }) {
|
|
48
|
+
let latestVersion;
|
|
49
|
+
if (checkForUpdate && name) {
|
|
50
|
+
let cachePath = path.join(CACHE_PATH, name, "latest-version.json");
|
|
51
|
+
let cachedLatestVersion;
|
|
52
|
+
try {
|
|
53
|
+
cachedLatestVersion = await fs.readJson(cachePath);
|
|
54
|
+
} catch {}
|
|
55
|
+
if (!cachedLatestVersion || Date.now() - cachedLatestVersion.datetime > 864e4) {
|
|
56
|
+
latestVersion = await fetchLatestVersion(name);
|
|
57
|
+
await fs.ensureFile(cachePath);
|
|
58
|
+
await fs.writeJson(cachePath, {
|
|
59
|
+
value: latestVersion,
|
|
60
|
+
datetime: Date.now()
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new this({
|
|
65
|
+
name,
|
|
66
|
+
version,
|
|
67
|
+
latestVersion,
|
|
68
|
+
description,
|
|
69
|
+
bin,
|
|
70
|
+
ErrorBoundaryFallbackComponent
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Adds command to the program.
|
|
75
|
+
*
|
|
76
|
+
* @param command Command to add.
|
|
77
|
+
* @returns Program instance.
|
|
78
|
+
*/
|
|
79
|
+
addCommand(command) {
|
|
80
|
+
this.commands.push(command);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Renders a React element using Ink and outputs to the configured streams.
|
|
85
|
+
*
|
|
86
|
+
* @param element The React element to render.
|
|
87
|
+
*/
|
|
88
|
+
async renderElement(element) {
|
|
89
|
+
if (this.isRendering) throw new ProgramError("NO_NESTED_RENDER");
|
|
90
|
+
else this.isRendering = true;
|
|
91
|
+
let { render } = await import("ink");
|
|
92
|
+
let { createElement } = await import("react");
|
|
93
|
+
let { stdin, stdout, stderr } = this.streams;
|
|
94
|
+
try {
|
|
95
|
+
render(createElement(Wrapper, { program: this }, element), {
|
|
96
|
+
exitOnCtrlC: true,
|
|
97
|
+
patchConsole: true,
|
|
98
|
+
stderr,
|
|
99
|
+
stdin,
|
|
100
|
+
stdout
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof Error) await this.renderElement(createElement(this.ErrorBoundaryFallbackComponent, {
|
|
104
|
+
error,
|
|
105
|
+
resetErrorBoundary: () => {}
|
|
106
|
+
}));
|
|
107
|
+
} finally {
|
|
108
|
+
this.isRendering = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Runs the program.
|
|
113
|
+
*
|
|
114
|
+
* @param argv Unparsed command line arguments.
|
|
115
|
+
*/
|
|
116
|
+
async run(argv) {
|
|
117
|
+
let hasCommandRun = false;
|
|
118
|
+
for (let command of this.commands) {
|
|
119
|
+
let parsedArgs = command.parseArguments(argv);
|
|
120
|
+
if (parsedArgs.command) {
|
|
121
|
+
hasCommandRun = true;
|
|
122
|
+
if (parsedArgs.errors.length) {
|
|
123
|
+
let { createElement } = await import("react");
|
|
124
|
+
for (let error of parsedArgs.errors) {
|
|
125
|
+
process.exitCode = 1;
|
|
126
|
+
await this.renderElement(createElement(this.ErrorBoundaryFallbackComponent, {
|
|
127
|
+
error,
|
|
128
|
+
resetErrorBoundary: () => {}
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
try {
|
|
133
|
+
await command.run(parsedArgs, this);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
let { createElement } = await import("react");
|
|
136
|
+
if (error instanceof Error) {
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
await this.renderElement(createElement(this.ErrorBoundaryFallbackComponent, {
|
|
139
|
+
error,
|
|
140
|
+
resetErrorBoundary: () => {}
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!hasCommandRun) {
|
|
149
|
+
let { createElement } = await import("react");
|
|
150
|
+
await this.renderElement(createElement(Help, { program: this }));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
export { Program };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
import { createCustomError } from "@jakubmazanec/error";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
|
|
3
|
+
//#region source/program/ProgramError.ts
|
|
4
|
+
/**
|
|
5
|
+
* A subclass of `Error` that indicates a program failure.
|
|
6
|
+
*/
|
|
7
|
+
const ProgramError = createCustomError("ProgramError", { NO_NESTED_RENDER: "A React render process already exists. This usually occurs by triggering nested render calls." });
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ProgramError };
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
if (typeof packageJson.bin === "string" && packageJson.name) {
|
|
21
|
-
programDetail.bin = packageJson.name;
|
|
22
|
-
}
|
|
23
|
-
return programDetail;
|
|
1
|
+
//#region source/program/getProgramDetail.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates detailed information about a {@lincode Program}.
|
|
4
|
+
*/
|
|
5
|
+
function getProgramDetail(packageJson) {
|
|
6
|
+
let programDetail = {};
|
|
7
|
+
if (packageJson.name) programDetail.name = packageJson.name;
|
|
8
|
+
if (packageJson.version) programDetail.version = packageJson.version;
|
|
9
|
+
if (packageJson.description) programDetail.description = packageJson.description;
|
|
10
|
+
if (packageJson.bin && typeof packageJson.bin !== "string") {
|
|
11
|
+
let bins = Object.entries(packageJson.bin);
|
|
12
|
+
if (bins.length === 1) {
|
|
13
|
+
let firstBin = bins[0];
|
|
14
|
+
[programDetail.bin] = firstBin;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (typeof packageJson.bin === "string" && packageJson.name) programDetail.bin = packageJson.name;
|
|
18
|
+
return programDetail;
|
|
24
19
|
}
|
|
25
|
-
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getProgramDetail };
|