bdy 1.19.2-dev-pipeline → 1.19.2-dev
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 -103
- package/distTs/src/command/pipeline/run.js +125 -22
- package/distTs/src/command/pipeline.js +0 -23
- 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 +31 -14
- package/distTs/src/output.js +31 -149
- package/distTs/src/texts.js +34 -84
- package/distTs/src/tunnel/output/interactive/tunnel.js +2 -2
- package/package.json +1 -1
- package/distTs/src/command/crawl/link.js +0 -61
- package/distTs/src/command/crawl/run.js +0 -147
- package/distTs/src/command/crawl/validation.js +0 -154
- package/distTs/src/command/crawl.js +0 -13
- package/distTs/src/command/pipeline/create.js +0 -45
- package/distTs/src/command/pipeline/get.js +0 -42
- package/distTs/src/command/pipeline/list.js +0 -43
- package/distTs/src/command/pipeline/run/apply.js +0 -62
- package/distTs/src/command/pipeline/run/approve.js +0 -62
- package/distTs/src/command/pipeline/run/cancel.js +0 -36
- package/distTs/src/command/pipeline/run/list.js +0 -52
- package/distTs/src/command/pipeline/run/logs.js +0 -37
- package/distTs/src/command/pipeline/run/retry.js +0 -36
- package/distTs/src/command/pipeline/run/start.js +0 -96
- package/distTs/src/command/pipeline/run/status.js +0 -35
- package/distTs/src/command/pipeline/update.js +0 -41
- package/distTs/src/command/pipeline/yaml.js +0 -38
- package/distTs/src/command/tests/capture/validation.js +0 -46
- package/distTs/src/command/tests/capture.js +0 -103
- package/distTs/src/command/tests/unit/link.js +0 -61
- package/distTs/src/command/tests/unit/upload.js +0 -91
- package/distTs/src/command/tests/unit.js +0 -13
- package/distTs/src/command/tests/visual/link.js +0 -61
- package/distTs/src/command/tests/visual/session/close.js +0 -32
- package/distTs/src/command/tests/visual/session/create.js +0 -86
- package/distTs/src/command/tests/visual/session.js +0 -13
- package/distTs/src/command/tests/visual/setup.js +0 -20
- package/distTs/src/command/tests/visual/shared/validation.js +0 -145
- package/distTs/src/command/tests/visual/upload.js +0 -141
- package/distTs/src/command/tests/visual.js +0 -17
- package/distTs/src/command/tests.js +0 -15
- package/distTs/src/crawl/requests.js +0 -141
- package/distTs/src/output/pipeline.js +0 -1527
- package/distTs/src/types/crawl.js +0 -2
- package/distTs/src/types/pipeline.js +0 -424
- package/distTs/src/unitTest/context.js +0 -26
|
@@ -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
|
@@ -334,8 +334,8 @@ class Input {
|
|
|
334
334
|
}
|
|
335
335
|
static restApiTokenClient(allowNoToken = false, api = '', region = '', token = '') {
|
|
336
336
|
const ApiClient = require('./api/client').default;
|
|
337
|
-
const baseUrl = this.restApiBaseUrl(api, region);
|
|
338
337
|
const { token: t, refreshToken, clientId, clientToken, clientSecret, } = this.restApiToken(allowNoToken, token);
|
|
338
|
+
const baseUrl = this.restApiBaseUrl(api, region, t);
|
|
339
339
|
return new ApiClient(baseUrl, t, refreshToken, clientId, clientSecret, clientToken);
|
|
340
340
|
}
|
|
341
341
|
static artifactType(type) {
|
|
@@ -350,17 +350,6 @@ class Input {
|
|
|
350
350
|
return utils_1.ARTIFACT_SCOPE.PROJECT;
|
|
351
351
|
return utils_1.ARTIFACT_SCOPE.WORKSPACE;
|
|
352
352
|
}
|
|
353
|
-
static pipelineRunId(runId) {
|
|
354
|
-
const r = parseInt(runId, 10);
|
|
355
|
-
if (!isNaN(r))
|
|
356
|
-
return r;
|
|
357
|
-
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WRONG_RUN_ID);
|
|
358
|
-
}
|
|
359
|
-
static pipelineRunActionId(runActionId) {
|
|
360
|
-
if (runActionId)
|
|
361
|
-
return runActionId;
|
|
362
|
-
output_1.default.exitError(texts_1.ERR_RUN_PIPELINE_WRONG_RUN_ACTION_ID);
|
|
363
|
-
}
|
|
364
353
|
static pipelineRunPriority(priority) {
|
|
365
354
|
if (!priority)
|
|
366
355
|
return null;
|
|
@@ -442,8 +431,26 @@ class Input {
|
|
|
442
431
|
output_1.default.exitError(texts_1.ERR_REST_API_REGION);
|
|
443
432
|
}
|
|
444
433
|
}
|
|
445
|
-
static
|
|
446
|
-
|
|
434
|
+
static restApiBaseUrlFromToken(token) {
|
|
435
|
+
// bdy_sb_us_aHR0cHM6Ly9hcGkuc2Q1LmNvbQ_f92ml8f1p27nzo45806vczm6c78d0
|
|
436
|
+
const s = (token || '').split('_');
|
|
437
|
+
if (s.length > 1) {
|
|
438
|
+
const base = s[s.length - 2];
|
|
439
|
+
try {
|
|
440
|
+
return Buffer.from(base, 'base64').toString('utf8');
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
// do nothing
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
static restApiBaseUrl(api = '', region = '', token = '') {
|
|
449
|
+
let u = api;
|
|
450
|
+
if (!u)
|
|
451
|
+
u = this.restApiBaseUrlFromToken(token);
|
|
452
|
+
if (!u)
|
|
453
|
+
u = process.env.BUDDY_API_ENDPOINT || null;
|
|
447
454
|
if (!u)
|
|
448
455
|
u = cfg_1.default.getBaseUrl();
|
|
449
456
|
if (!u) {
|
|
@@ -468,6 +475,16 @@ class Input {
|
|
|
468
475
|
output_1.default.exitError(texts_1.ERR_REST_API_URL);
|
|
469
476
|
}
|
|
470
477
|
}
|
|
478
|
+
static pipelineRunWaitTime(time) {
|
|
479
|
+
let t = Number.parseInt(time, 10);
|
|
480
|
+
if (!t)
|
|
481
|
+
t = 1440;
|
|
482
|
+
else if (t < 0)
|
|
483
|
+
t = 1;
|
|
484
|
+
else if (t > 1440)
|
|
485
|
+
t = 1440;
|
|
486
|
+
return t;
|
|
487
|
+
}
|
|
471
488
|
static resolvePath(path) {
|
|
472
489
|
const p = (0, node_path_1.resolve)(path);
|
|
473
490
|
const exists = node_fs_1.default.existsSync(p);
|
package/distTs/src/output.js
CHANGED
|
@@ -18,69 +18,39 @@ class Output {
|
|
|
18
18
|
static getCyanColor(text) {
|
|
19
19
|
return chalk_1.default.hex('#00C9FF')(text);
|
|
20
20
|
}
|
|
21
|
-
static getTermKitCyanColor(text) {
|
|
22
|
-
return `^C${text}^:`;
|
|
23
|
-
}
|
|
24
21
|
static getBlueColor(text) {
|
|
25
22
|
return chalk_1.default.hex('#1A86FD')(text);
|
|
26
23
|
}
|
|
27
|
-
static
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
static getPurpleColor(text) {
|
|
31
|
-
return chalk_1.default.hex('#A06BC4')(text);
|
|
32
|
-
}
|
|
33
|
-
static getTermKitPurpleColor(text) {
|
|
34
|
-
return `^M${text}^:`;
|
|
24
|
+
static getLightColor(text) {
|
|
25
|
+
return chalk_1.default.hex('#05BBFF')(text);
|
|
35
26
|
}
|
|
36
27
|
static getMutedColor(text) {
|
|
37
28
|
return chalk_1.default.hex('#8B8D98')(text);
|
|
38
29
|
}
|
|
39
|
-
static getTermKitMutedColor(text) {
|
|
40
|
-
return `^w${text}^:`;
|
|
41
|
-
}
|
|
42
30
|
static getDimColor(text) {
|
|
43
31
|
return chalk_1.default.hex('#555869')(text);
|
|
44
32
|
}
|
|
45
|
-
static getTermKitDimColor(text) {
|
|
46
|
-
return `^K${text}^:`;
|
|
47
|
-
}
|
|
48
33
|
static getArgColor(text) {
|
|
49
34
|
return chalk_1.default.hex('#5A8AB5')(text);
|
|
50
35
|
}
|
|
51
|
-
static getTermKitArgColor(text) {
|
|
52
|
-
return `^B${text}^:`;
|
|
53
|
-
}
|
|
54
36
|
static getLabelColor(text) {
|
|
55
37
|
return chalk_1.default.hex('#D1D5DB')(text);
|
|
56
38
|
}
|
|
57
|
-
static getTermKitLabelColor(text) {
|
|
58
|
-
return `^W${text}^:`;
|
|
59
|
-
}
|
|
60
39
|
static getGreenColor(text) {
|
|
61
|
-
return chalk_1.default.
|
|
62
|
-
}
|
|
63
|
-
static getTermKitGreenColor(text) {
|
|
64
|
-
return `^G${text}^:`;
|
|
40
|
+
return chalk_1.default.green(text);
|
|
65
41
|
}
|
|
66
42
|
static getYellowColor(text) {
|
|
67
43
|
return chalk_1.default.yellow(text);
|
|
68
44
|
}
|
|
69
|
-
static getTermKitYellowColor(text) {
|
|
70
|
-
return `^Y${text}^:`;
|
|
71
|
-
}
|
|
72
45
|
static getRedColor(text) {
|
|
73
|
-
return chalk_1.default.
|
|
74
|
-
}
|
|
75
|
-
static getTermKitRedColor(text) {
|
|
76
|
-
return `^R${text}^:`;
|
|
46
|
+
return chalk_1.default.red(text);
|
|
77
47
|
}
|
|
78
48
|
static getInquirerTheme() {
|
|
79
49
|
return {
|
|
80
50
|
prefix: this.getCyanColor('?'),
|
|
81
51
|
style: {
|
|
82
52
|
highlight: (text) => this.getCyanColor(text),
|
|
83
|
-
answer: (text) => this.
|
|
53
|
+
answer: (text) => this.getLightColor(text),
|
|
84
54
|
message: (text) => this.getLabelColor(text),
|
|
85
55
|
help: (text) => this.getDimColor(text),
|
|
86
56
|
description: (text) => this.getArgColor(text),
|
|
@@ -114,6 +84,9 @@ class Output {
|
|
|
114
84
|
static newline() {
|
|
115
85
|
terminal('\n');
|
|
116
86
|
}
|
|
87
|
+
static light(txt, newLine = true) {
|
|
88
|
+
this.normal(this.getLightColor(txt), newLine);
|
|
89
|
+
}
|
|
117
90
|
static muted(txt, newLine = true) {
|
|
118
91
|
this.normal(this.getMutedColor(txt), newLine);
|
|
119
92
|
}
|
|
@@ -276,16 +249,11 @@ class Output {
|
|
|
276
249
|
static async confirm(message = 'Are you sure?') {
|
|
277
250
|
if (this.isStdInTTY()) {
|
|
278
251
|
const prompts = require('@inquirer/prompts');
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
288
|
-
}
|
|
252
|
+
return await prompts.confirm({
|
|
253
|
+
message,
|
|
254
|
+
theme: this.getInquirerTheme(),
|
|
255
|
+
default: false,
|
|
256
|
+
});
|
|
289
257
|
}
|
|
290
258
|
this.cyan('? ', false);
|
|
291
259
|
this.label(message, false);
|
|
@@ -295,19 +263,12 @@ class Output {
|
|
|
295
263
|
static async inputString(message, def, required, signal) {
|
|
296
264
|
if (this.isStdInTTY()) {
|
|
297
265
|
const prompts = require('@inquirer/prompts');
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}, { signal });
|
|
305
|
-
}
|
|
306
|
-
catch (err) {
|
|
307
|
-
if (err.name === 'AbortPromptError')
|
|
308
|
-
throw err;
|
|
309
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
310
|
-
}
|
|
266
|
+
return await prompts.input({
|
|
267
|
+
required,
|
|
268
|
+
message,
|
|
269
|
+
default: def,
|
|
270
|
+
theme: this.getInquirerTheme(),
|
|
271
|
+
}, { signal });
|
|
311
272
|
}
|
|
312
273
|
this.cyan('? ', false);
|
|
313
274
|
this.normal(message, false);
|
|
@@ -321,17 +282,12 @@ class Output {
|
|
|
321
282
|
static async inputMenuAdv(message, items) {
|
|
322
283
|
const prompts = require('@inquirer/prompts');
|
|
323
284
|
if (this.isStdInTTY()) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
catch {
|
|
333
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
334
|
-
}
|
|
285
|
+
return await prompts.select({
|
|
286
|
+
message,
|
|
287
|
+
theme: this.getInquirerTheme(),
|
|
288
|
+
loop: false,
|
|
289
|
+
choices: items,
|
|
290
|
+
});
|
|
335
291
|
}
|
|
336
292
|
else {
|
|
337
293
|
this.cyan('? ', false);
|
|
@@ -381,17 +337,12 @@ class Output {
|
|
|
381
337
|
static async inputMenu(message, items) {
|
|
382
338
|
if (this.isStdInTTY()) {
|
|
383
339
|
const prompts = require('@inquirer/prompts');
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
catch {
|
|
393
|
-
this.exitError(texts_1.ERR_CANCELLED);
|
|
394
|
-
}
|
|
340
|
+
return await prompts.select({
|
|
341
|
+
message,
|
|
342
|
+
theme: this.getInquirerTheme(),
|
|
343
|
+
loop: false,
|
|
344
|
+
choices: items.map((item, index) => ({ value: index, name: item })),
|
|
345
|
+
});
|
|
395
346
|
}
|
|
396
347
|
else {
|
|
397
348
|
this.cyan('? ', false);
|
|
@@ -432,72 +383,6 @@ class Output {
|
|
|
432
383
|
}
|
|
433
384
|
return `${normalized}/api`;
|
|
434
385
|
}
|
|
435
|
-
static createScreenBuffer(onKey, onResize) {
|
|
436
|
-
const viewPort = new termkit_no_lazy_require_1.default.ScreenBuffer({
|
|
437
|
-
dst: terminal,
|
|
438
|
-
width: terminal.width,
|
|
439
|
-
height: terminal.height,
|
|
440
|
-
x: 1,
|
|
441
|
-
y: 1,
|
|
442
|
-
});
|
|
443
|
-
terminal.grabInput();
|
|
444
|
-
terminal.hideCursor();
|
|
445
|
-
terminal.fullscreen(true);
|
|
446
|
-
const exit = () => {
|
|
447
|
-
terminal.fullscreen(false);
|
|
448
|
-
terminal.hideCursor(false);
|
|
449
|
-
terminal.grabInput(false);
|
|
450
|
-
process.exit();
|
|
451
|
-
};
|
|
452
|
-
terminal.on('key', (name) => {
|
|
453
|
-
const shouldExit = onKey(name);
|
|
454
|
-
if (shouldExit)
|
|
455
|
-
exit();
|
|
456
|
-
});
|
|
457
|
-
terminal.on('resize', () => {
|
|
458
|
-
viewPort.resize({
|
|
459
|
-
width: termkit_no_lazy_require_1.default.terminal.width,
|
|
460
|
-
height: termkit_no_lazy_require_1.default.terminal.height,
|
|
461
|
-
x: 1,
|
|
462
|
-
y: 1,
|
|
463
|
-
});
|
|
464
|
-
onResize();
|
|
465
|
-
});
|
|
466
|
-
let y = 1;
|
|
467
|
-
const put = (str) => {
|
|
468
|
-
viewPort.put({
|
|
469
|
-
x: 1,
|
|
470
|
-
y,
|
|
471
|
-
markup: true,
|
|
472
|
-
}, str);
|
|
473
|
-
y += 1;
|
|
474
|
-
return y;
|
|
475
|
-
};
|
|
476
|
-
const blank = () => {
|
|
477
|
-
y += 1;
|
|
478
|
-
return y;
|
|
479
|
-
};
|
|
480
|
-
const reset = () => {
|
|
481
|
-
y = 1;
|
|
482
|
-
viewPort.fill({
|
|
483
|
-
char: ' ',
|
|
484
|
-
});
|
|
485
|
-
};
|
|
486
|
-
const apply = () => {
|
|
487
|
-
viewPort.draw();
|
|
488
|
-
};
|
|
489
|
-
const getY = () => {
|
|
490
|
-
return y;
|
|
491
|
-
};
|
|
492
|
-
return {
|
|
493
|
-
put,
|
|
494
|
-
reset,
|
|
495
|
-
blank,
|
|
496
|
-
apply,
|
|
497
|
-
getY,
|
|
498
|
-
exit,
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
386
|
static async selectRegion() {
|
|
502
387
|
const index = await Output.inputMenu(texts_1.TXT_LOGIN_SELECT_REGION, [
|
|
503
388
|
'US (default)',
|
|
@@ -513,9 +398,6 @@ class Output {
|
|
|
513
398
|
return utils_1.REST_API_REGION.AS;
|
|
514
399
|
return utils_1.REST_API_REGION.ONPREM;
|
|
515
400
|
}
|
|
516
|
-
static getTerminal() {
|
|
517
|
-
return terminal;
|
|
518
|
-
}
|
|
519
401
|
static exitError(err) {
|
|
520
402
|
this.killSpinner();
|
|
521
403
|
terminal.fullscreen(false);
|