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