@oclif/core 3.0.0-beta.2 → 3.0.0-beta.20
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 +10 -6
- package/flush.js +1 -1
- package/handle.js +1 -1
- package/lib/args.d.ts +1 -1
- package/lib/args.js +17 -18
- package/lib/cli-ux/action/base.d.ts +3 -5
- package/lib/cli-ux/action/base.js +32 -26
- package/lib/cli-ux/action/simple.js +13 -18
- package/lib/cli-ux/action/spinner.d.ts +4 -2
- package/lib/cli-ux/action/spinner.js +27 -19
- package/lib/cli-ux/action/spinners.js +1 -1
- package/lib/cli-ux/action/types.d.ts +5 -0
- package/lib/cli-ux/action/types.js +2 -0
- package/lib/cli-ux/config.d.ts +0 -1
- package/lib/cli-ux/config.js +17 -21
- package/lib/cli-ux/exit.d.ts +1 -1
- package/lib/cli-ux/exit.js +4 -1
- package/lib/cli-ux/flush.d.ts +1 -0
- package/lib/cli-ux/flush.js +28 -0
- package/lib/cli-ux/index.d.ts +10 -30
- package/lib/cli-ux/index.js +32 -75
- package/lib/cli-ux/list.js +3 -3
- package/lib/cli-ux/prompt.js +32 -22
- package/lib/cli-ux/stream.js +1 -0
- 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 +8 -5
- package/lib/cli-ux/styled/object.js +7 -9
- package/lib/cli-ux/styled/table.d.ts +4 -4
- package/lib/cli-ux/styled/table.js +61 -64
- package/lib/cli-ux/styled/tree.js +1 -3
- package/lib/cli-ux/wait.js +3 -5
- package/lib/command.d.ts +15 -19
- package/lib/command.js +117 -96
- package/lib/config/config.d.ts +16 -23
- package/lib/config/config.js +180 -334
- package/lib/config/index.d.ts +1 -1
- package/lib/config/index.js +1 -2
- package/lib/config/plugin-loader.d.ts +30 -0
- package/lib/config/plugin-loader.js +145 -0
- package/lib/config/plugin.d.ts +6 -11
- package/lib/config/plugin.js +112 -78
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +64 -51
- package/lib/config/util.d.ts +1 -11
- package/lib/config/util.js +6 -59
- package/lib/errors/config.js +1 -1
- package/lib/errors/errors/cli.d.ts +1 -1
- package/lib/errors/errors/cli.js +18 -14
- package/lib/errors/errors/exit.d.ts +0 -3
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.d.ts +0 -3
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/errors/pretty-print.js +11 -9
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +28 -18
- package/lib/errors/index.d.ts +2 -2
- package/lib/errors/index.js +20 -19
- package/lib/errors/logger.js +9 -8
- package/lib/execute.d.ts +49 -0
- package/lib/execute.js +63 -0
- package/lib/flags.d.ts +102 -31
- package/lib/flags.js +81 -46
- package/lib/help/command.d.ts +2 -0
- package/lib/help/command.js +68 -53
- package/lib/help/docopts.js +9 -13
- package/lib/help/formatter.d.ts +1 -1
- package/lib/help/formatter.js +35 -24
- package/lib/help/index.d.ts +7 -3
- package/lib/help/index.js +77 -55
- package/lib/help/root.js +7 -9
- package/lib/help/util.d.ts +1 -7
- package/lib/help/util.js +8 -28
- package/lib/index.d.ts +19 -18
- package/lib/index.js +36 -48
- package/lib/interfaces/config.d.ts +30 -30
- package/lib/interfaces/errors.d.ts +1 -1
- package/lib/interfaces/hooks.d.ts +3 -3
- package/lib/interfaces/index.d.ts +14 -14
- package/lib/interfaces/parser.d.ts +188 -116
- package/lib/interfaces/pjson.d.ts +2 -1
- package/lib/interfaces/plugin.d.ts +10 -1
- package/lib/main.d.ts +0 -48
- package/lib/main.js +11 -66
- package/lib/module-loader.d.ts +68 -79
- package/lib/module-loader.js +183 -150
- package/lib/parser/errors.d.ts +3 -3
- package/lib/parser/errors.js +17 -10
- package/lib/parser/help.js +5 -5
- package/lib/parser/parse.d.ts +3 -0
- package/lib/parser/parse.js +114 -115
- package/lib/parser/validate.js +45 -25
- package/lib/performance.d.ts +5 -1
- package/lib/performance.js +40 -19
- package/lib/util/aggregate-flags.d.ts +2 -0
- package/lib/util/aggregate-flags.js +13 -0
- package/lib/util/cache-command.d.ts +3 -0
- package/lib/util/cache-command.js +109 -0
- package/lib/util/cache-default-value.d.ts +2 -0
- package/lib/util/cache-default-value.js +28 -0
- package/lib/util/ensure-arg-object.d.ts +12 -0
- package/lib/util/ensure-arg-object.js +14 -0
- package/lib/util/fs.d.ts +7 -0
- package/lib/util/fs.js +54 -0
- package/lib/util/os.d.ts +19 -0
- package/lib/util/os.js +28 -0
- package/lib/{util.d.ts → util/util.d.ts} +6 -15
- package/lib/util/util.js +98 -0
- package/package.json +32 -34
- package/lib/cli-ux/action/pride-spinner.d.ts +0 -4
- package/lib/cli-ux/action/pride-spinner.js +0 -30
- package/lib/util.js +0 -126
package/README.md
CHANGED
|
@@ -11,7 +11,11 @@ base library for oclif CLIs
|
|
|
11
11
|
Migrating
|
|
12
12
|
=====
|
|
13
13
|
|
|
14
|
-
See the [migration guide](./
|
|
14
|
+
See the [v3 migration guide](./guides/V3_MIGRATION.md) for an overview of breaking changes that occurred between v2 and v3.
|
|
15
|
+
|
|
16
|
+
See the [v2 migration guide](./guides/V2_MIGRATION.md) for an overview of breaking changes that occurred between v1 and v2.
|
|
17
|
+
|
|
18
|
+
Migrating from `@oclif/config` and `@oclif/command`? See the [v1 migration guide](./guides/PRE_CORE_MIGRATION.md).
|
|
15
19
|
|
|
16
20
|
CLI UX
|
|
17
21
|
=====
|
|
@@ -28,7 +32,7 @@ You can, however, use `@oclif/core` in a standalone script like this:
|
|
|
28
32
|
#!/usr/bin/env ts-node
|
|
29
33
|
|
|
30
34
|
import * as fs from 'fs'
|
|
31
|
-
import {Command, Flags} from '@oclif/core'
|
|
35
|
+
import {Command, Flags, flush, handle} from '@oclif/core'
|
|
32
36
|
|
|
33
37
|
class LS extends Command {
|
|
34
38
|
static description = 'List the files in a directory.'
|
|
@@ -50,10 +54,10 @@ class LS extends Command {
|
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
LS.run().then(() => {
|
|
54
|
-
|
|
55
|
-
}, () => {
|
|
56
|
-
|
|
57
|
+
LS.run().then(async () => {
|
|
58
|
+
await flush()
|
|
59
|
+
}, async (err) => {
|
|
60
|
+
await handle(err)
|
|
57
61
|
})
|
|
58
62
|
```
|
|
59
63
|
|
package/flush.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./lib').flush
|
|
1
|
+
module.exports = require('./lib/cli-ux/flush').flush
|
package/handle.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = error => require('./lib/errors/handle').handle(error)
|
|
1
|
+
module.exports = async error => require('./lib/errors/handle').handle(error)
|
package/lib/args.d.ts
CHANGED
package/lib/args.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
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
|
|
5
|
-
const
|
|
4
|
+
const fs_1 = require("./util/fs");
|
|
5
|
+
const node_url_1 = require("node:url");
|
|
6
|
+
const util_1 = require("./util/util");
|
|
6
7
|
function custom(defaults) {
|
|
7
|
-
return (options = {}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
};
|
|
8
|
+
return (options = {}) => ({
|
|
9
|
+
parse: async (i, _context, _opts) => i,
|
|
10
|
+
...defaults,
|
|
11
|
+
...options,
|
|
12
|
+
input: [],
|
|
13
|
+
type: 'option',
|
|
14
|
+
});
|
|
16
15
|
}
|
|
17
16
|
exports.custom = custom;
|
|
18
17
|
exports.boolean = custom({
|
|
19
18
|
parse: async (b) => Boolean(b) && (0, util_1.isNotFalsy)(b),
|
|
20
19
|
});
|
|
21
20
|
exports.integer = custom({
|
|
22
|
-
|
|
21
|
+
async parse(input, _, opts) {
|
|
23
22
|
if (!/^-?\d+$/.test(input))
|
|
24
23
|
throw new Error(`Expected an integer but received: ${input}`);
|
|
25
24
|
const num = Number.parseInt(input, 10);
|
|
@@ -31,16 +30,16 @@ exports.integer = custom({
|
|
|
31
30
|
},
|
|
32
31
|
});
|
|
33
32
|
exports.directory = custom({
|
|
34
|
-
|
|
33
|
+
async parse(input, _, opts) {
|
|
35
34
|
if (opts.exists)
|
|
36
|
-
return (0,
|
|
35
|
+
return (0, fs_1.dirExists)(input);
|
|
37
36
|
return input;
|
|
38
37
|
},
|
|
39
38
|
});
|
|
40
39
|
exports.file = custom({
|
|
41
|
-
|
|
40
|
+
async parse(input, _, opts) {
|
|
42
41
|
if (opts.exists)
|
|
43
|
-
return (0,
|
|
42
|
+
return (0, fs_1.fileExists)(input);
|
|
44
43
|
return input;
|
|
45
44
|
},
|
|
46
45
|
});
|
|
@@ -49,9 +48,9 @@ exports.file = custom({
|
|
|
49
48
|
* if the string is not a valid URL.
|
|
50
49
|
*/
|
|
51
50
|
exports.url = custom({
|
|
52
|
-
|
|
51
|
+
async parse(input) {
|
|
53
52
|
try {
|
|
54
|
-
return new
|
|
53
|
+
return new node_url_1.URL(input);
|
|
55
54
|
}
|
|
56
55
|
catch {
|
|
57
56
|
throw new Error(`Expected a valid url but received: ${input}`);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
+
import { Options } from './types';
|
|
1
2
|
export interface ITask {
|
|
2
3
|
action: string;
|
|
3
4
|
status: string | undefined;
|
|
4
5
|
active: boolean;
|
|
5
6
|
}
|
|
6
7
|
export type ActionType = 'spinner' | 'simple' | 'debug';
|
|
7
|
-
export interface Options {
|
|
8
|
-
stdout?: boolean;
|
|
9
|
-
}
|
|
10
8
|
export declare class ActionBase {
|
|
11
9
|
type: ActionType;
|
|
12
10
|
std: 'stdout' | 'stderr';
|
|
@@ -22,9 +20,9 @@ export declare class ActionBase {
|
|
|
22
20
|
get running(): boolean;
|
|
23
21
|
get status(): string | undefined;
|
|
24
22
|
set status(status: string | undefined);
|
|
25
|
-
pauseAsync<T
|
|
23
|
+
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
|
26
24
|
pause(fn: () => any, icon?: string): Promise<any>;
|
|
27
|
-
protected _start(): void;
|
|
25
|
+
protected _start(_opts: Options): void;
|
|
28
26
|
protected _stop(_: string): void;
|
|
29
27
|
protected _resume(): void;
|
|
30
28
|
protected _pause(_?: string): void;
|
|
@@ -1,27 +1,27 @@
|
|
|
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/util");
|
|
6
|
+
const node_util_1 = require("node:util");
|
|
7
7
|
class ActionBase {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
8
|
+
type;
|
|
9
|
+
std = 'stderr';
|
|
10
|
+
stdmocks;
|
|
11
|
+
stdmockOrigs = {
|
|
12
|
+
stdout: stream_1.stdout.write,
|
|
13
|
+
stderr: stream_1.stderr.write,
|
|
14
|
+
};
|
|
15
15
|
start(action, status, opts = {}) {
|
|
16
16
|
this.std = opts.stdout ? 'stdout' : 'stderr';
|
|
17
17
|
const task = { action, status, active: Boolean(this.task && this.task.active) };
|
|
18
18
|
this.task = task;
|
|
19
|
-
this._start();
|
|
19
|
+
this._start(opts);
|
|
20
20
|
task.active = true;
|
|
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
|
}
|
|
@@ -31,8 +31,9 @@ class ActionBase {
|
|
|
31
31
|
this._stdout(false);
|
|
32
32
|
}
|
|
33
33
|
get globals() {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
;
|
|
35
|
+
global.ux = global.ux || {};
|
|
36
|
+
const globals = global.ux;
|
|
36
37
|
globals.action = globals.action || {};
|
|
37
38
|
return globals;
|
|
38
39
|
}
|
|
@@ -55,7 +56,7 @@ class ActionBase {
|
|
|
55
56
|
return this.task ? this.task.status : undefined;
|
|
56
57
|
}
|
|
57
58
|
set status(status) {
|
|
58
|
-
const task = this
|
|
59
|
+
const { task } = this;
|
|
59
60
|
if (!task) {
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
@@ -66,7 +67,7 @@ class ActionBase {
|
|
|
66
67
|
task.status = status;
|
|
67
68
|
}
|
|
68
69
|
async pauseAsync(fn, icon) {
|
|
69
|
-
const task = this
|
|
70
|
+
const { task } = this;
|
|
70
71
|
const active = task && task.active;
|
|
71
72
|
if (task && active) {
|
|
72
73
|
this._pause(icon);
|
|
@@ -80,7 +81,7 @@ class ActionBase {
|
|
|
80
81
|
return ret;
|
|
81
82
|
}
|
|
82
83
|
pause(fn, icon) {
|
|
83
|
-
const task = this
|
|
84
|
+
const { task } = this;
|
|
84
85
|
const active = task && task.active;
|
|
85
86
|
if (task && active) {
|
|
86
87
|
this._pause(icon);
|
|
@@ -93,7 +94,7 @@ class ActionBase {
|
|
|
93
94
|
}
|
|
94
95
|
return ret;
|
|
95
96
|
}
|
|
96
|
-
_start() {
|
|
97
|
+
_start(_opts) {
|
|
97
98
|
throw new Error('not implemented');
|
|
98
99
|
}
|
|
99
100
|
_stop(_) {
|
|
@@ -106,7 +107,9 @@ class ActionBase {
|
|
|
106
107
|
_pause(_) {
|
|
107
108
|
throw new Error('not implemented');
|
|
108
109
|
}
|
|
109
|
-
_updateStatus(_, __) {
|
|
110
|
+
_updateStatus(_, __) {
|
|
111
|
+
// Not implemented
|
|
112
|
+
}
|
|
110
113
|
// mock out stdout/stderr so it doesn't screw up the rendering
|
|
111
114
|
_stdout(toggle) {
|
|
112
115
|
try {
|
|
@@ -137,7 +140,7 @@ class ActionBase {
|
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
catch (error) {
|
|
140
|
-
this._write('stderr', (0,
|
|
143
|
+
this._write('stderr', (0, node_util_1.inspect)(error));
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
// flush mocked stdout/stderr
|
|
@@ -153,25 +156,28 @@ class ActionBase {
|
|
|
153
156
|
}
|
|
154
157
|
// add newline if there isn't one already
|
|
155
158
|
// otherwise we'll just overwrite it when we render
|
|
156
|
-
if (output && std && output
|
|
159
|
+
if (output && std && output.at(-1) !== '\n') {
|
|
157
160
|
this._write(std, '\n');
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
163
|
catch (error) {
|
|
161
|
-
this._write('stderr', (0,
|
|
164
|
+
this._write('stderr', (0, node_util_1.inspect)(error));
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
167
|
// write to the real stdout/stderr
|
|
165
168
|
_write(std, s) {
|
|
166
169
|
switch (std) {
|
|
167
|
-
case 'stdout':
|
|
168
|
-
this.stdmockOrigs.stdout.apply(stream_1.stdout, (0,
|
|
170
|
+
case 'stdout': {
|
|
171
|
+
this.stdmockOrigs.stdout.apply(stream_1.stdout, (0, util_1.castArray)(s));
|
|
169
172
|
break;
|
|
170
|
-
|
|
171
|
-
|
|
173
|
+
}
|
|
174
|
+
case 'stderr': {
|
|
175
|
+
this.stdmockOrigs.stderr.apply(stream_1.stderr, (0, util_1.castArray)(s));
|
|
172
176
|
break;
|
|
173
|
-
|
|
177
|
+
}
|
|
178
|
+
default: {
|
|
174
179
|
throw new Error(`invalid std: ${std}`);
|
|
180
|
+
}
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
183
|
}
|
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const base_1 = require("./base");
|
|
4
4
|
class SimpleAction extends base_1.ActionBase {
|
|
5
|
-
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.type = 'simple';
|
|
8
|
-
}
|
|
5
|
+
type = 'simple';
|
|
9
6
|
_start() {
|
|
10
|
-
|
|
11
|
-
if (!task)
|
|
7
|
+
if (!this.task)
|
|
12
8
|
return;
|
|
13
|
-
this._render(task.action, task.status);
|
|
9
|
+
this._render(this.task.action, this.task.status);
|
|
14
10
|
}
|
|
15
11
|
_pause(icon) {
|
|
16
12
|
if (icon)
|
|
@@ -18,29 +14,28 @@ class SimpleAction extends base_1.ActionBase {
|
|
|
18
14
|
else
|
|
19
15
|
this._flush();
|
|
20
16
|
}
|
|
21
|
-
_resume() {
|
|
17
|
+
_resume() {
|
|
18
|
+
// Not implemented
|
|
19
|
+
}
|
|
22
20
|
_updateStatus(status, prevStatus, newline = false) {
|
|
23
|
-
|
|
24
|
-
if (!task)
|
|
21
|
+
if (!this.task)
|
|
25
22
|
return;
|
|
26
|
-
if (task.active && !prevStatus)
|
|
23
|
+
if (this.task.active && !prevStatus)
|
|
27
24
|
this._write(this.std, ` ${status}`);
|
|
28
25
|
else
|
|
29
|
-
this._write(this.std, `${task.action}... ${status}`);
|
|
26
|
+
this._write(this.std, `${this.task.action}... ${status}`);
|
|
30
27
|
if (newline || !prevStatus)
|
|
31
28
|
this._flush();
|
|
32
29
|
}
|
|
33
30
|
_stop(status) {
|
|
34
|
-
|
|
35
|
-
if (!task)
|
|
31
|
+
if (!this.task)
|
|
36
32
|
return;
|
|
37
|
-
this._updateStatus(status, task.status, true);
|
|
33
|
+
this._updateStatus(status, this.task.status, true);
|
|
38
34
|
}
|
|
39
35
|
_render(action, status) {
|
|
40
|
-
|
|
41
|
-
if (!task)
|
|
36
|
+
if (!this.task)
|
|
42
37
|
return;
|
|
43
|
-
if (task.active)
|
|
38
|
+
if (this.task.active)
|
|
44
39
|
this._flush();
|
|
45
40
|
this._write(this.std, status ? `${action}... ${status}` : `${action}...`);
|
|
46
41
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ActionBase, ActionType } from './base';
|
|
3
|
+
import { Options } from './types';
|
|
3
4
|
export default class SpinnerAction extends ActionBase {
|
|
4
5
|
type: ActionType;
|
|
5
6
|
spinner?: NodeJS.Timeout;
|
|
6
|
-
frames:
|
|
7
|
+
frames: string[];
|
|
7
8
|
frameIndex: number;
|
|
8
9
|
constructor();
|
|
9
|
-
protected _start(): void;
|
|
10
|
+
protected _start(opts: Options): void;
|
|
10
11
|
protected _stop(status: string): void;
|
|
11
12
|
protected _pause(icon?: string): void;
|
|
12
13
|
protected _frame(): string;
|
|
14
|
+
private getFrames;
|
|
13
15
|
private _render;
|
|
14
16
|
private _reset;
|
|
15
17
|
private _lines;
|
|
@@ -1,32 +1,38 @@
|
|
|
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 ansiEscapes = require('ansi-escapes');
|
|
8
|
-
const screen_1 = require("../../screen");
|
|
9
|
-
const spinners_1 = require("./spinners");
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const supportsColor = tslib_1.__importStar(require("supports-color"));
|
|
10
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"));
|
|
11
|
+
const ansiEscapes = require('ansi-escapes');
|
|
11
12
|
function color(s) {
|
|
12
13
|
if (!supportsColor)
|
|
13
14
|
return s;
|
|
14
15
|
const has256 = supportsColor.stdout ? supportsColor.stdout.has256 : (process.env.TERM || '').includes('256');
|
|
15
|
-
return has256 ? `\u001B[38;5;104m${s}${
|
|
16
|
+
return has256 ? `\u001B[38;5;104m${s}${ansi_styles_1.default.reset.open}` : chalk_1.default.magenta(s);
|
|
16
17
|
}
|
|
17
18
|
class SpinnerAction extends base_1.ActionBase {
|
|
19
|
+
type = 'spinner';
|
|
20
|
+
spinner;
|
|
21
|
+
frames;
|
|
22
|
+
frameIndex;
|
|
18
23
|
constructor() {
|
|
19
24
|
super();
|
|
20
|
-
this.
|
|
21
|
-
this.frames = spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
|
|
25
|
+
this.frames = this.getFrames();
|
|
22
26
|
this.frameIndex = 0;
|
|
23
27
|
}
|
|
24
|
-
_start() {
|
|
28
|
+
_start(opts) {
|
|
29
|
+
if (opts.style)
|
|
30
|
+
this.frames = this.getFrames(opts);
|
|
25
31
|
this._reset();
|
|
26
32
|
if (this.spinner)
|
|
27
33
|
clearInterval(this.spinner);
|
|
28
34
|
this._render();
|
|
29
|
-
this.spinner = setInterval(icon => this._render.bind(this)(icon), process.platform === 'win32' ? 500 : 100, 'spinner');
|
|
35
|
+
this.spinner = setInterval((icon) => this._render.bind(this)(icon), process.platform === 'win32' ? 500 : 100, 'spinner');
|
|
30
36
|
const interval = this.spinner;
|
|
31
37
|
interval.unref();
|
|
32
38
|
}
|
|
@@ -51,15 +57,19 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
51
57
|
this.frameIndex = ++this.frameIndex % this.frames.length;
|
|
52
58
|
return color(frame);
|
|
53
59
|
}
|
|
60
|
+
getFrames(opts) {
|
|
61
|
+
if (opts?.style)
|
|
62
|
+
return spinners_1.default[opts.style].frames;
|
|
63
|
+
return spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
|
|
64
|
+
}
|
|
54
65
|
_render(icon) {
|
|
55
|
-
|
|
56
|
-
if (!task)
|
|
66
|
+
if (!this.task)
|
|
57
67
|
return;
|
|
58
68
|
this._reset();
|
|
59
69
|
this._flushStdout();
|
|
60
70
|
const frame = icon === 'spinner' ? ` ${this._frame()}` : icon || '';
|
|
61
|
-
const status = task.status ? ` ${task.status}` : '';
|
|
62
|
-
this.output = `${task.action}...${frame}${status}\n`;
|
|
71
|
+
const status = this.task.status ? ` ${this.task.status}` : '';
|
|
72
|
+
this.output = `${this.task.action}...${frame}${status}\n`;
|
|
63
73
|
this._write(this.std, this.output);
|
|
64
74
|
}
|
|
65
75
|
_reset() {
|
|
@@ -70,9 +80,7 @@ class SpinnerAction extends base_1.ActionBase {
|
|
|
70
80
|
this.output = undefined;
|
|
71
81
|
}
|
|
72
82
|
_lines(s) {
|
|
73
|
-
return
|
|
74
|
-
.map(l => Math.ceil(l.length / screen_1.errtermwidth))
|
|
75
|
-
.reduce((c, i) => c + i, 0);
|
|
83
|
+
return (0, strip_ansi_1.default)(s).split('\n').map((l) => Math.ceil(l.length / screen_1.errtermwidth)).reduce((c, i) => c + i, 0);
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
exports.default = SpinnerAction;
|
package/lib/cli-ux/config.d.ts
CHANGED
package/lib/cli-ux/config.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.config = exports.Config = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const pride_spinner_1 = require("./action/pride-spinner");
|
|
9
|
-
const version = semver.parse((0, util_1.requireJson)(__dirname, '..', '..', 'package.json').version);
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("../util/fs");
|
|
6
|
+
const simple_1 = tslib_1.__importDefault(require("./action/simple"));
|
|
7
|
+
const spinner_1 = tslib_1.__importDefault(require("./action/spinner"));
|
|
10
8
|
const g = global;
|
|
11
|
-
const globals = g
|
|
9
|
+
const globals = g.ux || (g.ux = {});
|
|
12
10
|
const actionType = (Boolean(process.stderr.isTTY) &&
|
|
13
11
|
!process.env.CI &&
|
|
14
12
|
!['dumb', 'emacs-color'].includes(process.env.TERM) &&
|
|
15
|
-
'spinner') ||
|
|
16
|
-
|
|
17
|
-
const
|
|
13
|
+
'spinner') ||
|
|
14
|
+
'simple';
|
|
15
|
+
const Action = actionType === 'spinner' ? spinner_1.default : simple_1.default;
|
|
18
16
|
class Config {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.errorsHandled = false;
|
|
24
|
-
this.showStackTrace = true;
|
|
25
|
-
}
|
|
17
|
+
outputLevel = 'info';
|
|
18
|
+
action = new Action();
|
|
19
|
+
errorsHandled = false;
|
|
20
|
+
showStackTrace = true;
|
|
26
21
|
get debug() {
|
|
27
22
|
return globals.debug || process.env.DEBUG === '*';
|
|
28
23
|
}
|
|
@@ -38,10 +33,11 @@ class Config {
|
|
|
38
33
|
}
|
|
39
34
|
exports.Config = Config;
|
|
40
35
|
function fetch() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
const major = (0, fs_1.requireJson)(__dirname, '..', '..', 'package.json').version.split('.')[0];
|
|
37
|
+
if (globals[major])
|
|
38
|
+
return globals[major];
|
|
39
|
+
globals[major] = new Config();
|
|
40
|
+
return globals[major];
|
|
45
41
|
}
|
|
46
42
|
exports.config = fetch();
|
|
47
43
|
exports.default = exports.config;
|
package/lib/cli-ux/exit.d.ts
CHANGED
package/lib/cli-ux/exit.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExitError = void 0;
|
|
4
4
|
class ExitError extends Error {
|
|
5
|
+
ux;
|
|
6
|
+
code;
|
|
7
|
+
error;
|
|
5
8
|
constructor(status, error) {
|
|
6
9
|
const code = 'EEXIT';
|
|
7
10
|
super(error ? error.message : `${code}: ${status}`);
|
|
8
11
|
this.error = error;
|
|
9
|
-
this
|
|
12
|
+
this.ux = { exit: status };
|
|
10
13
|
this.code = code;
|
|
11
14
|
}
|
|
12
15
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function flush(ms?: number): Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flush = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const stream_1 = require("./stream");
|
|
6
|
+
function timeout(p, ms) {
|
|
7
|
+
function wait(ms, unref = false) {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
const t = setTimeout(() => resolve(null), ms);
|
|
10
|
+
if (unref)
|
|
11
|
+
t.unref();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return Promise.race([p, wait(ms, true).then(() => (0, errors_1.error)('timed out'))]);
|
|
15
|
+
}
|
|
16
|
+
async function _flush() {
|
|
17
|
+
const p = new Promise((resolve) => {
|
|
18
|
+
stream_1.stdout.once('drain', () => resolve(null));
|
|
19
|
+
});
|
|
20
|
+
const flushed = stream_1.stdout.write('');
|
|
21
|
+
if (flushed)
|
|
22
|
+
return;
|
|
23
|
+
return p;
|
|
24
|
+
}
|
|
25
|
+
async function flush(ms = 10000) {
|
|
26
|
+
await timeout(_flush(), ms);
|
|
27
|
+
}
|
|
28
|
+
exports.flush = flush;
|
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;
|
|
@@ -16,7 +13,6 @@ export declare class ux {
|
|
|
16
13
|
static get anykey(): typeof uxPrompt.anykey;
|
|
17
14
|
static get confirm(): typeof uxPrompt.confirm;
|
|
18
15
|
static get action(): ActionBase;
|
|
19
|
-
static get prideAction(): ActionBase;
|
|
20
16
|
static styledObject(obj: any, keys?: string[]): void;
|
|
21
17
|
static styledHeader(header: string): void;
|
|
22
18
|
static get styledJSON(): typeof styled.styledJSON;
|
|
@@ -33,27 +29,11 @@ export declare class ux {
|
|
|
33
29
|
static annotation(text: string, annotation: string): void;
|
|
34
30
|
static flush(ms?: number): Promise<void>;
|
|
35
31
|
}
|
|
36
|
-
declare const action: ActionBase
|
|
37
|
-
declare const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
declare const flush: typeof ux.flush;
|
|
45
|
-
declare const info: typeof ux.info;
|
|
46
|
-
declare const log: typeof ux.log;
|
|
47
|
-
declare const prideAction: ActionBase;
|
|
48
|
-
declare const progress: typeof styled.progress;
|
|
49
|
-
declare const prompt: typeof uxPrompt.prompt;
|
|
50
|
-
declare const styledHeader: typeof ux.styledHeader;
|
|
51
|
-
declare const styledJSON: typeof styled.styledJSON;
|
|
52
|
-
declare const styledObject: typeof ux.styledObject;
|
|
53
|
-
declare const table: typeof styled.Table.table;
|
|
54
|
-
declare const trace: typeof ux.trace;
|
|
55
|
-
declare const tree: typeof styled.tree;
|
|
56
|
-
declare const url: typeof ux.url;
|
|
57
|
-
declare const wait: (ms?: number) => Promise<void>;
|
|
58
|
-
declare const warn: typeof Errors.warn;
|
|
59
|
-
export { action, ActionBase, annotation, anykey, config, Config, confirm, debug, done, error, exit, ExitError, flush, info, IPromptOptions, log, prideAction, 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';
|