@oclif/core 3.0.0-beta.9 → 3.0.0
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 +4 -2
- package/flush.d.ts +3 -0
- package/flush.js +1 -0
- package/handle.js +1 -0
- package/lib/args.d.ts +2 -2
- package/lib/args.js +17 -18
- package/lib/{ux → cli-ux}/action/base.d.ts +19 -21
- package/lib/{ux → cli-ux}/action/base.js +126 -120
- package/lib/{ux → cli-ux}/action/simple.js +25 -30
- package/lib/{ux → cli-ux}/action/spinner.d.ts +9 -7
- package/lib/{ux → cli-ux}/action/spinner.js +45 -37
- package/lib/{ux → cli-ux}/action/spinners.js +187 -187
- package/lib/cli-ux/action/types.d.ts +5 -0
- package/lib/cli-ux/action/types.js +2 -0
- package/lib/{ux → cli-ux}/config.d.ts +5 -5
- package/lib/{ux → cli-ux}/config.js +17 -17
- package/lib/{ux → cli-ux}/exit.js +3 -0
- package/lib/cli-ux/flush.d.ts +1 -0
- package/lib/cli-ux/flush.js +28 -0
- package/lib/cli-ux/index.d.ts +39 -0
- package/lib/{ux → cli-ux}/index.js +74 -88
- package/lib/{ux → cli-ux}/list.js +3 -3
- package/lib/{ux → cli-ux}/prompt.d.ts +3 -3
- package/lib/{ux → cli-ux}/prompt.js +35 -25
- package/lib/{ux → cli-ux}/stream.d.ts +6 -6
- package/lib/{ux → cli-ux}/stream.js +11 -10
- package/lib/cli-ux/styled/index.d.ts +4 -0
- package/lib/cli-ux/styled/index.js +11 -0
- package/lib/{ux → cli-ux}/styled/object.js +7 -9
- package/lib/{ux → cli-ux}/styled/table.d.ts +10 -10
- package/lib/{ux → cli-ux}/styled/table.js +130 -133
- package/lib/{ux → cli-ux}/styled/tree.js +11 -13
- package/lib/cli-ux/wait.js +5 -0
- package/lib/command.d.ts +82 -88
- package/lib/command.js +196 -175
- package/lib/config/config.d.ts +89 -90
- package/lib/config/config.js +466 -566
- package/lib/config/index.d.ts +0 -1
- package/lib/config/index.js +1 -3
- package/lib/config/plugin-loader.d.ts +12 -12
- package/lib/config/plugin-loader.js +72 -56
- package/lib/config/plugin.d.ts +25 -24
- package/lib/config/plugin.js +188 -154
- package/lib/config/ts-node.d.ts +2 -1
- package/lib/config/ts-node.js +71 -58
- package/lib/config/util.d.ts +1 -11
- package/lib/config/util.js +6 -59
- package/lib/errors/config.d.ts +1 -1
- package/lib/errors/config.js +6 -6
- package/lib/errors/errors/cli.d.ts +7 -7
- package/lib/errors/errors/cli.js +20 -16
- package/lib/errors/errors/exit.d.ts +1 -4
- package/lib/errors/errors/exit.js +1 -1
- package/lib/errors/errors/module-load.d.ts +1 -4
- package/lib/errors/errors/module-load.js +1 -1
- package/lib/errors/errors/pretty-print.d.ts +1 -1
- package/lib/errors/errors/pretty-print.js +12 -10
- package/lib/errors/handle.d.ts +12 -2
- package/lib/errors/handle.js +26 -14
- package/lib/errors/index.d.ts +10 -10
- package/lib/errors/index.js +25 -24
- package/lib/errors/logger.d.ts +2 -2
- package/lib/errors/logger.js +14 -13
- package/lib/execute.d.ts +6 -6
- package/lib/execute.js +10 -9
- package/lib/flags.d.ts +103 -32
- package/lib/flags.js +79 -45
- package/lib/help/command.d.ts +16 -14
- package/lib/help/command.js +178 -163
- package/lib/help/docopts.d.ts +5 -5
- package/lib/help/docopts.js +50 -54
- package/lib/help/formatter.d.ts +37 -37
- package/lib/help/formatter.js +66 -55
- package/lib/help/index.d.ts +25 -21
- package/lib/help/index.js +169 -147
- package/lib/help/root.d.ts +1 -1
- package/lib/help/root.js +15 -17
- package/lib/help/util.d.ts +2 -8
- package/lib/help/util.js +8 -28
- package/lib/index.d.ts +19 -20
- package/lib/index.js +37 -43
- package/lib/interfaces/config.d.ts +67 -66
- package/lib/interfaces/errors.d.ts +5 -5
- package/lib/interfaces/help.d.ts +17 -17
- package/lib/interfaces/hooks.d.ts +49 -49
- package/lib/interfaces/index.d.ts +7 -7
- package/lib/interfaces/manifest.d.ts +1 -1
- package/lib/interfaces/parser.d.ts +175 -51
- package/lib/interfaces/pjson.d.ts +41 -41
- package/lib/interfaces/plugin.d.ts +47 -41
- package/lib/interfaces/s3-manifest.d.ts +7 -7
- package/lib/interfaces/topic.d.ts +1 -1
- package/lib/interfaces/ts-config.d.ts +7 -7
- package/lib/main.d.ts +2 -2
- package/lib/main.js +16 -16
- package/lib/module-loader.d.ts +67 -77
- package/lib/module-loader.js +183 -150
- package/lib/parser/errors.d.ts +7 -7
- package/lib/parser/errors.js +29 -22
- package/lib/parser/help.js +5 -5
- package/lib/parser/index.js +2 -2
- package/lib/parser/parse.d.ts +9 -6
- package/lib/parser/parse.js +253 -221
- package/lib/parser/validate.js +53 -33
- package/lib/performance.d.ts +43 -32
- package/lib/performance.js +133 -91
- package/lib/screen.js +2 -2
- package/lib/settings.d.ts +11 -12
- package/lib/settings.js +2 -2
- 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} +7 -16
- package/lib/util/util.js +98 -0
- package/package.json +35 -37
- package/lib/util.js +0 -126
- package/lib/ux/flush.d.ts +0 -1
- package/lib/ux/flush.js +0 -27
- package/lib/ux/index.d.ts +0 -58
- package/lib/ux/styled/index.d.ts +0 -6
- package/lib/ux/styled/index.js +0 -13
- package/lib/ux/styled/json.d.ts +0 -1
- package/lib/ux/styled/json.js +0 -15
- package/lib/ux/wait.js +0 -7
- package/lib/{ux → cli-ux}/action/simple.d.ts +4 -4
- package/lib/{ux → cli-ux}/action/spinners.d.ts +117 -117
- package/lib/{ux → cli-ux}/exit.d.ts +2 -2
- package/lib/{ux → cli-ux}/list.d.ts +0 -0
- package/lib/{ux → cli-ux}/styled/object.d.ts +0 -0
- package/lib/{ux → cli-ux}/styled/progress.d.ts +0 -0
- package/lib/{ux → cli-ux}/styled/progress.js +0 -0
- package/lib/{ux → cli-ux}/styled/tree.d.ts +1 -1
- /package/lib/{ux → cli-ux}/wait.d.ts +0 -0
package/README.md
CHANGED
|
@@ -11,14 +11,16 @@ 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
|
=====
|
|
20
22
|
|
|
21
|
-
The [ux README](./src/ux/README.md) contains detailed usage examples of using the `ux` export.
|
|
23
|
+
The [ux README](./src/cli-ux/README.md) contains detailed usage examples of using the `ux` export.
|
|
22
24
|
|
|
23
25
|
Usage
|
|
24
26
|
=====
|
package/flush.d.ts
ADDED
package/flush.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/cli-ux/flush').flush
|
package/handle.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = async error => require('./lib/errors/handle').handle(error)
|
package/lib/args.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { URL } from 'url';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
3
|
import { Arg, ArgDefinition } from './interfaces/parser';
|
|
4
4
|
/**
|
|
5
5
|
* Create a custom arg.
|
|
@@ -21,8 +21,8 @@ import { Arg, ArgDefinition } from './interfaces/parser';
|
|
|
21
21
|
export declare function custom<T = string, P = Record<string, unknown>>(defaults: Partial<Arg<T, P>>): ArgDefinition<T, P>;
|
|
22
22
|
export declare const boolean: ArgDefinition<boolean, Record<string, unknown>>;
|
|
23
23
|
export declare const integer: ArgDefinition<number, {
|
|
24
|
-
min?: number | undefined;
|
|
25
24
|
max?: number | undefined;
|
|
25
|
+
min?: number | undefined;
|
|
26
26
|
}>;
|
|
27
27
|
export declare const directory: ArgDefinition<string, {
|
|
28
28
|
exists?: boolean | undefined;
|
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 node_url_1 = require("node:url");
|
|
5
|
+
const fs_1 = require("./util/fs");
|
|
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,35 +1,33 @@
|
|
|
1
|
+
import { Options } from './types';
|
|
1
2
|
export interface ITask {
|
|
2
3
|
action: string;
|
|
3
|
-
status: string | undefined;
|
|
4
4
|
active: boolean;
|
|
5
|
+
status: string | undefined;
|
|
5
6
|
}
|
|
6
|
-
export type ActionType = '
|
|
7
|
-
export interface Options {
|
|
8
|
-
stdout?: boolean;
|
|
9
|
-
}
|
|
7
|
+
export type ActionType = 'debug' | 'simple' | 'spinner';
|
|
10
8
|
export declare class ActionBase {
|
|
11
|
-
type: ActionType;
|
|
12
|
-
std: 'stdout' | 'stderr';
|
|
13
|
-
protected stdmocks?: ['stdout' | 'stderr', string[]][];
|
|
14
9
|
private stdmockOrigs;
|
|
10
|
+
std: 'stderr' | 'stdout';
|
|
11
|
+
protected stdmocks?: ['stderr' | 'stdout', string[]][];
|
|
12
|
+
type: ActionType;
|
|
13
|
+
protected _flushStdout(): void;
|
|
14
|
+
protected _pause(_?: string): void;
|
|
15
|
+
protected _resume(): void;
|
|
16
|
+
protected _start(_opts: Options): void;
|
|
17
|
+
protected _stdout(toggle: boolean): void;
|
|
18
|
+
protected _stop(_: string): void;
|
|
19
|
+
protected _updateStatus(_: string | undefined, __?: string): void;
|
|
20
|
+
protected _write(std: 'stderr' | 'stdout', s: string | string[]): void;
|
|
21
|
+
private get globals();
|
|
22
|
+
pause(fn: () => any, icon?: string): Promise<any>;
|
|
23
|
+
pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
|
|
15
24
|
start(action: string, status?: string, opts?: Options): void;
|
|
16
25
|
stop(msg?: string): void;
|
|
17
|
-
private get globals();
|
|
18
|
-
get task(): ITask | undefined;
|
|
19
|
-
set task(task: ITask | undefined);
|
|
20
26
|
protected get output(): string | undefined;
|
|
21
27
|
protected set output(output: string | undefined);
|
|
22
28
|
get running(): boolean;
|
|
23
29
|
get status(): string | undefined;
|
|
24
30
|
set status(status: string | undefined);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
protected _start(): void;
|
|
28
|
-
protected _stop(_: string): void;
|
|
29
|
-
protected _resume(): void;
|
|
30
|
-
protected _pause(_?: string): void;
|
|
31
|
-
protected _updateStatus(_: string | undefined, __?: string): void;
|
|
32
|
-
protected _stdout(toggle: boolean): void;
|
|
33
|
-
protected _flushStdout(): void;
|
|
34
|
-
protected _write(std: 'stdout' | 'stderr', s: string | string[]): void;
|
|
31
|
+
get task(): ITask | undefined;
|
|
32
|
+
set task(task: ITask | undefined);
|
|
35
33
|
}
|
|
@@ -1,112 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActionBase = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const node_util_1 = require("node:util");
|
|
5
|
+
const util_1 = require("../../util/util");
|
|
6
6
|
const stream_1 = require("../stream");
|
|
7
7
|
class ActionBase {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this._stdout(false);
|
|
32
|
-
}
|
|
33
|
-
get globals() {
|
|
34
|
-
global.ux = global.ux || {};
|
|
35
|
-
const globals = global.ux;
|
|
36
|
-
globals.action = globals.action || {};
|
|
37
|
-
return globals;
|
|
38
|
-
}
|
|
39
|
-
get task() {
|
|
40
|
-
return this.globals.action.task;
|
|
41
|
-
}
|
|
42
|
-
set task(task) {
|
|
43
|
-
this.globals.action.task = task;
|
|
44
|
-
}
|
|
45
|
-
get output() {
|
|
46
|
-
return this.globals.output;
|
|
47
|
-
}
|
|
48
|
-
set output(output) {
|
|
49
|
-
this.globals.output = output;
|
|
50
|
-
}
|
|
51
|
-
get running() {
|
|
52
|
-
return Boolean(this.task);
|
|
53
|
-
}
|
|
54
|
-
get status() {
|
|
55
|
-
return this.task ? this.task.status : undefined;
|
|
56
|
-
}
|
|
57
|
-
set status(status) {
|
|
58
|
-
const task = this.task;
|
|
59
|
-
if (!task) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (task.status === status) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this._updateStatus(status, task.status);
|
|
66
|
-
task.status = status;
|
|
67
|
-
}
|
|
68
|
-
async pauseAsync(fn, icon) {
|
|
69
|
-
const task = this.task;
|
|
70
|
-
const active = task && task.active;
|
|
71
|
-
if (task && active) {
|
|
72
|
-
this._pause(icon);
|
|
73
|
-
this._stdout(false);
|
|
74
|
-
task.active = false;
|
|
75
|
-
}
|
|
76
|
-
const ret = await fn();
|
|
77
|
-
if (task && active) {
|
|
78
|
-
this._resume();
|
|
79
|
-
}
|
|
80
|
-
return ret;
|
|
81
|
-
}
|
|
82
|
-
pause(fn, icon) {
|
|
83
|
-
const task = this.task;
|
|
84
|
-
const active = task && task.active;
|
|
85
|
-
if (task && active) {
|
|
86
|
-
this._pause(icon);
|
|
87
|
-
this._stdout(false);
|
|
88
|
-
task.active = false;
|
|
8
|
+
stdmockOrigs = {
|
|
9
|
+
stderr: stream_1.stderr.write,
|
|
10
|
+
stdout: stream_1.stdout.write,
|
|
11
|
+
};
|
|
12
|
+
std = 'stderr';
|
|
13
|
+
stdmocks;
|
|
14
|
+
type;
|
|
15
|
+
// flush mocked stdout/stderr
|
|
16
|
+
_flushStdout() {
|
|
17
|
+
try {
|
|
18
|
+
let output = '';
|
|
19
|
+
let std;
|
|
20
|
+
while (this.stdmocks && this.stdmocks.length > 0) {
|
|
21
|
+
const cur = this.stdmocks.shift();
|
|
22
|
+
std = cur[0];
|
|
23
|
+
this._write(std, cur[1]);
|
|
24
|
+
output += cur[1][0].toString('utf8');
|
|
25
|
+
}
|
|
26
|
+
// add newline if there isn't one already
|
|
27
|
+
// otherwise we'll just overwrite it when we render
|
|
28
|
+
if (output && std && output.at(-1) !== '\n') {
|
|
29
|
+
this._write(std, '\n');
|
|
30
|
+
}
|
|
89
31
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this._resume();
|
|
32
|
+
catch (error) {
|
|
33
|
+
this._write('stderr', (0, node_util_1.inspect)(error));
|
|
93
34
|
}
|
|
94
|
-
return ret;
|
|
95
35
|
}
|
|
96
|
-
|
|
97
|
-
throw new Error('not implemented');
|
|
98
|
-
}
|
|
99
|
-
_stop(_) {
|
|
36
|
+
_pause(_) {
|
|
100
37
|
throw new Error('not implemented');
|
|
101
38
|
}
|
|
102
39
|
_resume() {
|
|
103
40
|
if (this.task)
|
|
104
41
|
this.start(this.task.action, this.task.status);
|
|
105
42
|
}
|
|
106
|
-
|
|
43
|
+
_start(_opts) {
|
|
107
44
|
throw new Error('not implemented');
|
|
108
45
|
}
|
|
109
|
-
_updateStatus(_, __) { }
|
|
110
46
|
// mock out stdout/stderr so it doesn't screw up the rendering
|
|
111
47
|
_stdout(toggle) {
|
|
112
48
|
try {
|
|
@@ -114,8 +50,8 @@ class ActionBase {
|
|
|
114
50
|
if (this.stdmocks)
|
|
115
51
|
return;
|
|
116
52
|
this.stdmockOrigs = {
|
|
117
|
-
stdout: stream_1.stdout.write,
|
|
118
53
|
stderr: stream_1.stderr.write,
|
|
54
|
+
stdout: stream_1.stdout.write,
|
|
119
55
|
};
|
|
120
56
|
this.stdmocks = [];
|
|
121
57
|
stream_1.stdout.write = (...args) => {
|
|
@@ -137,42 +73,112 @@ class ActionBase {
|
|
|
137
73
|
}
|
|
138
74
|
}
|
|
139
75
|
catch (error) {
|
|
140
|
-
this._write('stderr', (0,
|
|
76
|
+
this._write('stderr', (0, node_util_1.inspect)(error));
|
|
141
77
|
}
|
|
142
78
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
while (this.stdmocks && this.stdmocks.length > 0) {
|
|
149
|
-
const cur = this.stdmocks.shift();
|
|
150
|
-
std = cur[0];
|
|
151
|
-
this._write(std, cur[1]);
|
|
152
|
-
output += cur[1][0].toString('utf8');
|
|
153
|
-
}
|
|
154
|
-
// add newline if there isn't one already
|
|
155
|
-
// otherwise we'll just overwrite it when we render
|
|
156
|
-
if (output && std && output[output.length - 1] !== '\n') {
|
|
157
|
-
this._write(std, '\n');
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
this._write('stderr', (0, util_1.inspect)(error));
|
|
162
|
-
}
|
|
79
|
+
_stop(_) {
|
|
80
|
+
throw new Error('not implemented');
|
|
81
|
+
}
|
|
82
|
+
_updateStatus(_, __) {
|
|
83
|
+
// Not implemented
|
|
163
84
|
}
|
|
164
85
|
// write to the real stdout/stderr
|
|
165
86
|
_write(std, s) {
|
|
166
87
|
switch (std) {
|
|
167
|
-
case 'stdout':
|
|
168
|
-
this.stdmockOrigs.stdout.apply(stream_1.stdout, (0,
|
|
88
|
+
case 'stdout': {
|
|
89
|
+
this.stdmockOrigs.stdout.apply(stream_1.stdout, (0, util_1.castArray)(s));
|
|
169
90
|
break;
|
|
170
|
-
|
|
171
|
-
|
|
91
|
+
}
|
|
92
|
+
case 'stderr': {
|
|
93
|
+
this.stdmockOrigs.stderr.apply(stream_1.stderr, (0, util_1.castArray)(s));
|
|
172
94
|
break;
|
|
173
|
-
|
|
95
|
+
}
|
|
96
|
+
default: {
|
|
174
97
|
throw new Error(`invalid std: ${std}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
get globals() {
|
|
102
|
+
;
|
|
103
|
+
global.ux = global.ux || {};
|
|
104
|
+
const globals = global.ux;
|
|
105
|
+
globals.action = globals.action || {};
|
|
106
|
+
return globals;
|
|
107
|
+
}
|
|
108
|
+
pause(fn, icon) {
|
|
109
|
+
const { task } = this;
|
|
110
|
+
const active = task && task.active;
|
|
111
|
+
if (task && active) {
|
|
112
|
+
this._pause(icon);
|
|
113
|
+
this._stdout(false);
|
|
114
|
+
task.active = false;
|
|
115
|
+
}
|
|
116
|
+
const ret = fn();
|
|
117
|
+
if (task && active) {
|
|
118
|
+
this._resume();
|
|
119
|
+
}
|
|
120
|
+
return ret;
|
|
121
|
+
}
|
|
122
|
+
async pauseAsync(fn, icon) {
|
|
123
|
+
const { task } = this;
|
|
124
|
+
const active = task && task.active;
|
|
125
|
+
if (task && active) {
|
|
126
|
+
this._pause(icon);
|
|
127
|
+
this._stdout(false);
|
|
128
|
+
task.active = false;
|
|
175
129
|
}
|
|
130
|
+
const ret = await fn();
|
|
131
|
+
if (task && active) {
|
|
132
|
+
this._resume();
|
|
133
|
+
}
|
|
134
|
+
return ret;
|
|
135
|
+
}
|
|
136
|
+
start(action, status, opts = {}) {
|
|
137
|
+
this.std = opts.stdout ? 'stdout' : 'stderr';
|
|
138
|
+
const task = { action, active: Boolean(this.task && this.task.active), status };
|
|
139
|
+
this.task = task;
|
|
140
|
+
this._start(opts);
|
|
141
|
+
task.active = true;
|
|
142
|
+
this._stdout(true);
|
|
143
|
+
}
|
|
144
|
+
stop(msg = 'done') {
|
|
145
|
+
const { task } = this;
|
|
146
|
+
if (!task) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this._stop(msg);
|
|
150
|
+
task.active = false;
|
|
151
|
+
this.task = undefined;
|
|
152
|
+
this._stdout(false);
|
|
153
|
+
}
|
|
154
|
+
get output() {
|
|
155
|
+
return this.globals.output;
|
|
156
|
+
}
|
|
157
|
+
set output(output) {
|
|
158
|
+
this.globals.output = output;
|
|
159
|
+
}
|
|
160
|
+
get running() {
|
|
161
|
+
return Boolean(this.task);
|
|
162
|
+
}
|
|
163
|
+
get status() {
|
|
164
|
+
return this.task ? this.task.status : undefined;
|
|
165
|
+
}
|
|
166
|
+
set status(status) {
|
|
167
|
+
const { task } = this;
|
|
168
|
+
if (!task) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (task.status === status) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this._updateStatus(status, task.status);
|
|
175
|
+
task.status = status;
|
|
176
|
+
}
|
|
177
|
+
get task() {
|
|
178
|
+
return this.globals.action.task;
|
|
179
|
+
}
|
|
180
|
+
set task(task) {
|
|
181
|
+
this.globals.action.task = task;
|
|
176
182
|
}
|
|
177
183
|
}
|
|
178
184
|
exports.ActionBase = ActionBase;
|
|
@@ -2,15 +2,10 @@
|
|
|
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
|
-
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
_start() {
|
|
10
|
-
const task = this.task;
|
|
11
|
-
if (!task)
|
|
12
|
-
return;
|
|
13
|
-
this._render(task.action, task.status);
|
|
5
|
+
type = 'simple';
|
|
6
|
+
_flush() {
|
|
7
|
+
this._write(this.std, '\n');
|
|
8
|
+
this._flushStdout();
|
|
14
9
|
}
|
|
15
10
|
_pause(icon) {
|
|
16
11
|
if (icon)
|
|
@@ -18,35 +13,35 @@ class SimpleAction extends base_1.ActionBase {
|
|
|
18
13
|
else
|
|
19
14
|
this._flush();
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const task = this.task;
|
|
24
|
-
if (!task)
|
|
16
|
+
_render(action, status) {
|
|
17
|
+
if (!this.task)
|
|
25
18
|
return;
|
|
26
|
-
if (task.active
|
|
27
|
-
this._write(this.std, ` ${status}`);
|
|
28
|
-
else
|
|
29
|
-
this._write(this.std, `${task.action}... ${status}`);
|
|
30
|
-
if (newline || !prevStatus)
|
|
19
|
+
if (this.task.active)
|
|
31
20
|
this._flush();
|
|
21
|
+
this._write(this.std, status ? `${action}... ${status}` : `${action}...`);
|
|
22
|
+
}
|
|
23
|
+
_resume() {
|
|
24
|
+
// Not implemented
|
|
25
|
+
}
|
|
26
|
+
_start() {
|
|
27
|
+
if (!this.task)
|
|
28
|
+
return;
|
|
29
|
+
this._render(this.task.action, this.task.status);
|
|
32
30
|
}
|
|
33
31
|
_stop(status) {
|
|
34
|
-
|
|
35
|
-
if (!task)
|
|
32
|
+
if (!this.task)
|
|
36
33
|
return;
|
|
37
|
-
this._updateStatus(status, task.status, true);
|
|
34
|
+
this._updateStatus(status, this.task.status, true);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (!task)
|
|
36
|
+
_updateStatus(status, prevStatus, newline = false) {
|
|
37
|
+
if (!this.task)
|
|
42
38
|
return;
|
|
43
|
-
if (task.active)
|
|
39
|
+
if (this.task.active && !prevStatus)
|
|
40
|
+
this._write(this.std, ` ${status}`);
|
|
41
|
+
else
|
|
42
|
+
this._write(this.std, `${this.task.action}... ${status}`);
|
|
43
|
+
if (newline || !prevStatus)
|
|
44
44
|
this._flush();
|
|
45
|
-
this._write(this.std, status ? `${action}... ${status}` : `${action}...`);
|
|
46
|
-
}
|
|
47
|
-
_flush() {
|
|
48
|
-
this._write(this.std, '\n');
|
|
49
|
-
this._flushStdout();
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
47
|
exports.default = SimpleAction;
|
|
@@ -1,16 +1,18 @@
|
|
|
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
|
-
type: ActionType;
|
|
5
|
-
spinner?: NodeJS.Timeout;
|
|
6
|
-
frames: any;
|
|
7
5
|
frameIndex: number;
|
|
6
|
+
frames: string[];
|
|
7
|
+
spinner?: NodeJS.Timeout;
|
|
8
|
+
type: ActionType;
|
|
8
9
|
constructor();
|
|
9
|
-
protected _start(): void;
|
|
10
|
-
protected _stop(status: string): void;
|
|
11
|
-
protected _pause(icon?: string): void;
|
|
12
10
|
protected _frame(): string;
|
|
11
|
+
private _lines;
|
|
12
|
+
protected _pause(icon?: string): void;
|
|
13
13
|
private _render;
|
|
14
14
|
private _reset;
|
|
15
|
-
|
|
15
|
+
protected _start(opts: Options): void;
|
|
16
|
+
protected _stop(status: string): void;
|
|
17
|
+
private getFrames;
|
|
16
18
|
}
|