bdy 1.22.25-dev-pipeline → 1.22.25-master
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/distTs/package.json +1 -1
- package/distTs/src/api/client.js +2 -110
- package/distTs/src/command/pipeline/run/start.js +14 -6
- package/distTs/src/command/pipeline/run.js +125 -22
- package/distTs/src/command/pipeline.js +0 -26
- package/distTs/src/command/pre.js +1 -1
- package/distTs/src/command/project/get.js +18 -0
- package/distTs/src/command/project/link.js +11 -11
- package/distTs/src/command/project/set.js +31 -0
- package/distTs/src/command/sandbox/get/yaml.js +30 -0
- package/distTs/src/command/vt/scrape.js +193 -0
- package/distTs/src/input.js +15 -61
- package/distTs/src/output/pipeline.js +14 -7
- package/distTs/src/output.js +32 -156
- package/distTs/src/texts.js +169 -217
- package/distTs/src/tunnel/output/interactive/tunnel.js +2 -2
- package/distTs/src/tunnel/server/sftp.js +38 -9
- package/distTs/src/tunnel/tunnel.js +0 -24
- package/package.json +1 -1
- package/distTs/src/command/pipeline/run/apply.js +0 -62
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const texts_1 = require("../../texts");
|
|
9
|
+
const validation_1 = require("../../visualTest/validation");
|
|
10
|
+
const output_1 = __importDefault(require("../../output"));
|
|
11
|
+
const requests_1 = require("../../visualTest/requests");
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const node_zlib_1 = require("node:zlib");
|
|
14
|
+
const tar_stream_1 = __importDefault(require("tar-stream"));
|
|
15
|
+
const promises_1 = require("node:stream/promises");
|
|
16
|
+
const node_fs_1 = require("node:fs");
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const promises_2 = require("node:fs/promises");
|
|
19
|
+
const commandScrape = (0, utils_1.newCommand)('scrape', texts_1.DESC_COMMAND_VT_SCRAPE);
|
|
20
|
+
commandScrape.argument('<url>', texts_1.OPTION_SCRAPE_URL);
|
|
21
|
+
commandScrape.option('--follow', texts_1.OPTION_SCRAPE_FOLLOW, false);
|
|
22
|
+
commandScrape.addOption(new commander_1.Option('--outputType <type>', texts_1.OPTION_SCRAPE_OUTPUT_TYPE)
|
|
23
|
+
.choices(['jpeg', 'png', 'md', 'html'])
|
|
24
|
+
.makeOptionMandatory());
|
|
25
|
+
commandScrape.option('--quality <quality>', texts_1.OPTION_SCRAPE_QUALITY);
|
|
26
|
+
commandScrape.option('--fullPage', texts_1.OPTION_SCRAPE_FULL_PAGE, false);
|
|
27
|
+
commandScrape.option('--cssSelector <selector>', texts_1.OPTION_SCRAPE_CSS_SELECTOR);
|
|
28
|
+
commandScrape.option('--xpathSelector <selector>', texts_1.OPTION_SCRAPE_XPATH_SELECTOR);
|
|
29
|
+
commandScrape.addOption(new commander_1.Option('--browser <browser>', texts_1.OPTION_SCRAPE_BROWSER)
|
|
30
|
+
.choices(['chrome', 'firefox', 'safari'])
|
|
31
|
+
.default('chrome'));
|
|
32
|
+
commandScrape.option('--viewport <viewport>', texts_1.OPTION_SCRAPE_VIEWPORT, '1920x1080');
|
|
33
|
+
commandScrape.option('--devicePixelRatio <ratio>', texts_1.OPTION_SCRAPE_DEVICE_PIXEL_RATIO, '1');
|
|
34
|
+
commandScrape.option('--waitForElement <selector>', texts_1.OPTION_SCRAPE_WAIT_FOR_ELEMENT);
|
|
35
|
+
commandScrape.option('--darkMode', texts_1.OPTION_SCRAPE_DARK_MODE, false);
|
|
36
|
+
commandScrape.option('--delay <delay>', texts_1.OPTION_SCRAPE_DELAY, '0');
|
|
37
|
+
commandScrape.option('--outputDir <dir>', texts_1.OPTION_SCRAPE_OUTPUT_DIR, '.');
|
|
38
|
+
commandScrape.action(async (inputUrl, options) => {
|
|
39
|
+
if (!(0, validation_1.checkToken)()) {
|
|
40
|
+
output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
|
|
41
|
+
}
|
|
42
|
+
const { url, follow, outputType, quality, outputDir, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement, } = validateInputAndOptions(inputUrl, options);
|
|
43
|
+
try {
|
|
44
|
+
const { buildId } = await (0, requests_1.sendScrap)(url, outputType, follow, quality, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement);
|
|
45
|
+
output_1.default.normal('Starting scrape session');
|
|
46
|
+
const status = await watchSessionStatus(buildId);
|
|
47
|
+
if (!status.ok) {
|
|
48
|
+
output_1.default.exitError(`Unexpected error while watching session status: ${status.error}`);
|
|
49
|
+
}
|
|
50
|
+
output_1.default.normal('Downloading scrape package');
|
|
51
|
+
const scrapPackageStream = await (0, requests_1.downloadScrapPackage)(buildId);
|
|
52
|
+
const brotliDecompressor = (0, node_zlib_1.createBrotliDecompress)();
|
|
53
|
+
const unpack = tar_stream_1.default.extract();
|
|
54
|
+
unpack.on('entry', async (header, stream, next) => {
|
|
55
|
+
const currentDir = process.cwd();
|
|
56
|
+
const preparedOutputDir = outputDir.startsWith('.')
|
|
57
|
+
? node_path_1.default.join(currentDir, outputDir)
|
|
58
|
+
: outputDir;
|
|
59
|
+
const newFilePath = node_path_1.default.join(preparedOutputDir, header.name);
|
|
60
|
+
try {
|
|
61
|
+
if (header.type === 'file') {
|
|
62
|
+
await (0, promises_2.mkdir)(node_path_1.default.dirname(newFilePath), { recursive: true });
|
|
63
|
+
const fileWriteStream = (0, node_fs_1.createWriteStream)(newFilePath);
|
|
64
|
+
await (0, promises_1.pipeline)(stream, fileWriteStream);
|
|
65
|
+
next();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
stream.resume();
|
|
69
|
+
next();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (entryError) {
|
|
73
|
+
output_1.default.error(`Error processing entry ${header.name}: ${entryError}`);
|
|
74
|
+
next(entryError);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
await (0, promises_1.pipeline)(scrapPackageStream, brotliDecompressor, unpack);
|
|
78
|
+
output_1.default.exitSuccess('Downloading scrape package finished');
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
output_1.default.exitError(`${error}`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
function validateInputAndOptions(input, options) {
|
|
85
|
+
const urlSchema = zod_1.z.string().url();
|
|
86
|
+
const optionsSchema = zod_1.z.object({
|
|
87
|
+
follow: zod_1.z.boolean(),
|
|
88
|
+
outputType: zod_1.z.enum(['jpeg', 'png', 'md', 'html']),
|
|
89
|
+
quality: zod_1.z.coerce.number().min(1).max(100).optional(),
|
|
90
|
+
outputDir: zod_1.z.string().default('.'),
|
|
91
|
+
fullPage: zod_1.z.boolean().optional(),
|
|
92
|
+
cssSelector: zod_1.z.string().optional(),
|
|
93
|
+
xpathSelector: zod_1.z.string().optional(),
|
|
94
|
+
browser: zod_1.z.enum(['chrome', 'firefox', 'safari']),
|
|
95
|
+
viewport: zod_1.z
|
|
96
|
+
.string()
|
|
97
|
+
.refine((value) => {
|
|
98
|
+
const [width, height] = value.split('x');
|
|
99
|
+
return (width &&
|
|
100
|
+
height &&
|
|
101
|
+
!isNaN(Number(width)) &&
|
|
102
|
+
!isNaN(Number(height)) &&
|
|
103
|
+
Number(width) > 0 &&
|
|
104
|
+
Number(height) > 0);
|
|
105
|
+
}, 'Invalid viewport format, example: 1920x1080')
|
|
106
|
+
.transform((value) => {
|
|
107
|
+
const [width, height] = value.split('x');
|
|
108
|
+
return {
|
|
109
|
+
width: Number(width),
|
|
110
|
+
height: Number(height),
|
|
111
|
+
};
|
|
112
|
+
}),
|
|
113
|
+
devicePixelRatio: zod_1.z.coerce.number().min(1).max(4),
|
|
114
|
+
darkMode: zod_1.z.boolean(),
|
|
115
|
+
delay: zod_1.z.coerce.number().min(0).max(10000),
|
|
116
|
+
waitForElement: zod_1.z.string().optional(),
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
const url = urlSchema.parse(input);
|
|
120
|
+
const { follow, outputType, quality, outputDir, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement, } = optionsSchema.parse(options);
|
|
121
|
+
if (typeof quality === 'number' && outputType !== 'jpeg') {
|
|
122
|
+
output_1.default.exitError('Quality is only supported for jpeg output type, use --outputType jpeg');
|
|
123
|
+
}
|
|
124
|
+
if (cssSelector && xpathSelector) {
|
|
125
|
+
output_1.default.exitError('Only one of --cssSelector or --xpathSelector can be used');
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
url,
|
|
129
|
+
follow,
|
|
130
|
+
outputType,
|
|
131
|
+
quality,
|
|
132
|
+
outputDir,
|
|
133
|
+
fullPage,
|
|
134
|
+
cssSelector,
|
|
135
|
+
xpathSelector,
|
|
136
|
+
browser,
|
|
137
|
+
viewport,
|
|
138
|
+
devicePixelRatio,
|
|
139
|
+
darkMode,
|
|
140
|
+
delay,
|
|
141
|
+
waitForElement,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof zod_1.ZodError) {
|
|
146
|
+
output_1.default.exitError(error.errors.map((e) => `${e.path}: ${e.message}`).join(', '));
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function watchSessionStatus(buildId) {
|
|
154
|
+
return new Promise((resolve) => {
|
|
155
|
+
const eventSource = (0, requests_1.connectToScrapSession)(buildId);
|
|
156
|
+
eventSource.addEventListener('SESSION_STATUS', (event) => {
|
|
157
|
+
const data = JSON.parse(event.data);
|
|
158
|
+
if (data.status === 'GATHER_URLS_COMPLETED') {
|
|
159
|
+
output_1.default.normal(`Gathering URLs completed, found ${data.text} URLs`);
|
|
160
|
+
}
|
|
161
|
+
else if (data.status === 'GATHER_URLS_FAILED') {
|
|
162
|
+
output_1.default.error('Gathering URLs failed');
|
|
163
|
+
}
|
|
164
|
+
else if (data.status === 'SCRAPE_URL_COMPLETED') {
|
|
165
|
+
output_1.default.normal(`Scraping ${data.text} completed`);
|
|
166
|
+
}
|
|
167
|
+
else if (data.status === 'SCRAPE_URL_FAILED') {
|
|
168
|
+
output_1.default.error(`Scraping ${data.text} failed`);
|
|
169
|
+
}
|
|
170
|
+
else if (data.status === 'CREATE_PACKAGE_COMPLETED') {
|
|
171
|
+
output_1.default.normal('Package created');
|
|
172
|
+
}
|
|
173
|
+
else if (data.status === 'CREATE_PACKAGE_FAILED') {
|
|
174
|
+
output_1.default.error('Package creation failed');
|
|
175
|
+
}
|
|
176
|
+
else if (data.status === 'FINISHED') {
|
|
177
|
+
eventSource.close();
|
|
178
|
+
output_1.default.normal('Scrape session finished');
|
|
179
|
+
resolve({ ok: true });
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
eventSource.addEventListener('error', (event) => {
|
|
183
|
+
if (event.code) {
|
|
184
|
+
eventSource.close();
|
|
185
|
+
if (event.code === 410) {
|
|
186
|
+
output_1.default.normal('Scrape session finished');
|
|
187
|
+
}
|
|
188
|
+
resolve({ ok: event.code === 410, error: event.code });
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
exports.default = commandScrape;
|
package/distTs/src/input.js
CHANGED
|
@@ -351,17 +351,6 @@ class Input {
|
|
|
351
351
|
return utils_1.ARTIFACT_SCOPE.PROJECT;
|
|
352
352
|
return utils_1.ARTIFACT_SCOPE.WORKSPACE;
|
|
353
353
|
}
|
|
354
|
-
static pipelineRunId(runId) {
|
|
355
|
-
const r = parseInt(runId, 10);
|
|
356
|
-
if (!isNaN(r))
|
|
357
|
-
return r;
|
|
358
|
-
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WRONG_RUN_ID);
|
|
359
|
-
}
|
|
360
|
-
static pipelineRunActionId(runActionId) {
|
|
361
|
-
if (runActionId)
|
|
362
|
-
return runActionId;
|
|
363
|
-
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WRONG_RUN_ACTION_ID);
|
|
364
|
-
}
|
|
365
354
|
static pipelineRunPriority(priority) {
|
|
366
355
|
if (!priority)
|
|
367
356
|
return null;
|
|
@@ -419,47 +408,6 @@ class Input {
|
|
|
419
408
|
}
|
|
420
409
|
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WRONG_DELAY);
|
|
421
410
|
}
|
|
422
|
-
static pipelineRunVariablesFromFile(p, encrypted) {
|
|
423
|
-
const list = [];
|
|
424
|
-
const s = (0, node_path_1.resolve)(p);
|
|
425
|
-
if (!node_fs_1.default.existsSync(s)) {
|
|
426
|
-
output_1.default.exitError(texts_1.ERR_PIPELINE_RUN_VAR_FILE_NOT_FOUND);
|
|
427
|
-
}
|
|
428
|
-
let lines;
|
|
429
|
-
try {
|
|
430
|
-
lines = node_fs_1.default.readFileSync(s, 'utf8').split(/\r?\n/);
|
|
431
|
-
}
|
|
432
|
-
catch (err) {
|
|
433
|
-
if (err.code === 'ENOENT')
|
|
434
|
-
output_1.default.exitError(texts_1.ERR_PIPELINE_RUN_VAR_FILE_NOT_FOUND);
|
|
435
|
-
output_1.default.exitError(texts_1.ERR_PIPELINE_RUN_VAR_FILE_INVALID);
|
|
436
|
-
}
|
|
437
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
438
|
-
const line = lines[i].trim();
|
|
439
|
-
if (line.startsWith('#'))
|
|
440
|
-
continue;
|
|
441
|
-
if (line) {
|
|
442
|
-
const ci = line.indexOf(':');
|
|
443
|
-
const ei = line.indexOf('=');
|
|
444
|
-
const sep = ci >= 0 && (ei < 0 || ci < ei) ? ':' : '=';
|
|
445
|
-
const l = line.split(sep);
|
|
446
|
-
if (l.length < 2) {
|
|
447
|
-
output_1.default.exitError(texts_1.ERR_PIPELINE_RUN_VAR_FILE_INVALID);
|
|
448
|
-
}
|
|
449
|
-
const key = l.shift().trim();
|
|
450
|
-
const value = l.join(sep).trim();
|
|
451
|
-
if (!key) {
|
|
452
|
-
output_1.default.exitError(texts_1.ERR_PIPELINE_RUN_VAR_FILE_INVALID);
|
|
453
|
-
}
|
|
454
|
-
list.push({
|
|
455
|
-
key,
|
|
456
|
-
value,
|
|
457
|
-
encrypted
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
return list;
|
|
462
|
-
}
|
|
463
411
|
static pipelineRunVariable(variable, encrypted) {
|
|
464
412
|
const list = [];
|
|
465
413
|
variable.forEach((v) => {
|
|
@@ -543,6 +491,16 @@ class Input {
|
|
|
543
491
|
output_1.default.exitError(texts_1.ERR_REST_API_URL);
|
|
544
492
|
}
|
|
545
493
|
}
|
|
494
|
+
static pipelineRunWaitTime(time) {
|
|
495
|
+
let t = Number.parseInt(time, 10);
|
|
496
|
+
if (!t)
|
|
497
|
+
t = 1440;
|
|
498
|
+
else if (t < 0)
|
|
499
|
+
t = 1;
|
|
500
|
+
else if (t > 1440)
|
|
501
|
+
t = 1440;
|
|
502
|
+
return t;
|
|
503
|
+
}
|
|
546
504
|
static resolvePath(path) {
|
|
547
505
|
const p = (0, node_path_1.resolve)(path);
|
|
548
506
|
const exists = node_fs_1.default.existsSync(p);
|
|
@@ -587,7 +545,7 @@ class Input {
|
|
|
587
545
|
version = (0, uuid_1.v4)();
|
|
588
546
|
return {
|
|
589
547
|
identifier,
|
|
590
|
-
version
|
|
548
|
+
version
|
|
591
549
|
};
|
|
592
550
|
}
|
|
593
551
|
static restApiSandboxIsUpload(destPath) {
|
|
@@ -831,15 +789,11 @@ class Input {
|
|
|
831
789
|
};
|
|
832
790
|
}
|
|
833
791
|
static async resolveSuiteId(client, workspace, project, identifier, type) {
|
|
834
|
-
const paramKey = type === 'vt'
|
|
835
|
-
? '
|
|
836
|
-
: type === 'crawl'
|
|
837
|
-
? 'crawl_suite'
|
|
792
|
+
const paramKey = type === 'vt' ? 'visual_test_suite'
|
|
793
|
+
: type === 'crawl' ? 'crawl_suite'
|
|
838
794
|
: 'unit_test_suite';
|
|
839
|
-
const responseKey = type === 'vt'
|
|
840
|
-
? '
|
|
841
|
-
: type === 'crawl'
|
|
842
|
-
? 'crawl_suite_id'
|
|
795
|
+
const responseKey = type === 'vt' ? 'visual_test_suite_id'
|
|
796
|
+
: type === 'crawl' ? 'crawl_suite_id'
|
|
843
797
|
: 'unit_test_suite_id';
|
|
844
798
|
try {
|
|
845
799
|
const result = await client.resolveIdentifiers(workspace, {
|
|
@@ -471,7 +471,7 @@ class OutputPipeline {
|
|
|
471
471
|
static _jsonActionsLogsHelp(identifier, runId, actionRunId) {
|
|
472
472
|
if (!actionRunId)
|
|
473
473
|
actionRunId = '<action-run-id>';
|
|
474
|
-
return `To view action logs run: \`bdy pip run logs ${identifier} ${runId} ${actionRunId}\``;
|
|
474
|
+
return `To view action logs run: \`bdy pip run logs ${identifier} ${runId} ${actionRunId} --format jsonl\``;
|
|
475
475
|
}
|
|
476
476
|
static _runDetailsFinished(status, finished, tabs) {
|
|
477
477
|
if (finished &&
|
|
@@ -1105,13 +1105,21 @@ class OutputPipeline {
|
|
|
1105
1105
|
const a = {
|
|
1106
1106
|
...action,
|
|
1107
1107
|
};
|
|
1108
|
-
if (action.runId) {
|
|
1108
|
+
if (action.runId && !a.logs) {
|
|
1109
1109
|
a.logs = this._jsonActionsLogsHelp(identifier, runId, action.runId);
|
|
1110
1110
|
}
|
|
1111
1111
|
output_1.default.json({ type: 'action', action: a });
|
|
1112
1112
|
}
|
|
1113
|
-
static jsonRun(run) {
|
|
1114
|
-
|
|
1113
|
+
static jsonRun(identifier, run) {
|
|
1114
|
+
const r = {
|
|
1115
|
+
...run,
|
|
1116
|
+
};
|
|
1117
|
+
(r.actions || []).forEach((a) => {
|
|
1118
|
+
if (a.runId && !a.logs) {
|
|
1119
|
+
a.logs = this._jsonActionsLogsHelp(identifier, run.runId, a.runId);
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1122
|
+
output_1.default.json({ type: 'run', run: r });
|
|
1115
1123
|
}
|
|
1116
1124
|
static jsonLog(log) {
|
|
1117
1125
|
output_1.default.json({ type: 'log', log });
|
|
@@ -1328,7 +1336,7 @@ class OutputPipeline {
|
|
|
1328
1336
|
totalFetchesCount += 1;
|
|
1329
1337
|
if (!noFollow || noWait) {
|
|
1330
1338
|
if (isJson)
|
|
1331
|
-
this.jsonRun(run);
|
|
1339
|
+
this.jsonRun(identifier, run);
|
|
1332
1340
|
else
|
|
1333
1341
|
draw(run);
|
|
1334
1342
|
}
|
|
@@ -1337,8 +1345,7 @@ class OutputPipeline {
|
|
|
1337
1345
|
}
|
|
1338
1346
|
});
|
|
1339
1347
|
if (isJson) {
|
|
1340
|
-
this.jsonRun(run);
|
|
1341
|
-
this.jsonInfo(this._jsonActionsLogsHelp(identifier, runId));
|
|
1348
|
+
this.jsonRun(identifier, run);
|
|
1342
1349
|
}
|
|
1343
1350
|
else {
|
|
1344
1351
|
if (totalFetchesCount > 1 || noFollow) {
|
package/distTs/src/output.js
CHANGED
|
@@ -20,69 +20,39 @@ class Output {
|
|
|
20
20
|
static getCyanColor(text) {
|
|
21
21
|
return chalk_1.default.hex('#00C9FF')(text);
|
|
22
22
|
}
|
|
23
|
-
static getTermKitCyanColor(text) {
|
|
24
|
-
return `^C${text}^:`;
|
|
25
|
-
}
|
|
26
23
|
static getBlueColor(text) {
|
|
27
24
|
return chalk_1.default.hex('#1A86FD')(text);
|
|
28
25
|
}
|
|
29
|
-
static
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
static getPurpleColor(text) {
|
|
33
|
-
return chalk_1.default.hex('#A06BC4')(text);
|
|
34
|
-
}
|
|
35
|
-
static getTermKitPurpleColor(text) {
|
|
36
|
-
return `^M${text}^:`;
|
|
26
|
+
static getLightColor(text) {
|
|
27
|
+
return chalk_1.default.hex('#05BBFF')(text);
|
|
37
28
|
}
|
|
38
29
|
static getMutedColor(text) {
|
|
39
30
|
return chalk_1.default.hex('#8B8D98')(text);
|
|
40
31
|
}
|
|
41
|
-
static getTermKitMutedColor(text) {
|
|
42
|
-
return `^w${text}^:`;
|
|
43
|
-
}
|
|
44
32
|
static getDimColor(text) {
|
|
45
|
-
return chalk_1.default.hex('#
|
|
46
|
-
}
|
|
47
|
-
static getTermKitDimColor(text) {
|
|
48
|
-
return `^K${text}^:`;
|
|
33
|
+
return chalk_1.default.hex('#555869')(text);
|
|
49
34
|
}
|
|
50
35
|
static getArgColor(text) {
|
|
51
36
|
return chalk_1.default.hex('#5A8AB5')(text);
|
|
52
37
|
}
|
|
53
|
-
static getTermKitArgColor(text) {
|
|
54
|
-
return `^B${text}^:`;
|
|
55
|
-
}
|
|
56
38
|
static getLabelColor(text) {
|
|
57
39
|
return chalk_1.default.hex('#D1D5DB')(text);
|
|
58
40
|
}
|
|
59
|
-
static getTermKitLabelColor(text) {
|
|
60
|
-
return `^W${text}^:`;
|
|
61
|
-
}
|
|
62
41
|
static getGreenColor(text) {
|
|
63
|
-
return chalk_1.default.
|
|
64
|
-
}
|
|
65
|
-
static getTermKitGreenColor(text) {
|
|
66
|
-
return `^G${text}^:`;
|
|
42
|
+
return chalk_1.default.green(text);
|
|
67
43
|
}
|
|
68
44
|
static getYellowColor(text) {
|
|
69
45
|
return chalk_1.default.yellow(text);
|
|
70
46
|
}
|
|
71
|
-
static getTermKitYellowColor(text) {
|
|
72
|
-
return `^Y${text}^:`;
|
|
73
|
-
}
|
|
74
47
|
static getRedColor(text) {
|
|
75
|
-
return chalk_1.default.
|
|
76
|
-
}
|
|
77
|
-
static getTermKitRedColor(text) {
|
|
78
|
-
return `^R${text}^:`;
|
|
48
|
+
return chalk_1.default.red(text);
|
|
79
49
|
}
|
|
80
50
|
static getInquirerTheme() {
|
|
81
51
|
return {
|
|
82
52
|
prefix: this.getCyanColor('?'),
|
|
83
53
|
style: {
|
|
84
54
|
highlight: (text) => this.getCyanColor(text),
|
|
85
|
-
answer: (text) => this.
|
|
55
|
+
answer: (text) => this.getLightColor(text),
|
|
86
56
|
message: (text) => this.getLabelColor(text),
|
|
87
57
|
help: (text) => this.getDimColor(text),
|
|
88
58
|
description: (text) => this.getArgColor(text),
|
|
@@ -122,6 +92,9 @@ class Output {
|
|
|
122
92
|
static newline() {
|
|
123
93
|
getTerminal()('\n');
|
|
124
94
|
}
|
|
95
|
+
static light(txt, newLine = true) {
|
|
96
|
+
this.normal(this.getLightColor(txt), newLine);
|
|
97
|
+
}
|
|
125
98
|
static muted(txt, newLine = true) {
|
|
126
99
|
this.normal(this.getMutedColor(txt), newLine);
|
|
127
100
|
}
|
|
@@ -284,16 +257,11 @@ class Output {
|
|
|
284
257
|
static async confirm(message = 'Are you sure?') {
|
|
285
258
|
if (this.isStdInTTY()) {
|
|
286
259
|
const prompts = require('@inquirer/prompts');
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
catch {
|
|
295
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
296
|
-
}
|
|
260
|
+
return await prompts.confirm({
|
|
261
|
+
message,
|
|
262
|
+
theme: this.getInquirerTheme(),
|
|
263
|
+
default: false,
|
|
264
|
+
});
|
|
297
265
|
}
|
|
298
266
|
this.cyan('? ', false);
|
|
299
267
|
this.label(message, false);
|
|
@@ -303,19 +271,12 @@ class Output {
|
|
|
303
271
|
static async inputString(message, def, required, signal) {
|
|
304
272
|
if (this.isStdInTTY()) {
|
|
305
273
|
const prompts = require('@inquirer/prompts');
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}, { signal });
|
|
313
|
-
}
|
|
314
|
-
catch (err) {
|
|
315
|
-
if (err.name === 'AbortPromptError')
|
|
316
|
-
throw err;
|
|
317
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
318
|
-
}
|
|
274
|
+
return await prompts.input({
|
|
275
|
+
required,
|
|
276
|
+
message,
|
|
277
|
+
default: def,
|
|
278
|
+
theme: this.getInquirerTheme(),
|
|
279
|
+
}, { signal });
|
|
319
280
|
}
|
|
320
281
|
this.cyan('? ', false);
|
|
321
282
|
this.normal(message, false);
|
|
@@ -329,17 +290,12 @@ class Output {
|
|
|
329
290
|
static async inputMenuAdv(message, items) {
|
|
330
291
|
const prompts = require('@inquirer/prompts');
|
|
331
292
|
if (this.isStdInTTY()) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
catch {
|
|
341
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
342
|
-
}
|
|
293
|
+
return await prompts.select({
|
|
294
|
+
message,
|
|
295
|
+
theme: this.getInquirerTheme(),
|
|
296
|
+
loop: false,
|
|
297
|
+
choices: items,
|
|
298
|
+
});
|
|
343
299
|
}
|
|
344
300
|
else {
|
|
345
301
|
this.cyan('? ', false);
|
|
@@ -389,17 +345,12 @@ class Output {
|
|
|
389
345
|
static async inputMenu(message, items) {
|
|
390
346
|
if (this.isStdInTTY()) {
|
|
391
347
|
const prompts = require('@inquirer/prompts');
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
catch {
|
|
401
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
402
|
-
}
|
|
348
|
+
return await prompts.select({
|
|
349
|
+
message,
|
|
350
|
+
theme: this.getInquirerTheme(),
|
|
351
|
+
loop: false,
|
|
352
|
+
choices: items.map((item, index) => ({ value: index, name: item })),
|
|
353
|
+
});
|
|
403
354
|
}
|
|
404
355
|
else {
|
|
405
356
|
this.cyan('? ', false);
|
|
@@ -440,75 +391,6 @@ class Output {
|
|
|
440
391
|
}
|
|
441
392
|
return `${normalized}/api`;
|
|
442
393
|
}
|
|
443
|
-
static createScreenBuffer(onKey, onResize) {
|
|
444
|
-
const TerminalKit = require('terminal-kit/lib/termkit-no-lazy-require');
|
|
445
|
-
const terminal = getTerminal();
|
|
446
|
-
// @ts-ignore
|
|
447
|
-
const viewPort = new TerminalKit.ScreenBuffer({
|
|
448
|
-
dst: terminal,
|
|
449
|
-
width: terminal.width,
|
|
450
|
-
height: terminal.height,
|
|
451
|
-
x: 1,
|
|
452
|
-
y: 1,
|
|
453
|
-
});
|
|
454
|
-
terminal.grabInput();
|
|
455
|
-
terminal.hideCursor();
|
|
456
|
-
terminal.fullscreen(true);
|
|
457
|
-
const exit = () => {
|
|
458
|
-
terminal.fullscreen(false);
|
|
459
|
-
terminal.hideCursor(false);
|
|
460
|
-
terminal.grabInput(false);
|
|
461
|
-
process.exit();
|
|
462
|
-
};
|
|
463
|
-
terminal.on('key', (name) => {
|
|
464
|
-
const shouldExit = onKey(name);
|
|
465
|
-
if (shouldExit)
|
|
466
|
-
exit();
|
|
467
|
-
});
|
|
468
|
-
terminal.on('resize', () => {
|
|
469
|
-
viewPort.resize({
|
|
470
|
-
width: TerminalKit.terminal.width,
|
|
471
|
-
height: TerminalKit.terminal.height,
|
|
472
|
-
x: 1,
|
|
473
|
-
y: 1,
|
|
474
|
-
});
|
|
475
|
-
onResize();
|
|
476
|
-
});
|
|
477
|
-
let y = 1;
|
|
478
|
-
const put = (str) => {
|
|
479
|
-
viewPort.put({
|
|
480
|
-
x: 1,
|
|
481
|
-
y,
|
|
482
|
-
markup: true,
|
|
483
|
-
}, str);
|
|
484
|
-
y += 1;
|
|
485
|
-
return y;
|
|
486
|
-
};
|
|
487
|
-
const blank = () => {
|
|
488
|
-
y += 1;
|
|
489
|
-
return y;
|
|
490
|
-
};
|
|
491
|
-
const reset = () => {
|
|
492
|
-
y = 1;
|
|
493
|
-
viewPort.fill({
|
|
494
|
-
char: ' ',
|
|
495
|
-
});
|
|
496
|
-
};
|
|
497
|
-
const apply = () => {
|
|
498
|
-
viewPort.draw();
|
|
499
|
-
};
|
|
500
|
-
const getY = () => {
|
|
501
|
-
return y;
|
|
502
|
-
};
|
|
503
|
-
return {
|
|
504
|
-
put,
|
|
505
|
-
reset,
|
|
506
|
-
blank,
|
|
507
|
-
apply,
|
|
508
|
-
getY,
|
|
509
|
-
exit,
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
394
|
static async selectRegion() {
|
|
513
395
|
const index = await Output.inputMenu(texts_1.TXT_LOGIN_SELECT_REGION, [
|
|
514
396
|
'US (default)',
|
|
@@ -524,9 +406,6 @@ class Output {
|
|
|
524
406
|
return utils_1.REST_API_REGION.AS;
|
|
525
407
|
return utils_1.REST_API_REGION.ONPREM;
|
|
526
408
|
}
|
|
527
|
-
static getTerminal() {
|
|
528
|
-
return getTerminal();
|
|
529
|
-
}
|
|
530
409
|
static getUndiciUnauthorizedAgent() {
|
|
531
410
|
if (!this._a) {
|
|
532
411
|
const undici = require('undici');
|
|
@@ -553,9 +432,6 @@ class Output {
|
|
|
553
432
|
_terminal.hideCursor(false);
|
|
554
433
|
_terminal.grabInput(false);
|
|
555
434
|
}
|
|
556
|
-
static json(json) {
|
|
557
|
-
this.normal(JSON.stringify(json));
|
|
558
|
-
}
|
|
559
435
|
static exitError(err) {
|
|
560
436
|
this.clearUndici();
|
|
561
437
|
this.clearTerminal();
|