@oclif/core 3.0.0-beta.13 → 3.0.0-beta.15
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 +3 -1
- package/lib/args.d.ts +1 -1
- package/lib/args.js +13 -15
- package/lib/cli-ux/action/base.d.ts +1 -1
- package/lib/cli-ux/action/base.js +20 -15
- package/lib/cli-ux/action/simple.js +10 -8
- package/lib/cli-ux/action/spinner.js +11 -10
- package/lib/cli-ux/config.js +8 -7
- package/lib/cli-ux/flush.js +2 -3
- package/lib/cli-ux/index.d.ts +10 -28
- package/lib/cli-ux/index.js +26 -45
- package/lib/cli-ux/list.js +1 -1
- package/lib/cli-ux/prompt.js +24 -19
- package/lib/cli-ux/styled/index.d.ts +5 -6
- package/lib/cli-ux/styled/index.js +11 -11
- package/lib/cli-ux/styled/json.js +3 -2
- package/lib/cli-ux/styled/object.js +6 -8
- package/lib/cli-ux/styled/table.d.ts +4 -4
- package/lib/cli-ux/styled/table.js +36 -45
- package/lib/cli-ux/wait.js +3 -5
- package/lib/command.d.ts +7 -5
- package/lib/command.js +35 -28
- package/lib/config/config.d.ts +2 -2
- package/lib/config/config.js +57 -43
- package/lib/config/plugin-loader.js +25 -11
- package/lib/config/plugin.d.ts +1 -1
- package/lib/config/plugin.js +66 -56
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +41 -34
- package/lib/config/util.d.ts +1 -5
- package/lib/config/util.js +5 -46
- package/lib/errors/config.js +1 -1
- package/lib/errors/errors/cli.d.ts +1 -1
- package/lib/errors/errors/cli.js +14 -13
- package/lib/errors/errors/exit.d.ts +0 -3
- package/lib/errors/errors/module-load.d.ts +0 -3
- package/lib/errors/errors/pretty-print.js +9 -8
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +23 -14
- package/lib/errors/index.d.ts +2 -2
- package/lib/errors/index.js +20 -19
- package/lib/errors/logger.js +4 -4
- package/lib/execute.d.ts +5 -5
- package/lib/execute.js +6 -5
- package/lib/flags.d.ts +102 -31
- package/lib/flags.js +75 -42
- package/lib/help/command.d.ts +2 -0
- package/lib/help/command.js +32 -32
- package/lib/help/docopts.js +2 -9
- package/lib/help/formatter.d.ts +1 -1
- package/lib/help/formatter.js +17 -17
- package/lib/help/index.d.ts +2 -2
- package/lib/help/index.js +22 -21
- package/lib/help/root.js +2 -2
- package/lib/help/util.d.ts +1 -1
- package/lib/help/util.js +9 -9
- package/lib/index.d.ts +19 -20
- package/lib/index.js +38 -42
- package/lib/interfaces/config.d.ts +5 -4
- package/lib/interfaces/errors.d.ts +1 -1
- package/lib/interfaces/parser.d.ts +168 -45
- package/lib/interfaces/plugin.d.ts +1 -0
- package/lib/main.d.ts +1 -1
- package/lib/main.js +16 -16
- package/lib/module-loader.d.ts +67 -77
- package/lib/module-loader.js +179 -149
- package/lib/parser/errors.d.ts +2 -2
- package/lib/parser/errors.js +4 -3
- package/lib/parser/help.js +3 -2
- package/lib/parser/parse.d.ts +3 -0
- package/lib/parser/parse.js +56 -52
- package/lib/parser/validate.js +9 -5
- package/lib/performance.d.ts +6 -2
- package/lib/performance.js +23 -12
- package/lib/util.d.ts +25 -1
- package/lib/util.js +93 -29
- package/package.json +10 -15
package/README.md
CHANGED
|
@@ -11,9 +11,11 @@ base library for oclif CLIs
|
|
|
11
11
|
Migrating
|
|
12
12
|
=====
|
|
13
13
|
|
|
14
|
+
See the [v3 migration guide](./guides/V3_MIGRATION.md) for an overview of breaking changes that occurred between v2 and v3.
|
|
15
|
+
|
|
14
16
|
See the [v2 migration guide](./guides/V2_MIGRATION.md) for an overview of breaking changes that occurred between v1 and v2.
|
|
15
17
|
|
|
16
|
-
See the [
|
|
18
|
+
Migrating from `@oclif/config` and `@oclif/command`? See the [v1 migration guide](./guides/PRE_CORE_MIGRATION.md).
|
|
17
19
|
|
|
18
20
|
CLI UX
|
|
19
21
|
=====
|
package/lib/args.d.ts
CHANGED
package/lib/args.js
CHANGED
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.string = exports.url = exports.file = exports.directory = exports.integer = exports.boolean = exports.custom = void 0;
|
|
4
|
-
const url_1 = require("url");
|
|
5
4
|
const util_1 = require("./util");
|
|
5
|
+
const node_url_1 = require("node:url");
|
|
6
6
|
function custom(defaults) {
|
|
7
|
-
return (options = {}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
};
|
|
7
|
+
return (options = {}) => ({
|
|
8
|
+
parse: async (i, _context, _opts) => i,
|
|
9
|
+
...defaults,
|
|
10
|
+
...options,
|
|
11
|
+
input: [],
|
|
12
|
+
type: 'option',
|
|
13
|
+
});
|
|
16
14
|
}
|
|
17
15
|
exports.custom = custom;
|
|
18
16
|
exports.boolean = custom({
|
|
19
17
|
parse: async (b) => Boolean(b) && (0, util_1.isNotFalsy)(b),
|
|
20
18
|
});
|
|
21
19
|
exports.integer = custom({
|
|
22
|
-
|
|
20
|
+
async parse(input, _, opts) {
|
|
23
21
|
if (!/^-?\d+$/.test(input))
|
|
24
22
|
throw new Error(`Expected an integer but received: ${input}`);
|
|
25
23
|
const num = Number.parseInt(input, 10);
|
|
@@ -31,14 +29,14 @@ exports.integer = custom({
|
|
|
31
29
|
},
|
|
32
30
|
});
|
|
33
31
|
exports.directory = custom({
|
|
34
|
-
|
|
32
|
+
async parse(input, _, opts) {
|
|
35
33
|
if (opts.exists)
|
|
36
34
|
return (0, util_1.dirExists)(input);
|
|
37
35
|
return input;
|
|
38
36
|
},
|
|
39
37
|
});
|
|
40
38
|
exports.file = custom({
|
|
41
|
-
|
|
39
|
+
async parse(input, _, opts) {
|
|
42
40
|
if (opts.exists)
|
|
43
41
|
return (0, util_1.fileExists)(input);
|
|
44
42
|
return input;
|
|
@@ -49,9 +47,9 @@ exports.file = custom({
|
|
|
49
47
|
* if the string is not a valid URL.
|
|
50
48
|
*/
|
|
51
49
|
exports.url = custom({
|
|
52
|
-
|
|
50
|
+
async parse(input) {
|
|
53
51
|
try {
|
|
54
|
-
return new
|
|
52
|
+
return new node_url_1.URL(input);
|
|
55
53
|
}
|
|
56
54
|
catch {
|
|
57
55
|
throw new Error(`Expected a valid url but received: ${input}`);
|
|
@@ -22,7 +22,7 @@ export declare class ActionBase {
|
|
|
22
22
|
get running(): boolean;
|
|
23
23
|
get status(): string | undefined;
|
|
24
24
|
set status(status: string | undefined);
|
|
25
|
-
pauseAsync<T
|
|
25
|
+
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
|
26
26
|
pause(fn: () => any, icon?: string): Promise<any>;
|
|
27
27
|
protected _start(): void;
|
|
28
28
|
protected _stop(_: string): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActionBase = void 0;
|
|
4
|
-
const util_1 = require("util");
|
|
5
|
-
const util_2 = require("../../util");
|
|
6
4
|
const stream_1 = require("../stream");
|
|
5
|
+
const util_1 = require("../../util");
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
7
7
|
class ActionBase {
|
|
8
8
|
constructor() {
|
|
9
9
|
this.std = 'stderr';
|
|
@@ -21,7 +21,7 @@ class ActionBase {
|
|
|
21
21
|
this._stdout(true);
|
|
22
22
|
}
|
|
23
23
|
stop(msg = 'done') {
|
|
24
|
-
const task = this
|
|
24
|
+
const { task } = this;
|
|
25
25
|
if (!task) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
@@ -55,7 +55,7 @@ class ActionBase {
|
|
|
55
55
|
return this.task ? this.task.status : undefined;
|
|
56
56
|
}
|
|
57
57
|
set status(status) {
|
|
58
|
-
const task = this
|
|
58
|
+
const { task } = this;
|
|
59
59
|
if (!task) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
@@ -66,7 +66,7 @@ class ActionBase {
|
|
|
66
66
|
task.status = status;
|
|
67
67
|
}
|
|
68
68
|
async pauseAsync(fn, icon) {
|
|
69
|
-
const task = this
|
|
69
|
+
const { task } = this;
|
|
70
70
|
const active = task && task.active;
|
|
71
71
|
if (task && active) {
|
|
72
72
|
this._pause(icon);
|
|
@@ -80,7 +80,7 @@ class ActionBase {
|
|
|
80
80
|
return ret;
|
|
81
81
|
}
|
|
82
82
|
pause(fn, icon) {
|
|
83
|
-
const task = this
|
|
83
|
+
const { task } = this;
|
|
84
84
|
const active = task && task.active;
|
|
85
85
|
if (task && active) {
|
|
86
86
|
this._pause(icon);
|
|
@@ -106,7 +106,9 @@ class ActionBase {
|
|
|
106
106
|
_pause(_) {
|
|
107
107
|
throw new Error('not implemented');
|
|
108
108
|
}
|
|
109
|
-
_updateStatus(_, __) {
|
|
109
|
+
_updateStatus(_, __) {
|
|
110
|
+
// Not implemented
|
|
111
|
+
}
|
|
110
112
|
// mock out stdout/stderr so it doesn't screw up the rendering
|
|
111
113
|
_stdout(toggle) {
|
|
112
114
|
try {
|
|
@@ -137,7 +139,7 @@ class ActionBase {
|
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
catch (error) {
|
|
140
|
-
this._write('stderr', (0,
|
|
142
|
+
this._write('stderr', (0, node_util_1.inspect)(error));
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
// flush mocked stdout/stderr
|
|
@@ -153,25 +155,28 @@ class ActionBase {
|
|
|
153
155
|
}
|
|
154
156
|
// add newline if there isn't one already
|
|
155
157
|
// otherwise we'll just overwrite it when we render
|
|
156
|
-
if (output && std && output
|
|
158
|
+
if (output && std && output.at(-1) !== '\n') {
|
|
157
159
|
this._write(std, '\n');
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
162
|
catch (error) {
|
|
161
|
-
this._write('stderr', (0,
|
|
163
|
+
this._write('stderr', (0, node_util_1.inspect)(error));
|
|
162
164
|
}
|
|
163
165
|
}
|
|
164
166
|
// write to the real stdout/stderr
|
|
165
167
|
_write(std, s) {
|
|
166
168
|
switch (std) {
|
|
167
|
-
case 'stdout':
|
|
168
|
-
this.stdmockOrigs.stdout.apply(stream_1.stdout, (0,
|
|
169
|
+
case 'stdout': {
|
|
170
|
+
this.stdmockOrigs.stdout.apply(stream_1.stdout, (0, util_1.castArray)(s));
|
|
169
171
|
break;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
}
|
|
173
|
+
case 'stderr': {
|
|
174
|
+
this.stdmockOrigs.stderr.apply(stream_1.stderr, (0, util_1.castArray)(s));
|
|
172
175
|
break;
|
|
173
|
-
|
|
176
|
+
}
|
|
177
|
+
default: {
|
|
174
178
|
throw new Error(`invalid std: ${std}`);
|
|
179
|
+
}
|
|
175
180
|
}
|
|
176
181
|
}
|
|
177
182
|
}
|
|
@@ -7,7 +7,7 @@ class SimpleAction extends base_1.ActionBase {
|
|
|
7
7
|
this.type = 'simple';
|
|
8
8
|
}
|
|
9
9
|
_start() {
|
|
10
|
-
const task = this
|
|
10
|
+
const { task } = this;
|
|
11
11
|
if (!task)
|
|
12
12
|
return;
|
|
13
13
|
this._render(task.action, task.status);
|
|
@@ -18,31 +18,33 @@ class SimpleAction extends base_1.ActionBase {
|
|
|
18
18
|
else
|
|
19
19
|
this._flush();
|
|
20
20
|
}
|
|
21
|
-
_resume() {
|
|
21
|
+
_resume() {
|
|
22
|
+
// Not implemented
|
|
23
|
+
}
|
|
22
24
|
_updateStatus(status, prevStatus, newline = false) {
|
|
23
|
-
const task = this
|
|
25
|
+
const { task, std } = this;
|
|
24
26
|
if (!task)
|
|
25
27
|
return;
|
|
26
28
|
if (task.active && !prevStatus)
|
|
27
|
-
this._write(
|
|
29
|
+
this._write(std, ` ${status}`);
|
|
28
30
|
else
|
|
29
|
-
this._write(
|
|
31
|
+
this._write(std, `${task.action}... ${status}`);
|
|
30
32
|
if (newline || !prevStatus)
|
|
31
33
|
this._flush();
|
|
32
34
|
}
|
|
33
35
|
_stop(status) {
|
|
34
|
-
const task = this
|
|
36
|
+
const { task } = this;
|
|
35
37
|
if (!task)
|
|
36
38
|
return;
|
|
37
39
|
this._updateStatus(status, task.status, true);
|
|
38
40
|
}
|
|
39
41
|
_render(action, status) {
|
|
40
|
-
const task = this
|
|
42
|
+
const { task, std } = this;
|
|
41
43
|
if (!task)
|
|
42
44
|
return;
|
|
43
45
|
if (task.active)
|
|
44
46
|
this._flush();
|
|
45
|
-
this._write(
|
|
47
|
+
this._write(std, status ? `${action}... ${status}` : `${action}...`);
|
|
46
48
|
}
|
|
47
49
|
_flush() {
|
|
48
50
|
this._write(this.std, '\n');
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const supportsColor = require("supports-color");
|
|
5
|
-
const stripAnsi = require('strip-ansi');
|
|
6
|
-
const ansiStyles = require('ansi-styles');
|
|
7
|
-
const screen_1 = require("../../screen");
|
|
8
|
-
const spinners_1 = require("./spinners");
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const supportsColor = tslib_1.__importStar(require("supports-color"));
|
|
9
5
|
const base_1 = require("./base");
|
|
6
|
+
const ansi_styles_1 = tslib_1.__importDefault(require("ansi-styles"));
|
|
7
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
8
|
+
const screen_1 = require("../../screen");
|
|
9
|
+
const spinners_1 = tslib_1.__importDefault(require("./spinners"));
|
|
10
|
+
const strip_ansi_1 = tslib_1.__importDefault(require("strip-ansi"));
|
|
10
11
|
function color(s) {
|
|
11
12
|
if (!supportsColor)
|
|
12
13
|
return s;
|
|
13
14
|
const has256 = supportsColor.stdout ? supportsColor.stdout.has256 : (process.env.TERM || '').includes('256');
|
|
14
|
-
return has256 ? `\u001B[38;5;104m${s}${
|
|
15
|
+
return has256 ? `\u001B[38;5;104m${s}${ansi_styles_1.default.reset.open}` : chalk_1.default.magenta(s);
|
|
15
16
|
}
|
|
16
17
|
class SpinnerAction extends base_1.ActionBase {
|
|
17
18
|
constructor() {
|
|
@@ -51,7 +52,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
51
52
|
return color(frame);
|
|
52
53
|
}
|
|
53
54
|
_render(icon) {
|
|
54
|
-
const task = this
|
|
55
|
+
const { task, std, output } = this;
|
|
55
56
|
if (!task)
|
|
56
57
|
return;
|
|
57
58
|
this._reset();
|
|
@@ -59,7 +60,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
59
60
|
const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || '';
|
|
60
61
|
const status = task.status ? ` ${task.status}` : '';
|
|
61
62
|
this.output = `${task.action}...${frame}${status}\n`;
|
|
62
|
-
this._write(
|
|
63
|
+
this._write(std, output);
|
|
63
64
|
}
|
|
64
65
|
_reset() {
|
|
65
66
|
if (!this.output)
|
|
@@ -70,7 +71,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
70
71
|
this.output = undefined;
|
|
71
72
|
}
|
|
72
73
|
_lines(s) {
|
|
73
|
-
return
|
|
74
|
+
return (0, strip_ansi_1.default)(s).split('\n')
|
|
74
75
|
.map(l => Math.ceil(l.length / screen_1.errtermwidth))
|
|
75
76
|
.reduce((c, i) => c + i, 0);
|
|
76
77
|
}
|
package/lib/cli-ux/config.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config = exports.Config = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const util_1 = require("../util");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
6
|
+
const simple_1 = tslib_1.__importDefault(require("./action/simple"));
|
|
7
|
+
const spinner_1 = tslib_1.__importDefault(require("./action/spinner"));
|
|
7
8
|
const g = global;
|
|
8
9
|
const globals = g.ux || (g.ux = {});
|
|
9
|
-
const actionType = (Boolean(process.stderr.isTTY)
|
|
10
|
-
!process.env.CI
|
|
11
|
-
!['dumb', 'emacs-color'].includes(process.env.TERM)
|
|
12
|
-
'spinner') || 'simple';
|
|
13
|
-
const Action = actionType === 'spinner' ? spinner_1.default :
|
|
10
|
+
const actionType = (Boolean(process.stderr.isTTY)
|
|
11
|
+
&& !process.env.CI
|
|
12
|
+
&& !['dumb', 'emacs-color'].includes(process.env.TERM)
|
|
13
|
+
&& 'spinner') || 'simple';
|
|
14
|
+
const Action = actionType === 'spinner' ? spinner_1.default : simple_1.default;
|
|
14
15
|
class Config {
|
|
15
16
|
constructor() {
|
|
16
17
|
this.outputLevel = 'info';
|
package/lib/cli-ux/flush.js
CHANGED
|
@@ -17,9 +17,8 @@ async function _flush() {
|
|
|
17
17
|
__1.stdout.once('drain', () => resolve(null));
|
|
18
18
|
});
|
|
19
19
|
const flushed = __1.stdout.write('');
|
|
20
|
-
if (flushed)
|
|
21
|
-
return
|
|
22
|
-
}
|
|
20
|
+
if (flushed)
|
|
21
|
+
return;
|
|
23
22
|
return p;
|
|
24
23
|
}
|
|
25
24
|
async function flush(ms = 10000) {
|
package/lib/cli-ux/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import * as Errors from '../errors';
|
|
2
|
-
import { ActionBase } from './action/base';
|
|
3
|
-
import { config, Config } from './config';
|
|
4
|
-
import { ExitError } from './exit';
|
|
5
|
-
import { IPromptOptions } from './prompt';
|
|
6
2
|
import * as styled from './styled';
|
|
7
|
-
import { Table } from './styled';
|
|
8
3
|
import * as uxPrompt from './prompt';
|
|
4
|
+
import { Config } from './config';
|
|
5
|
+
import { ActionBase } from './action/base';
|
|
9
6
|
import uxWait from './wait';
|
|
10
7
|
export declare class ux {
|
|
11
8
|
static config: Config;
|
|
@@ -32,26 +29,11 @@ export declare class ux {
|
|
|
32
29
|
static annotation(text: string, annotation: string): void;
|
|
33
30
|
static flush(ms?: number): Promise<void>;
|
|
34
31
|
}
|
|
35
|
-
declare const action: ActionBase
|
|
36
|
-
declare const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
declare const flush: typeof ux.flush;
|
|
44
|
-
declare const info: typeof ux.info;
|
|
45
|
-
declare const log: typeof ux.log;
|
|
46
|
-
declare const progress: typeof styled.progress;
|
|
47
|
-
declare const prompt: typeof uxPrompt.prompt;
|
|
48
|
-
declare const styledHeader: typeof ux.styledHeader;
|
|
49
|
-
declare const styledJSON: typeof styled.styledJSON;
|
|
50
|
-
declare const styledObject: typeof ux.styledObject;
|
|
51
|
-
declare const table: typeof styled.Table.table;
|
|
52
|
-
declare const trace: typeof ux.trace;
|
|
53
|
-
declare const tree: typeof styled.tree;
|
|
54
|
-
declare const url: typeof ux.url;
|
|
55
|
-
declare const wait: (ms?: number) => Promise<void>;
|
|
56
|
-
declare const warn: typeof Errors.warn;
|
|
57
|
-
export { action, ActionBase, annotation, anykey, config, Config, confirm, debug, done, error, exit, ExitError, flush, info, IPromptOptions, log, progress, prompt, styledHeader, styledJSON, styledObject, table, Table, trace, tree, url, wait, warn, };
|
|
32
|
+
declare const action: ActionBase, annotation: typeof ux.annotation, anykey: typeof uxPrompt.anykey, confirm: typeof uxPrompt.confirm, debug: typeof ux.debug, done: typeof ux.done, flush: typeof ux.flush, info: typeof ux.info, log: typeof ux.log, progress: typeof styled.progress, prompt: typeof uxPrompt.prompt, styledHeader: typeof ux.styledHeader, styledJSON: typeof styled.styledJSON, styledObject: typeof ux.styledObject, table: typeof styled.Table.table, trace: typeof ux.trace, tree: typeof styled.tree, url: typeof ux.url, wait: (ms?: number) => Promise<void>;
|
|
33
|
+
declare const error: typeof Errors.error, exit: typeof Errors.exit, warn: typeof Errors.warn;
|
|
34
|
+
export { action, annotation, anykey, confirm, debug, done, error, exit, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, warn, };
|
|
35
|
+
export { ExitError } from './exit';
|
|
36
|
+
export { IPromptOptions } from './prompt';
|
|
37
|
+
export { Table } from './styled';
|
|
38
|
+
export { ActionBase } from './action/base';
|
|
39
|
+
export { config, Config } from './config';
|
package/lib/cli-ux/index.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function () { return base_1.ActionBase; } });
|
|
3
|
+
exports.Config = exports.config = exports.ActionBase = exports.Table = exports.ExitError = exports.warn = exports.wait = exports.url = exports.tree = exports.trace = exports.table = exports.styledObject = exports.styledJSON = exports.styledHeader = exports.prompt = exports.progress = exports.log = exports.info = exports.flush = exports.exit = exports.error = exports.done = exports.debug = exports.confirm = exports.anykey = exports.annotation = exports.action = exports.ux = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Errors = tslib_1.__importStar(require("../errors"));
|
|
6
|
+
const styled = tslib_1.__importStar(require("./styled"));
|
|
7
|
+
const uxPrompt = tslib_1.__importStar(require("./prompt"));
|
|
9
8
|
const config_1 = require("./config");
|
|
10
|
-
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
|
11
|
-
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
12
|
-
const exit_1 = require("./exit");
|
|
13
|
-
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
|
14
|
-
const styled = require("./styled");
|
|
15
|
-
const styled_1 = require("./styled");
|
|
16
|
-
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return styled_1.Table; } });
|
|
17
|
-
const uxPrompt = require("./prompt");
|
|
18
|
-
const wait_1 = require("./wait");
|
|
19
|
-
const stream_1 = require("./stream");
|
|
20
9
|
const flush_1 = require("./flush");
|
|
10
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
11
|
+
const stream_1 = require("./stream");
|
|
12
|
+
const node_util_1 = require("node:util");
|
|
13
|
+
const wait_1 = tslib_1.__importDefault(require("./wait"));
|
|
21
14
|
const hyperlinker = require('hyperlinker');
|
|
22
15
|
class ux {
|
|
23
16
|
static get prompt() {
|
|
@@ -35,12 +28,11 @@ class ux {
|
|
|
35
28
|
static get action() {
|
|
36
29
|
return config_1.config.action;
|
|
37
30
|
}
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
39
31
|
static styledObject(obj, keys) {
|
|
40
32
|
this.info(styled.styledObject(obj, keys));
|
|
41
33
|
}
|
|
42
34
|
static styledHeader(header) {
|
|
43
|
-
this.info(
|
|
35
|
+
this.info(chalk_1.default.dim('=== ') + chalk_1.default.bold(header) + '\n');
|
|
44
36
|
}
|
|
45
37
|
static get styledJSON() {
|
|
46
38
|
return styled.styledJSON;
|
|
@@ -62,16 +54,16 @@ class ux {
|
|
|
62
54
|
}
|
|
63
55
|
static trace(format, ...args) {
|
|
64
56
|
if (this.config.outputLevel === 'trace') {
|
|
65
|
-
stream_1.stdout.write(
|
|
57
|
+
stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
|
|
66
58
|
}
|
|
67
59
|
}
|
|
68
60
|
static debug(format, ...args) {
|
|
69
61
|
if (['trace', 'debug'].includes(this.config.outputLevel)) {
|
|
70
|
-
stream_1.stdout.write(
|
|
62
|
+
stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
65
|
static info(format, ...args) {
|
|
74
|
-
stream_1.stdout.write(
|
|
66
|
+
stream_1.stdout.write((0, node_util_1.format)(format, ...args) + '\n');
|
|
75
67
|
}
|
|
76
68
|
static log(format, ...args) {
|
|
77
69
|
this.info(format || '', ...args);
|
|
@@ -101,49 +93,29 @@ class ux {
|
|
|
101
93
|
}
|
|
102
94
|
exports.ux = ux;
|
|
103
95
|
ux.config = config_1.config;
|
|
104
|
-
const action = ux
|
|
96
|
+
const { action, annotation, anykey, confirm, debug, done, flush, info, log, progress, prompt, styledHeader, styledJSON, styledObject, table, trace, tree, url, wait, } = ux;
|
|
105
97
|
exports.action = action;
|
|
106
|
-
const annotation = ux.annotation;
|
|
107
98
|
exports.annotation = annotation;
|
|
108
|
-
const anykey = ux.anykey;
|
|
109
99
|
exports.anykey = anykey;
|
|
110
|
-
const confirm = ux.confirm;
|
|
111
100
|
exports.confirm = confirm;
|
|
112
|
-
const debug = ux.debug;
|
|
113
101
|
exports.debug = debug;
|
|
114
|
-
const done = ux.done;
|
|
115
102
|
exports.done = done;
|
|
116
|
-
const error = Errors.error;
|
|
117
|
-
exports.error = error;
|
|
118
|
-
const exit = Errors.exit;
|
|
119
|
-
exports.exit = exit;
|
|
120
|
-
const flush = ux.flush;
|
|
121
103
|
exports.flush = flush;
|
|
122
|
-
const info = ux.info;
|
|
123
104
|
exports.info = info;
|
|
124
|
-
const log = ux.log;
|
|
125
105
|
exports.log = log;
|
|
126
|
-
const progress = ux.progress;
|
|
127
106
|
exports.progress = progress;
|
|
128
|
-
const prompt = ux.prompt;
|
|
129
107
|
exports.prompt = prompt;
|
|
130
|
-
const styledHeader = ux.styledHeader;
|
|
131
108
|
exports.styledHeader = styledHeader;
|
|
132
|
-
const styledJSON = ux.styledJSON;
|
|
133
109
|
exports.styledJSON = styledJSON;
|
|
134
|
-
const styledObject = ux.styledObject;
|
|
135
110
|
exports.styledObject = styledObject;
|
|
136
|
-
const table = ux.table;
|
|
137
111
|
exports.table = table;
|
|
138
|
-
const trace = ux.trace;
|
|
139
112
|
exports.trace = trace;
|
|
140
|
-
const tree = ux.tree;
|
|
141
113
|
exports.tree = tree;
|
|
142
|
-
const url = ux.url;
|
|
143
114
|
exports.url = url;
|
|
144
|
-
const wait = ux.wait;
|
|
145
115
|
exports.wait = wait;
|
|
146
|
-
const warn = Errors
|
|
116
|
+
const { error, exit, warn } = Errors;
|
|
117
|
+
exports.error = error;
|
|
118
|
+
exports.exit = exit;
|
|
147
119
|
exports.warn = warn;
|
|
148
120
|
const uxProcessExitHandler = async () => {
|
|
149
121
|
try {
|
|
@@ -160,3 +132,12 @@ const uxListener = process.listeners('exit').find(fn => fn.name === uxProcessExi
|
|
|
160
132
|
if (!uxListener) {
|
|
161
133
|
process.once('exit', uxProcessExitHandler);
|
|
162
134
|
}
|
|
135
|
+
var exit_1 = require("./exit");
|
|
136
|
+
Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
|
137
|
+
var styled_1 = require("./styled");
|
|
138
|
+
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return styled_1.Table; } });
|
|
139
|
+
var base_1 = require("./action/base");
|
|
140
|
+
Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function () { return base_1.ActionBase; } });
|
|
141
|
+
var config_2 = require("./config");
|
|
142
|
+
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_2.config; } });
|
|
143
|
+
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_2.Config; } });
|
package/lib/cli-ux/list.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderList = void 0;
|
|
4
|
-
const screen_1 = require("../screen");
|
|
5
4
|
const util_1 = require("../util");
|
|
5
|
+
const screen_1 = require("../screen");
|
|
6
6
|
const wordwrap = require('wordwrap');
|
|
7
7
|
function linewrap(length, s) {
|
|
8
8
|
return wordwrap(length, screen_1.stdtermwidth, {
|
package/lib/cli-ux/prompt.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.anykey = exports.confirm = exports.prompt = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Errors = tslib_1.__importStar(require("../errors"));
|
|
6
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
5
7
|
const config_1 = require("./config");
|
|
6
|
-
const chalk = require("chalk");
|
|
7
8
|
const stream_1 = require("./stream");
|
|
8
9
|
function normal(options, retries = 100) {
|
|
9
10
|
if (retries < 0)
|
|
@@ -40,7 +41,7 @@ function getPrompt(name, type, defaultValue) {
|
|
|
40
41
|
defaultValue = '*'.repeat(defaultValue.length);
|
|
41
42
|
}
|
|
42
43
|
if (name && defaultValue)
|
|
43
|
-
prompt = name + ' ' +
|
|
44
|
+
prompt = name + ' ' + chalk_1.default.yellow('[' + defaultValue + ']') + ': ';
|
|
44
45
|
else if (name)
|
|
45
46
|
prompt = `${name}: `;
|
|
46
47
|
return prompt;
|
|
@@ -57,8 +58,8 @@ async function single(options) {
|
|
|
57
58
|
}
|
|
58
59
|
function replacePrompt(prompt) {
|
|
59
60
|
const ansiEscapes = require('ansi-escapes');
|
|
60
|
-
stream_1.stderr.write(ansiEscapes.cursorHide + ansiEscapes.cursorUp(1) + ansiEscapes.cursorLeft + prompt
|
|
61
|
-
ansiEscapes.cursorDown(1) + ansiEscapes.cursorLeft + ansiEscapes.cursorShow);
|
|
61
|
+
stream_1.stderr.write(ansiEscapes.cursorHide + ansiEscapes.cursorUp(1) + ansiEscapes.cursorLeft + prompt
|
|
62
|
+
+ ansiEscapes.cursorDown(1) + ansiEscapes.cursorLeft + ansiEscapes.cursorShow);
|
|
62
63
|
}
|
|
63
64
|
async function _prompt(name, inputOptions = {}) {
|
|
64
65
|
const prompt = getPrompt(name, inputOptions.type, inputOptions.default);
|
|
@@ -73,11 +74,13 @@ async function _prompt(name, inputOptions = {}) {
|
|
|
73
74
|
};
|
|
74
75
|
const passwordPrompt = require('password-prompt');
|
|
75
76
|
switch (options.type) {
|
|
76
|
-
case 'normal':
|
|
77
|
+
case 'normal': {
|
|
77
78
|
return normal(options);
|
|
78
|
-
|
|
79
|
+
}
|
|
80
|
+
case 'single': {
|
|
79
81
|
return single(options);
|
|
80
|
-
|
|
82
|
+
}
|
|
83
|
+
case 'mask': {
|
|
81
84
|
return passwordPrompt(options.prompt, {
|
|
82
85
|
method: options.type,
|
|
83
86
|
required: options.required,
|
|
@@ -86,14 +89,17 @@ async function _prompt(name, inputOptions = {}) {
|
|
|
86
89
|
replacePrompt(getPrompt(name, 'hide', inputOptions.default));
|
|
87
90
|
return value;
|
|
88
91
|
});
|
|
89
|
-
|
|
92
|
+
}
|
|
93
|
+
case 'hide': {
|
|
90
94
|
return passwordPrompt(options.prompt, {
|
|
91
95
|
method: options.type,
|
|
92
96
|
required: options.required,
|
|
93
97
|
default: options.default,
|
|
94
98
|
});
|
|
95
|
-
|
|
99
|
+
}
|
|
100
|
+
default: {
|
|
96
101
|
throw new Error(`unexpected type ${options.type}`);
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
@@ -103,9 +109,7 @@ async function _prompt(name, inputOptions = {}) {
|
|
|
103
109
|
* @returns Promise<string>
|
|
104
110
|
*/
|
|
105
111
|
async function prompt(name, options = {}) {
|
|
106
|
-
return config_1.
|
|
107
|
-
return _prompt(name, options);
|
|
108
|
-
}, chalk.cyan('?'));
|
|
112
|
+
return config_1.config.action.pauseAsync(() => _prompt(name, options), chalk_1.default.cyan('?'));
|
|
109
113
|
}
|
|
110
114
|
exports.prompt = prompt;
|
|
111
115
|
/**
|
|
@@ -114,9 +118,10 @@ exports.prompt = prompt;
|
|
|
114
118
|
* @returns Promise<boolean>
|
|
115
119
|
*/
|
|
116
120
|
function confirm(message) {
|
|
117
|
-
return config_1.
|
|
121
|
+
return config_1.config.action.pauseAsync(async () => {
|
|
118
122
|
const confirm = async () => {
|
|
119
|
-
const
|
|
123
|
+
const raw = await _prompt(message);
|
|
124
|
+
const response = raw.toLowerCase();
|
|
120
125
|
if (['n', 'no'].includes(response))
|
|
121
126
|
return false;
|
|
122
127
|
if (['y', 'yes'].includes(response))
|
|
@@ -124,7 +129,7 @@ function confirm(message) {
|
|
|
124
129
|
return confirm();
|
|
125
130
|
};
|
|
126
131
|
return confirm();
|
|
127
|
-
},
|
|
132
|
+
}, chalk_1.default.cyan('?'));
|
|
128
133
|
}
|
|
129
134
|
exports.confirm = confirm;
|
|
130
135
|
/**
|
|
@@ -135,9 +140,9 @@ exports.confirm = confirm;
|
|
|
135
140
|
async function anykey(message) {
|
|
136
141
|
const tty = Boolean(process.stdin.setRawMode);
|
|
137
142
|
if (!message) {
|
|
138
|
-
message = tty
|
|
139
|
-
`Press any key to continue or ${
|
|
140
|
-
`Press enter to continue or ${
|
|
143
|
+
message = tty
|
|
144
|
+
? `Press any key to continue or ${chalk_1.default.yellow('q')} to exit`
|
|
145
|
+
: `Press enter to continue or ${chalk_1.default.yellow('q')} to exit`;
|
|
141
146
|
}
|
|
142
147
|
const char = await prompt(message, { type: 'single', required: false });
|
|
143
148
|
if (tty)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { styledJSON, styledObject, Table, tree, progress, };
|
|
1
|
+
export * as Table from './table';
|
|
2
|
+
export { default as progress } from './progress';
|
|
3
|
+
export { default as styledJSON } from './json';
|
|
4
|
+
export { default as styledObject } from './object';
|
|
5
|
+
export { default as tree } from './tree';
|