1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Table = exports.ExitError = exports.Config = exports.ActionBase = exports.config = exports.cli = exports.ux = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const Errors = (0, tslib_1.__importStar)(require("@oclif/core/lib/errors"));
|
6 | const util = (0, tslib_1.__importStar)(require("util"));
|
7 | const base_1 = require("./action/base");
|
8 | Object.defineProperty(exports, "ActionBase", { enumerable: true, get: function () { return base_1.ActionBase; } });
|
9 | 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 deps_1 = (0, tslib_1.__importDefault)(require("./deps"));
|
13 | const exit_1 = require("./exit");
|
14 | Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
15 | const Table = (0, tslib_1.__importStar)(require("./styled/table"));
|
16 | exports.Table = Table;
|
17 | function timeout(p, ms) {
|
18 | function wait(ms, unref = false) {
|
19 | return new Promise(resolve => {
|
20 | const t = setTimeout(() => resolve(null), ms);
|
21 | if (unref)
|
22 | t.unref();
|
23 | });
|
24 | }
|
25 | return Promise.race([p, wait(ms, true).then(() => exports.ux.error('timed out'))]);
|
26 | }
|
27 | async function flush() {
|
28 | const p = new Promise(resolve => {
|
29 | process.stdout.once('drain', () => resolve(null));
|
30 | });
|
31 | process.stdout.write('');
|
32 | return p;
|
33 | }
|
34 | exports.ux = {
|
35 | config: config_1.config,
|
36 | warn: Errors.warn,
|
37 | error: Errors.error,
|
38 | exit: Errors.exit,
|
39 | get prompt() {
|
40 | return deps_1.default.prompt.prompt;
|
41 | },
|
42 | |
43 |
|
44 |
|
45 | get anykey() {
|
46 | return deps_1.default.prompt.anykey;
|
47 | },
|
48 | get confirm() {
|
49 | return deps_1.default.prompt.confirm;
|
50 | },
|
51 | get action() {
|
52 | return config_1.config.action;
|
53 | },
|
54 | get prideAction() {
|
55 | return config_1.config.prideAction;
|
56 | },
|
57 | styledObject(obj, keys) {
|
58 | exports.ux.info(deps_1.default.styledObject(obj, keys));
|
59 | },
|
60 | get styledHeader() {
|
61 | return deps_1.default.styledHeader;
|
62 | },
|
63 | get styledJSON() {
|
64 | return deps_1.default.styledJSON;
|
65 | },
|
66 | get table() {
|
67 | return deps_1.default.table;
|
68 | },
|
69 | get tree() {
|
70 | return deps_1.default.tree;
|
71 | },
|
72 | get open() {
|
73 | return deps_1.default.open;
|
74 | },
|
75 | get wait() {
|
76 | return deps_1.default.wait;
|
77 | },
|
78 | get progress() {
|
79 | return deps_1.default.progress;
|
80 | },
|
81 | async done() {
|
82 | config_1.config.action.stop();
|
83 |
|
84 | },
|
85 | trace(format, ...args) {
|
86 | if (this.config.outputLevel === 'trace') {
|
87 | process.stdout.write(util.format(format, ...args) + '\n');
|
88 | }
|
89 | },
|
90 | debug(format, ...args) {
|
91 | if (['trace', 'debug'].includes(this.config.outputLevel)) {
|
92 | process.stdout.write(util.format(format, ...args) + '\n');
|
93 | }
|
94 | },
|
95 | info(format, ...args) {
|
96 | process.stdout.write(util.format(format, ...args) + '\n');
|
97 | },
|
98 | log(format, ...args) {
|
99 | this.info(format || '', ...args);
|
100 | },
|
101 | url(text, uri, params = {}) {
|
102 | const supports = require('supports-hyperlinks');
|
103 | if (supports.stdout) {
|
104 | const hyperlinker = require('hyperlinker');
|
105 | this.log(hyperlinker(text, uri, params));
|
106 | }
|
107 | else {
|
108 | this.log(uri);
|
109 | }
|
110 | },
|
111 | annotation(text, annotation) {
|
112 | const supports = require('supports-hyperlinks');
|
113 | if (supports.stdout) {
|
114 |
|
115 | this.log(`\u001B]1337;AddAnnotation=${text.length}|${annotation}\u0007${text}`);
|
116 | }
|
117 | else {
|
118 | this.log(text);
|
119 | }
|
120 | },
|
121 | async flush() {
|
122 | await timeout(flush(), 10000);
|
123 | },
|
124 | };
|
125 | exports.default = exports.ux;
|
126 | exports.cli = exports.ux;
|
127 | const cliuxProcessExitHandler = async () => {
|
128 | try {
|
129 | await exports.ux.done();
|
130 | }
|
131 | catch (error) {
|
132 |
|
133 | console.error(error);
|
134 | process.exitCode = 1;
|
135 | }
|
136 | };
|
137 |
|
138 |
|
139 | const cliuxListener = process.listeners('exit').find(fn => fn.name === cliuxProcessExitHandler.name);
|
140 | if (!cliuxListener) {
|
141 | process.once('exit', cliuxProcessExitHandler);
|
142 | }
|