bdy 1.25.5-stage → 1.25.7-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 +1 -1
- package/distTs/src/cliCommand.js +47 -4
- package/distTs/src/cliError.js +10 -0
- package/distTs/src/cliIndex.js +10 -0
- package/distTs/src/command/context/add.js +38 -0
- package/distTs/src/command/context/list.js +33 -0
- package/distTs/src/command/context/remove.js +36 -0
- package/distTs/src/command/context/show.js +35 -0
- package/distTs/src/command/context/use.js +25 -0
- package/distTs/src/command/context.js +22 -0
- package/distTs/src/command/login.js +1 -0
- package/distTs/src/command/logout.js +1 -0
- package/distTs/src/command/pipeline/run/approve.js +8 -15
- package/distTs/src/command/pipeline/run/cancel.js +7 -15
- package/distTs/src/command/pipeline/run/execution.js +20 -0
- package/distTs/src/command/pipeline/run/logs.js +6 -14
- package/distTs/src/command/pipeline/run/retry.js +7 -15
- package/distTs/src/command/pipeline/run/start.js +8 -15
- package/distTs/src/command/pipeline/run/status.js +6 -14
- package/distTs/src/command/project/link.js +1 -0
- package/distTs/src/command/register.js +1 -0
- package/distTs/src/command/sandbox/exec/command.js +7 -2
- package/distTs/src/command/sandbox/exec/logs.js +3 -2
- package/distTs/src/command/sandbox/exec/status.js +6 -2
- package/distTs/src/command/sandbox/finishExec.js +19 -2
- package/distTs/src/command/target/exec/command.js +25 -10
- package/distTs/src/command/target/exec/logs.js +14 -8
- package/distTs/src/command/target/exec/status.js +6 -2
- package/distTs/src/command/target/scope.js +3 -2
- package/distTs/src/command/whoami.js +7 -10
- package/distTs/src/command/workspace/get.js +2 -2
- package/distTs/src/command/workspace/set.js +1 -0
- package/distTs/src/input.js +205 -27
- package/distTs/src/output/pipeline.js +108 -28
- package/distTs/src/output.js +46 -8
- package/distTs/src/project/context.js +97 -0
- package/distTs/src/texts.js +257 -22
- package/distTs/src/tunnel/cfg.js +43 -4
- package/distTs/src/types/context.js +2 -0
- package/distTs/src/utils.js +15 -0
- package/package.json +1 -1
package/distTs/src/input.js
CHANGED
|
@@ -36,6 +36,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const cfg_1 = __importDefault(require("./project/cfg"));
|
|
40
|
+
const context_1 = require("./project/context");
|
|
39
41
|
const cliError_1 = __importDefault(require("./cliError"));
|
|
40
42
|
const output_1 = __importDefault(require("./output"));
|
|
41
43
|
const netmask_1 = require("netmask");
|
|
@@ -48,10 +50,159 @@ const utils_1 = require("./utils");
|
|
|
48
50
|
const texts_1 = require("./texts");
|
|
49
51
|
const tunnel_1 = require("./types/tunnel");
|
|
50
52
|
const node_path_1 = __importStar(require("node:path"));
|
|
51
|
-
const
|
|
53
|
+
const cfg_2 = __importDefault(require("./tunnel/cfg"));
|
|
52
54
|
const sandbox_1 = require("./types/sandbox");
|
|
53
55
|
const distro_1 = require("./types/distro");
|
|
54
56
|
class Input {
|
|
57
|
+
static contextOptions = {};
|
|
58
|
+
static resolvedContextScope;
|
|
59
|
+
static configureContext(options) {
|
|
60
|
+
this.contextOptions = options;
|
|
61
|
+
this.resolvedContextScope = undefined;
|
|
62
|
+
}
|
|
63
|
+
static contextName() {
|
|
64
|
+
return this.contextOptions.context || cfg_2.default.getActiveContext();
|
|
65
|
+
}
|
|
66
|
+
static context() {
|
|
67
|
+
return cfg_2.default.getContext(this.contextName());
|
|
68
|
+
}
|
|
69
|
+
static contextScope() {
|
|
70
|
+
const context = this.context();
|
|
71
|
+
if (!context)
|
|
72
|
+
return null;
|
|
73
|
+
this.resolvedContextScope ??= (0, context_1.resolveContextScope)(context, process.cwd());
|
|
74
|
+
return this.resolvedContextScope;
|
|
75
|
+
}
|
|
76
|
+
static contextEditableName(name) {
|
|
77
|
+
if (['default', 'git', 'link'].includes(name))
|
|
78
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_CONTEXT_RESERVED);
|
|
79
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(name))
|
|
80
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_CONTEXT_NAME);
|
|
81
|
+
return name;
|
|
82
|
+
}
|
|
83
|
+
static contextApiEndpoint(api) {
|
|
84
|
+
try {
|
|
85
|
+
const url = new URL(api.includes('://') ? api : `https://${api}`);
|
|
86
|
+
if (url.protocol !== 'https:' ||
|
|
87
|
+
url.username ||
|
|
88
|
+
url.password ||
|
|
89
|
+
url.pathname !== '/' ||
|
|
90
|
+
url.search ||
|
|
91
|
+
url.hash)
|
|
92
|
+
throw new Error();
|
|
93
|
+
return url.origin;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_CONTEXT_API);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
static contextDefinition(options) {
|
|
100
|
+
if ((options.fromLink && options.fromGit) ||
|
|
101
|
+
((options.fromLink || options.fromGit) &&
|
|
102
|
+
(options.workspace !== undefined || options.project !== undefined)) ||
|
|
103
|
+
(options.remote !== undefined && !options.fromGit))
|
|
104
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_CONTEXT_SOURCE);
|
|
105
|
+
if (options.project && !options.workspace)
|
|
106
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_CONTEXT_PROJECT);
|
|
107
|
+
const api = options.api !== undefined
|
|
108
|
+
? this.contextApiEndpoint(options.api)
|
|
109
|
+
: undefined;
|
|
110
|
+
return {
|
|
111
|
+
source: options.fromGit ? 'git' : options.fromLink ? 'link' : 'explicit',
|
|
112
|
+
...(options.workspace ? { workspace: options.workspace } : {}),
|
|
113
|
+
...(options.project ? { project: options.project } : {}),
|
|
114
|
+
...(options.token ? { token: options.token } : {}),
|
|
115
|
+
...(api ? { api } : {}),
|
|
116
|
+
...(options.fromGit ? { remote: options.remote || 'origin' } : {}),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// Account display preserves the legacy distinction between global and linked
|
|
120
|
+
// workspace, while named contexts own their entire scope.
|
|
121
|
+
static accountScope() {
|
|
122
|
+
if (this.context())
|
|
123
|
+
return {
|
|
124
|
+
workspace: this.restApiWorkspace(undefined, true),
|
|
125
|
+
project: this.restApiProject(undefined, true),
|
|
126
|
+
localWorkspace: '',
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
workspace: cfg_2.default.getWorkspace(),
|
|
130
|
+
project: cfg_1.default.getProject(),
|
|
131
|
+
localWorkspace: cfg_1.default.getWorkspace(),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
static showContext() {
|
|
135
|
+
const context = this.context();
|
|
136
|
+
const workspace = this.restApiWorkspace(this.contextOptions.workspace, true);
|
|
137
|
+
const project = this.restApiProject(this.contextOptions.project, true);
|
|
138
|
+
const auth = this.restApiToken(true, this.contextOptions.token);
|
|
139
|
+
const api = this.restApiBaseUrl(this.contextOptions.api, this.contextOptions.region, auth.token).origin;
|
|
140
|
+
const inSandbox = (0, utils_1.isInSandbox)();
|
|
141
|
+
const tokenSource = this.contextOptions.token
|
|
142
|
+
? 'flag'
|
|
143
|
+
: context?.token
|
|
144
|
+
? 'context'
|
|
145
|
+
: !inSandbox && process.env.BUDDY_TOKEN
|
|
146
|
+
? 'environment'
|
|
147
|
+
: cfg_2.default.getApiToken()
|
|
148
|
+
? 'config'
|
|
149
|
+
: process.env.BUDDY_TOKEN
|
|
150
|
+
? 'environment'
|
|
151
|
+
: null;
|
|
152
|
+
const workspaceSource = this.contextOptions.workspace
|
|
153
|
+
? 'flag'
|
|
154
|
+
: context
|
|
155
|
+
? workspace
|
|
156
|
+
? context.source
|
|
157
|
+
: null
|
|
158
|
+
: !inSandbox && process.env.BUDDY_WORKSPACE
|
|
159
|
+
? 'environment'
|
|
160
|
+
: cfg_1.default.getWorkspace()
|
|
161
|
+
? 'link'
|
|
162
|
+
: cfg_2.default.getWorkspace()
|
|
163
|
+
? 'config'
|
|
164
|
+
: process.env.BUDDY_WORKSPACE
|
|
165
|
+
? 'environment'
|
|
166
|
+
: null;
|
|
167
|
+
const projectSource = !project
|
|
168
|
+
? null
|
|
169
|
+
: this.contextOptions.project
|
|
170
|
+
? 'flag'
|
|
171
|
+
: context
|
|
172
|
+
? context.source
|
|
173
|
+
: process.env.BUDDY_PROJECT
|
|
174
|
+
? 'environment'
|
|
175
|
+
: 'link';
|
|
176
|
+
const apiSource = this.contextOptions.api
|
|
177
|
+
? 'flag'
|
|
178
|
+
: context?.api
|
|
179
|
+
? 'context'
|
|
180
|
+
: this.restApiBaseUrlFromToken(auth.token)
|
|
181
|
+
? 'token'
|
|
182
|
+
: process.env.BUDDY_API_ENDPOINT
|
|
183
|
+
? 'environment'
|
|
184
|
+
: cfg_2.default.getBaseUrl()
|
|
185
|
+
? 'config'
|
|
186
|
+
: this.contextOptions.region
|
|
187
|
+
? 'flag'
|
|
188
|
+
: process.env.BUDDY_REGION
|
|
189
|
+
? 'environment'
|
|
190
|
+
: 'default';
|
|
191
|
+
return {
|
|
192
|
+
name: this.contextName(),
|
|
193
|
+
source: context?.source || 'default',
|
|
194
|
+
workspace,
|
|
195
|
+
project,
|
|
196
|
+
api,
|
|
197
|
+
remote: context?.source === 'git' ? context.remote || 'origin' : null,
|
|
198
|
+
token: { available: !!auth.token, source: tokenSource },
|
|
199
|
+
sources: {
|
|
200
|
+
workspace: workspaceSource,
|
|
201
|
+
project: projectSource,
|
|
202
|
+
api: apiSource,
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
55
206
|
static timeout(timeout) {
|
|
56
207
|
const t = parseInt(timeout, 10);
|
|
57
208
|
if (isNaN(t) || t <= 0 || t > 999) {
|
|
@@ -344,7 +495,7 @@ class Input {
|
|
|
344
495
|
// Inside a sandbox, cfg (written by an explicit `bdy login`) takes precedence
|
|
345
496
|
// over the sandbox-injected BUDDY_TOKEN env var. Outside a sandbox, env beats cfg
|
|
346
497
|
const tokenEnv = process.env.BUDDY_TOKEN;
|
|
347
|
-
let t = token;
|
|
498
|
+
let t = token || this.context()?.token || '';
|
|
348
499
|
if (!t && !inSandbox && tokenEnv)
|
|
349
500
|
t = tokenEnv;
|
|
350
501
|
let rf = '';
|
|
@@ -352,11 +503,11 @@ class Input {
|
|
|
352
503
|
let cs = '';
|
|
353
504
|
let ct = '';
|
|
354
505
|
if (!t) {
|
|
355
|
-
t =
|
|
356
|
-
rf =
|
|
357
|
-
cid =
|
|
358
|
-
cs =
|
|
359
|
-
ct =
|
|
506
|
+
t = cfg_2.default.getApiToken();
|
|
507
|
+
rf = cfg_2.default.getApiRefreshApiToken();
|
|
508
|
+
cid = cfg_2.default.getApiClientId();
|
|
509
|
+
cs = cfg_2.default.getApiClientSecret();
|
|
510
|
+
ct = cfg_2.default.getApiClientToken();
|
|
360
511
|
}
|
|
361
512
|
if (!t && inSandbox && tokenEnv)
|
|
362
513
|
t = tokenEnv;
|
|
@@ -869,13 +1020,13 @@ class Input {
|
|
|
869
1020
|
return null;
|
|
870
1021
|
}
|
|
871
1022
|
static restApiBaseUrl(api = '', region = '', token = '') {
|
|
872
|
-
let u = api;
|
|
1023
|
+
let u = api || this.context()?.api || '';
|
|
873
1024
|
if (!u)
|
|
874
1025
|
u = this.restApiBaseUrlFromToken(token);
|
|
875
1026
|
if (!u)
|
|
876
1027
|
u = process.env.BUDDY_API_ENDPOINT || null;
|
|
877
1028
|
if (!u)
|
|
878
|
-
u =
|
|
1029
|
+
u = cfg_2.default.getBaseUrl();
|
|
879
1030
|
if (!u) {
|
|
880
1031
|
const r = region || process.env.BUDDY_REGION;
|
|
881
1032
|
if (r?.toLowerCase() === utils_1.REST_API_REGION.EU) {
|
|
@@ -907,18 +1058,25 @@ class Input {
|
|
|
907
1058
|
return p;
|
|
908
1059
|
}
|
|
909
1060
|
static restApiWorkspace(workspace, allowNull, ignoreProjectConfig = false) {
|
|
1061
|
+
if (!ignoreProjectConfig && this.context()) {
|
|
1062
|
+
const value = workspace || this.contextScope()?.workspace;
|
|
1063
|
+
if (value)
|
|
1064
|
+
return value;
|
|
1065
|
+
if (allowNull)
|
|
1066
|
+
return null;
|
|
1067
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_REST_API_WORKSPACE, texts_1.TXT_CONTEXT_WORKSPACE_HINT);
|
|
1068
|
+
}
|
|
910
1069
|
// Inside a sandbox, cfg/project cfg (set by an explicit `bdy login` or .bdy/cfg.json)
|
|
911
1070
|
// takes precedence over the sandbox-injected BUDDY_WORKSPACE env var.
|
|
912
1071
|
// Outside a sandbox, env beats cfg.
|
|
913
|
-
const ProjectCfg = require('./project/cfg').default;
|
|
914
1072
|
let w = workspace;
|
|
915
1073
|
const inSandbox = (0, utils_1.isInSandbox)();
|
|
916
1074
|
if (!w && !inSandbox && process.env.BUDDY_WORKSPACE)
|
|
917
1075
|
w = process.env.BUDDY_WORKSPACE;
|
|
918
1076
|
if (!w && !ignoreProjectConfig)
|
|
919
|
-
w = ProjectCfg.getWorkspace();
|
|
920
|
-
if (!w)
|
|
921
1077
|
w = cfg_1.default.getWorkspace();
|
|
1078
|
+
if (!w)
|
|
1079
|
+
w = cfg_2.default.getWorkspace();
|
|
922
1080
|
if (!w && inSandbox && process.env.BUDDY_WORKSPACE)
|
|
923
1081
|
w = process.env.BUDDY_WORKSPACE;
|
|
924
1082
|
if (!w) {
|
|
@@ -1242,17 +1400,40 @@ class Input {
|
|
|
1242
1400
|
sandboxId = await client.findSandboxByIdentifier(workspace, identifier, project, environmentId);
|
|
1243
1401
|
}
|
|
1244
1402
|
if (!sandboxId) {
|
|
1245
|
-
|
|
1403
|
+
throw new cliError_1.default('not_found', texts_1.ERR_SANDBOX_NOT_FOUND);
|
|
1246
1404
|
}
|
|
1247
1405
|
return sandboxId;
|
|
1248
1406
|
}
|
|
1249
1407
|
static restApiProject(project, allowNull) {
|
|
1250
|
-
const
|
|
1408
|
+
const context = this.context();
|
|
1409
|
+
if (context) {
|
|
1410
|
+
let value = project;
|
|
1411
|
+
if (!value) {
|
|
1412
|
+
let scope;
|
|
1413
|
+
try {
|
|
1414
|
+
scope = this.contextScope();
|
|
1415
|
+
}
|
|
1416
|
+
catch (err) {
|
|
1417
|
+
// An explicit workspace is sufficient for workspace-scoped commands.
|
|
1418
|
+
// If the dynamic source is unavailable, none of its project can carry over.
|
|
1419
|
+
if (!this.contextOptions.workspace || context.source === 'explicit')
|
|
1420
|
+
throw err;
|
|
1421
|
+
}
|
|
1422
|
+
const changedWorkspace = this.contextOptions.workspace && this.contextOptions.workspace !== scope?.workspace;
|
|
1423
|
+
if (!changedWorkspace)
|
|
1424
|
+
value = scope?.project || '';
|
|
1425
|
+
}
|
|
1426
|
+
if (value)
|
|
1427
|
+
return value;
|
|
1428
|
+
if (allowNull)
|
|
1429
|
+
return null;
|
|
1430
|
+
throw new cliError_1.default('usage_error', texts_1.ERR_REST_API_PROJECT, texts_1.TXT_CONTEXT_PROJECT_HINT);
|
|
1431
|
+
}
|
|
1251
1432
|
let p = process.env.BUDDY_PROJECT;
|
|
1252
1433
|
if (project)
|
|
1253
1434
|
p = project;
|
|
1254
1435
|
if (!p)
|
|
1255
|
-
p =
|
|
1436
|
+
p = cfg_1.default.getProject();
|
|
1256
1437
|
if (!p) {
|
|
1257
1438
|
if (allowNull)
|
|
1258
1439
|
return null;
|
|
@@ -1330,14 +1511,14 @@ class Input {
|
|
|
1330
1511
|
const workspace = Input.restApiWorkspace('', true);
|
|
1331
1512
|
const project = Input.restApiProject('', true);
|
|
1332
1513
|
let fromLogin = false;
|
|
1333
|
-
if (!token &&
|
|
1514
|
+
if (!token && (this.context() ? this.restApiToken(true).token : cfg_2.default.getApiToken()) && workspace) {
|
|
1334
1515
|
const client = Input.restApiTokenClient();
|
|
1335
1516
|
const result = await client.getTunnelToken(workspace, project);
|
|
1336
1517
|
token = String(result?.token || '');
|
|
1337
1518
|
fromLogin = true;
|
|
1338
1519
|
}
|
|
1339
1520
|
else if (!token) {
|
|
1340
|
-
token =
|
|
1521
|
+
token = cfg_2.default.getToken();
|
|
1341
1522
|
}
|
|
1342
1523
|
if (!token)
|
|
1343
1524
|
throw new Error(texts_1.ERR_TOKEN_NOT_PROVIDED);
|
|
@@ -1350,7 +1531,7 @@ class Input {
|
|
|
1350
1531
|
throw new Error(texts_1.ERR_WRONG_TOKEN);
|
|
1351
1532
|
}
|
|
1352
1533
|
if (!fromLogin)
|
|
1353
|
-
|
|
1534
|
+
cfg_2.default.setToken(token);
|
|
1354
1535
|
return {
|
|
1355
1536
|
token,
|
|
1356
1537
|
host: d.host,
|
|
@@ -1382,9 +1563,8 @@ class Input {
|
|
|
1382
1563
|
const envToken = process.env.BUDDY_VT_TOKEN;
|
|
1383
1564
|
if (envToken)
|
|
1384
1565
|
return envToken;
|
|
1385
|
-
const
|
|
1386
|
-
|
|
1387
|
-
if (suiteIdentifier && (cfg_1.default.getApiToken() || process.env.BUDDY_TOKEN)) {
|
|
1566
|
+
const suiteIdentifier = cfg_1.default.getVtSuite();
|
|
1567
|
+
if (suiteIdentifier && this.restApiToken(true).token) {
|
|
1388
1568
|
const workspace = Input.restApiWorkspace('', true);
|
|
1389
1569
|
const project = Input.restApiProject('', true);
|
|
1390
1570
|
if (workspace && project) {
|
|
@@ -1402,9 +1582,8 @@ class Input {
|
|
|
1402
1582
|
const envToken = process.env.BUDDY_CRAWL_TOKEN;
|
|
1403
1583
|
if (envToken)
|
|
1404
1584
|
return envToken;
|
|
1405
|
-
const
|
|
1406
|
-
|
|
1407
|
-
if (suiteIdentifier && (cfg_1.default.getApiToken() || process.env.BUDDY_TOKEN)) {
|
|
1585
|
+
const suiteIdentifier = cfg_1.default.getCrawlSuite();
|
|
1586
|
+
if (suiteIdentifier && this.restApiToken(true).token) {
|
|
1408
1587
|
const workspace = Input.restApiWorkspace('', true);
|
|
1409
1588
|
const project = Input.restApiProject('', true);
|
|
1410
1589
|
if (workspace && project) {
|
|
@@ -1422,9 +1601,8 @@ class Input {
|
|
|
1422
1601
|
const envToken = process.env.BUDDY_UT_TOKEN;
|
|
1423
1602
|
if (envToken)
|
|
1424
1603
|
return envToken;
|
|
1425
|
-
const
|
|
1426
|
-
|
|
1427
|
-
if (suiteIdentifier && (cfg_1.default.getApiToken() || process.env.BUDDY_TOKEN)) {
|
|
1604
|
+
const suiteIdentifier = cfg_1.default.getUtSuite();
|
|
1605
|
+
if (suiteIdentifier && this.restApiToken(true).token) {
|
|
1428
1606
|
const workspace = Input.restApiWorkspace('', true);
|
|
1429
1607
|
const project = Input.restApiProject('', true);
|
|
1430
1608
|
if (workspace && project) {
|
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
const output_1 = __importDefault(require("../output"));
|
|
40
|
+
const cliError_1 = __importStar(require("../cliError"));
|
|
41
|
+
const texts_1 = require("../texts");
|
|
7
42
|
const pipeline_1 = require("../types/pipeline");
|
|
8
43
|
const utils_1 = require("../utils");
|
|
9
44
|
// @ts-ignore
|
|
@@ -24,17 +59,21 @@ var MODE;
|
|
|
24
59
|
})(MODE || (MODE = {}));
|
|
25
60
|
const LOGS_LIMIT = 1000;
|
|
26
61
|
class OutputPipeline {
|
|
27
|
-
static async runLogs(client, workspace, project, identifier, pipelineId, runId, runActionId, noWait, isJson) {
|
|
28
|
-
if (output_1.default.isTTY() && !noWait && !isJson) {
|
|
62
|
+
static async runLogs(client, workspace, project, identifier, pipelineId, runId, runActionId, noWait, isJson, semanticExitCode = false) {
|
|
63
|
+
if (output_1.default.isTTY() && !noWait && !isJson && !semanticExitCode) {
|
|
29
64
|
return await this._runLogsInteractive(client, workspace, project, pipelineId, runId, runActionId);
|
|
30
65
|
}
|
|
31
|
-
return await this._runLogsNonInteractive(client, workspace, project, identifier, pipelineId, runId, runActionId, noWait, isJson);
|
|
66
|
+
return await this._runLogsNonInteractive(client, workspace, project, identifier, pipelineId, runId, runActionId, noWait, isJson, semanticExitCode);
|
|
32
67
|
}
|
|
33
|
-
static async runStatus(client, workspace, project, identifier, pipelineId, runId, noWait, noFollow, isJson) {
|
|
34
|
-
if (output_1.default.isTTY() &&
|
|
68
|
+
static async runStatus(client, workspace, project, identifier, pipelineId, runId, noWait, noFollow, isJson, semanticExitCode = false) {
|
|
69
|
+
if (output_1.default.isTTY() &&
|
|
70
|
+
!noWait &&
|
|
71
|
+
!noFollow &&
|
|
72
|
+
!isJson &&
|
|
73
|
+
!semanticExitCode) {
|
|
35
74
|
return await this._runStatusInteractive(client, workspace, project, pipelineId, runId);
|
|
36
75
|
}
|
|
37
|
-
return await this._runStatusNonInteractive(client, workspace, project, identifier, pipelineId, runId, noWait, noFollow, isJson);
|
|
76
|
+
return await this._runStatusNonInteractive(client, workspace, project, identifier, pipelineId, runId, noWait, noFollow, isJson, semanticExitCode);
|
|
38
77
|
}
|
|
39
78
|
static _canCancel(status) {
|
|
40
79
|
return ![
|
|
@@ -1082,19 +1121,39 @@ class OutputPipeline {
|
|
|
1082
1121
|
draw();
|
|
1083
1122
|
}, true);
|
|
1084
1123
|
}
|
|
1085
|
-
static
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1124
|
+
static runExitCode(status) {
|
|
1125
|
+
switch (status) {
|
|
1126
|
+
case pipeline_1.PIPELINE_RUN_STATUS.SUCCESSFUL:
|
|
1127
|
+
return cliError_1.SemanticExitCode.SUCCESS;
|
|
1128
|
+
case pipeline_1.PIPELINE_RUN_STATUS.FAILED:
|
|
1129
|
+
case pipeline_1.PIPELINE_RUN_STATUS.TERMINATED:
|
|
1130
|
+
case pipeline_1.PIPELINE_RUN_STATUS.SKIPPED:
|
|
1131
|
+
case pipeline_1.PIPELINE_RUN_STATUS.NOT_EXECUTED:
|
|
1132
|
+
return cliError_1.SemanticExitCode.FAILURE;
|
|
1133
|
+
case pipeline_1.PIPELINE_RUN_STATUS.INITIAL:
|
|
1134
|
+
case pipeline_1.PIPELINE_RUN_STATUS.ENQUEUED:
|
|
1135
|
+
case pipeline_1.PIPELINE_RUN_STATUS.INPROGRESS:
|
|
1136
|
+
case pipeline_1.PIPELINE_RUN_STATUS.TERMINATING:
|
|
1137
|
+
case pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_APPLY:
|
|
1138
|
+
case pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VARIABLES:
|
|
1139
|
+
case pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_SETTABLE_VARIABLES:
|
|
1140
|
+
case pipeline_1.PIPELINE_RUN_STATUS.WAITING_FOR_VT_SESSION:
|
|
1141
|
+
return cliError_1.SemanticExitCode.PENDING;
|
|
1142
|
+
default:
|
|
1143
|
+
throw new cliError_1.default('command_failed', (0, texts_1.ERR_PIPELINE_RUN_STATUS_UNKNOWN)(status));
|
|
1096
1144
|
}
|
|
1097
1145
|
}
|
|
1146
|
+
static _exitByStatus(isJson, status, semanticExitCode = false) {
|
|
1147
|
+
const code = semanticExitCode
|
|
1148
|
+
? this.runExitCode(status)
|
|
1149
|
+
: status === pipeline_1.PIPELINE_RUN_STATUS.FAILED ||
|
|
1150
|
+
status === pipeline_1.PIPELINE_RUN_STATUS.TERMINATED
|
|
1151
|
+
? 1
|
|
1152
|
+
: 0;
|
|
1153
|
+
if (isJson)
|
|
1154
|
+
this.jsonExit(code);
|
|
1155
|
+
output_1.default.exitCode(code);
|
|
1156
|
+
}
|
|
1098
1157
|
static jsonExit(code) {
|
|
1099
1158
|
output_1.default.json({ type: 'exit', code });
|
|
1100
1159
|
}
|
|
@@ -1124,7 +1183,7 @@ class OutputPipeline {
|
|
|
1124
1183
|
static jsonLog(log) {
|
|
1125
1184
|
output_1.default.json({ type: 'log', log });
|
|
1126
1185
|
}
|
|
1127
|
-
static async _runLogsNonInteractive(client, workspace, project, identifier, pipelineId, runId, runActionId, noWait, isJson) {
|
|
1186
|
+
static async _runLogsNonInteractive(client, workspace, project, identifier, pipelineId, runId, runActionId, noWait, isJson, semanticExitCode = false) {
|
|
1128
1187
|
let action = null;
|
|
1129
1188
|
let actionLogsStart = 0;
|
|
1130
1189
|
let lastActionLogsStart = -1;
|
|
@@ -1252,7 +1311,7 @@ class OutputPipeline {
|
|
|
1252
1311
|
}
|
|
1253
1312
|
}
|
|
1254
1313
|
}
|
|
1255
|
-
this._exitByStatus(isJson, action?.status);
|
|
1314
|
+
this._exitByStatus(isJson, action?.status, semanticExitCode);
|
|
1256
1315
|
}
|
|
1257
1316
|
};
|
|
1258
1317
|
this._actionLogsLoop(client, workspace, project, pipelineId, runId, runActionId, draw)
|
|
@@ -1263,10 +1322,12 @@ class OutputPipeline {
|
|
|
1263
1322
|
action = a;
|
|
1264
1323
|
totalFetchesCount += 1;
|
|
1265
1324
|
draw();
|
|
1325
|
+
if (semanticExitCode)
|
|
1326
|
+
this.runExitCode(a.status);
|
|
1266
1327
|
}
|
|
1267
|
-
});
|
|
1328
|
+
}, false, semanticExitCode);
|
|
1268
1329
|
}
|
|
1269
|
-
static async _runStatusNonInteractive(client, workspace, project, identifier, pipelineId, runId, noWait, noFollow, isJson) {
|
|
1330
|
+
static async _runStatusNonInteractive(client, workspace, project, identifier, pipelineId, runId, noWait, noFollow, isJson, semanticExitCode = false) {
|
|
1270
1331
|
let run = null;
|
|
1271
1332
|
let totalFetchesCount = 0;
|
|
1272
1333
|
const tabs = 40;
|
|
@@ -1342,10 +1403,25 @@ class OutputPipeline {
|
|
|
1342
1403
|
else
|
|
1343
1404
|
draw(run);
|
|
1344
1405
|
}
|
|
1406
|
+
if (semanticExitCode) {
|
|
1407
|
+
try {
|
|
1408
|
+
this.runExitCode(run.status);
|
|
1409
|
+
}
|
|
1410
|
+
catch (error) {
|
|
1411
|
+
// Even --no-follow must identify the run before reporting an unknown status.
|
|
1412
|
+
if (noFollow && !noWait) {
|
|
1413
|
+
if (isJson)
|
|
1414
|
+
this.jsonRun(identifier, run);
|
|
1415
|
+
else
|
|
1416
|
+
draw(run);
|
|
1417
|
+
}
|
|
1418
|
+
throw error;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1345
1421
|
if (noWait) {
|
|
1346
|
-
this._exitByStatus(isJson, run.status);
|
|
1422
|
+
this._exitByStatus(isJson, run.status, semanticExitCode);
|
|
1347
1423
|
}
|
|
1348
|
-
});
|
|
1424
|
+
}, false, semanticExitCode);
|
|
1349
1425
|
if (isJson) {
|
|
1350
1426
|
this.jsonRun(identifier, run);
|
|
1351
1427
|
}
|
|
@@ -1389,7 +1465,7 @@ class OutputPipeline {
|
|
|
1389
1465
|
output_1.default.normal(this._dimLine());
|
|
1390
1466
|
output_1.default.normal(this._runActionsLogsHelp(identifier, runId));
|
|
1391
1467
|
}
|
|
1392
|
-
this._exitByStatus(isJson, run.status);
|
|
1468
|
+
this._exitByStatus(isJson, run.status, semanticExitCode);
|
|
1393
1469
|
}
|
|
1394
1470
|
static async _actionLogsLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange) {
|
|
1395
1471
|
let logs = [];
|
|
@@ -1419,7 +1495,7 @@ class OutputPipeline {
|
|
|
1419
1495
|
await (0, utils_1.sleep)(3000);
|
|
1420
1496
|
}
|
|
1421
1497
|
}
|
|
1422
|
-
static async _actionStatusLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange, dontExit = false) {
|
|
1498
|
+
static async _actionStatusLoop(client, workspace, project, pipelineId, runId, actionExecutionId, onChange, dontExit = false, semanticExitCode = false) {
|
|
1423
1499
|
const fetchAction = async () => {
|
|
1424
1500
|
return await client.getPipelineRunActionExecution(workspace, project, pipelineId, runId, actionExecutionId);
|
|
1425
1501
|
};
|
|
@@ -1437,7 +1513,9 @@ class OutputPipeline {
|
|
|
1437
1513
|
let finished = null;
|
|
1438
1514
|
if (a.finish_date)
|
|
1439
1515
|
finished = new Date(a.finish_date);
|
|
1440
|
-
status =
|
|
1516
|
+
status = semanticExitCode
|
|
1517
|
+
? a.status
|
|
1518
|
+
: a.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
|
|
1441
1519
|
const name = a.action?.name || '';
|
|
1442
1520
|
const actionId = a.action?.id || -1;
|
|
1443
1521
|
const url = a.html_url || '';
|
|
@@ -1514,7 +1592,7 @@ class OutputPipeline {
|
|
|
1514
1592
|
return;
|
|
1515
1593
|
}
|
|
1516
1594
|
}
|
|
1517
|
-
static async _runStatusLoop(client, workspace, project, pipelineId, runId, onChange, dontExit = false) {
|
|
1595
|
+
static async _runStatusLoop(client, workspace, project, pipelineId, runId, onChange, dontExit = false, semanticExitCode = false) {
|
|
1518
1596
|
let lastRun;
|
|
1519
1597
|
const fetchRun = async () => {
|
|
1520
1598
|
return await client.getPipelineRun(workspace, project, pipelineId, runId);
|
|
@@ -1537,7 +1615,9 @@ class OutputPipeline {
|
|
|
1537
1615
|
const run = await fetchRun();
|
|
1538
1616
|
started = new Date(run.start_date || new Date());
|
|
1539
1617
|
trigger = run.triggered_on || pipeline_1.PIPELINE_RUN_TRIGGER.CLICK;
|
|
1540
|
-
status =
|
|
1618
|
+
status = semanticExitCode
|
|
1619
|
+
? run.status
|
|
1620
|
+
: run.status || pipeline_1.PIPELINE_RUN_STATUS.INITIAL;
|
|
1541
1621
|
url = run.html_url;
|
|
1542
1622
|
if (run.creator) {
|
|
1543
1623
|
if (run.creator.name)
|
package/distTs/src/output.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -7,7 +40,7 @@ const texts_1 = require("./texts");
|
|
|
7
40
|
const utils_1 = require("./utils");
|
|
8
41
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
42
|
const node_readline_1 = require("node:readline");
|
|
10
|
-
const cliError_1 =
|
|
43
|
+
const cliError_1 = __importStar(require("./cliError"));
|
|
11
44
|
let _terminal = null;
|
|
12
45
|
function getTerminal() {
|
|
13
46
|
if (!_terminal) {
|
|
@@ -18,6 +51,7 @@ function getTerminal() {
|
|
|
18
51
|
}
|
|
19
52
|
class Output {
|
|
20
53
|
static errorFormat = 'text';
|
|
54
|
+
static errorExitCode = 1;
|
|
21
55
|
static s;
|
|
22
56
|
static _a;
|
|
23
57
|
static getCyanColor(text) {
|
|
@@ -341,7 +375,7 @@ class Output {
|
|
|
341
375
|
}
|
|
342
376
|
});
|
|
343
377
|
}
|
|
344
|
-
static async confirm(message = 'Are you sure?') {
|
|
378
|
+
static async confirm(message = 'Are you sure?', quiet = false) {
|
|
345
379
|
if (this.isStdInTTY()) {
|
|
346
380
|
const prompts = require('@inquirer/prompts');
|
|
347
381
|
try {
|
|
@@ -349,15 +383,17 @@ class Output {
|
|
|
349
383
|
message,
|
|
350
384
|
theme: this.getInquirerTheme(),
|
|
351
385
|
default: false,
|
|
352
|
-
});
|
|
386
|
+
}, quiet ? { output: process.stderr } : undefined);
|
|
353
387
|
}
|
|
354
388
|
catch {
|
|
355
389
|
this.exitError(texts_1.ERR_CANCELLED);
|
|
356
390
|
}
|
|
357
391
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
392
|
+
if (!quiet) {
|
|
393
|
+
this.cyan('? ', false);
|
|
394
|
+
this.label(message, false);
|
|
395
|
+
this.cyan(` No`);
|
|
396
|
+
}
|
|
361
397
|
return false;
|
|
362
398
|
}
|
|
363
399
|
static async inputString(message, def, required, signal) {
|
|
@@ -693,11 +729,13 @@ class Output {
|
|
|
693
729
|
}
|
|
694
730
|
}
|
|
695
731
|
}
|
|
696
|
-
static exitError(err) {
|
|
732
|
+
static exitError(err, code = this.errorExitCode) {
|
|
733
|
+
if (code === cliError_1.SemanticExitCode.ERROR && cliError_1.default.details(err).code === 'not_found')
|
|
734
|
+
code = cliError_1.SemanticExitCode.NOT_FOUND;
|
|
697
735
|
this.clearUndici();
|
|
698
736
|
this.clearTerminal();
|
|
699
737
|
this.writeError(err);
|
|
700
|
-
process.exit(
|
|
738
|
+
process.exit(code);
|
|
701
739
|
}
|
|
702
740
|
static writeError(err, format = this.errorFormat) {
|
|
703
741
|
const error = cliError_1.default.details(err);
|