@commercetools-frontend/deployment-cli 2.0.0 → 2.0.1

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.
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var cac = require('cac');
6
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
7
6
  var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
8
7
  var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
9
8
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
10
9
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
11
10
  var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
11
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
12
12
  var cosmiconfig = require('cosmiconfig');
13
13
  var merge = require('lodash/merge');
14
14
  var prompts = require('prompts');
@@ -22,12 +22,12 @@ var node_process = require('node:process');
22
22
 
23
23
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
24
24
 
25
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
26
25
  var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
27
26
  var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
28
27
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
29
28
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
30
29
  var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
30
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
31
31
  var merge__default = /*#__PURE__*/_interopDefault(merge);
32
32
  var prompts__default = /*#__PURE__*/_interopDefault(prompts);
33
33
  var pRetry__default = /*#__PURE__*/_interopDefault(pRetry);
@@ -38,7 +38,7 @@ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
38
38
 
39
39
  var pkgJson = {
40
40
  name: "@commercetools-frontend/deployment-cli",
41
- version: "2.0.0",
41
+ version: "2.0.1",
42
42
  description: "CLI to manage Custom Applications deployments in Google Storage.",
43
43
  keywords: [
44
44
  "commercetools",
@@ -73,7 +73,7 @@ var pkgJson = {
73
73
  devDependencies: {
74
74
  "@tsconfig/node20": "20.1.4",
75
75
  "@types/lodash": "^4.14.198",
76
- "@types/node": "20.12.12",
76
+ "@types/node": "20.14.14",
77
77
  "@types/prompts": "2.4.9",
78
78
  msw: "1.3.3",
79
79
  typescript: "5.2.2"
@@ -110,7 +110,7 @@ async function loadConfig() {
110
110
  };
111
111
  try {
112
112
  const cosmiconfigResult = await deploymentConfigExplorer.search();
113
- const mergedConfig = merge__default["default"](defaultConfig, cosmiconfigResult === null || cosmiconfigResult === void 0 ? void 0 : cosmiconfigResult.config);
113
+ const mergedConfig = merge__default["default"](defaultConfig, cosmiconfigResult?.config);
114
114
  return mergedConfig;
115
115
  } catch (e) {
116
116
  console.warn(e);
@@ -119,13 +119,13 @@ async function loadConfig() {
119
119
  }
120
120
  function throwIfConfigurationLacksRequiredValues(parsedConfiguration) {
121
121
  if (!parsedConfiguration.CircleCI.projectName) {
122
- throw new Error("Missing 'projectName' in 'CircleCI' on configuration. Make sure it exists!");
122
+ throw new Error(`Missing 'projectName' in 'CircleCI' on configuration. Make sure it exists!`);
123
123
  }
124
124
  }
125
125
  function throwIfRequiredEnvironmentVariableIsUnset(requiredEnvironmentVariables) {
126
126
  _forEachInstanceProperty__default["default"](requiredEnvironmentVariables).call(requiredEnvironmentVariables, nameOfRequiredEnvironmentVariable => {
127
127
  const valueOfRequiredEnvironmentVariable = process.env[nameOfRequiredEnvironmentVariable];
128
- if (!valueOfRequiredEnvironmentVariable) throw new Error("Missing '".concat(nameOfRequiredEnvironmentVariable, "' environment variable"));
128
+ if (!valueOfRequiredEnvironmentVariable) throw new Error(`Missing '${nameOfRequiredEnvironmentVariable}' environment variable`);
129
129
  });
130
130
  }
131
131
  const promptOptions = {
@@ -151,23 +151,19 @@ const promptOptions = {
151
151
  type: 'select',
152
152
  name: 'deploymentPipeline',
153
153
  message: 'Select the revision you would like to deploy',
154
- choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, deploymentPipeline => {
155
- var _context, _context2;
156
- return {
157
- title: _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(deploymentPipeline.vcs.revision.substring(0, 7), " - ")).call(_context2, deploymentPipeline.vcs.commit.subject, " <")).call(_context, deploymentPipeline.trigger.actor.login, ">"),
158
- value: deploymentPipeline
159
- };
160
- })
154
+ choices: _mapInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, deploymentPipeline => ({
155
+ title: `${deploymentPipeline.vcs.revision.substring(0, 7)} - ${deploymentPipeline.vcs.commit.subject} <${deploymentPipeline.trigger.actor.login}>`,
156
+ value: deploymentPipeline
157
+ }))
161
158
  };
162
159
  },
163
160
  deploymentConfirmation: _ref4 => {
164
- var _context3;
165
161
  let approvalJob = _ref4.approvalJob,
166
162
  revision = _ref4.revision;
167
163
  return {
168
164
  type: 'toggle',
169
165
  name: 'confirmed',
170
- message: _concatInstanceProperty__default["default"](_context3 = "Are you sure you want to deploy by approving ".concat(approvalJob, " at ")).call(_context3, revision, "?"),
166
+ message: `Are you sure you want to deploy by approving ${approvalJob} at ${revision}?`,
171
167
  initial: false,
172
168
  active: 'Yes',
173
169
  inactive: 'No'
@@ -184,7 +180,7 @@ async function paginateToDeploymentPipeline(_ref5) {
184
180
  let nextPageToken;
185
181
  // eslint-disable-next-line no-plusplus
186
182
  for (let i = 0; i < maxPages; i++) {
187
- var _context4, _context5;
183
+ var _context, _context2;
188
184
  // eslint-disable-next-line no-await-in-loop
189
185
 
190
186
  const pipelineRequest = circleCiApis.pipelines({
@@ -195,19 +191,18 @@ async function paginateToDeploymentPipeline(_ref5) {
195
191
  debug
196
192
  });
197
193
  nextPageToken = pipelines.next_page_token;
198
- const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context4 = _filterInstanceProperty__default["default"](_context5 = pipelines.items).call(_context5, isNonScheduledPipeline)).call(_context4, isNonErroredPipeline);
194
+ const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context = _filterInstanceProperty__default["default"](_context2 = pipelines.items).call(_context2, isNonScheduledPipeline)).call(_context, isNonErroredPipeline);
199
195
  if (buildRevision) {
200
- var _context6, _context7;
201
- console.log(_concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = "\uD83D\uDD04 Trying to find pipeline with revision ".concat(buildRevision, ". Attempt ")).call(_context7, i + 1, " out of ")).call(_context6, maxPages, "."));
196
+ console.log(`🔄 Trying to find pipeline with revision ${buildRevision}. Attempt ${i + 1} out of ${maxPages}.`);
202
197
  deploymentPipeline = _findInstanceProperty__default["default"](nonScheduledPipelines).call(nonScheduledPipelines, pipeline => {
203
- var _context8;
204
- return _startsWithInstanceProperty__default["default"](_context8 = pipeline.vcs.revision).call(_context8, buildRevision);
198
+ var _context3;
199
+ return _startsWithInstanceProperty__default["default"](_context3 = pipeline.vcs.revision).call(_context3, buildRevision);
205
200
  });
206
201
  } else {
207
202
  deploymentPipeline = nonScheduledPipelines[0];
208
203
  }
209
204
  if (deploymentPipeline) {
210
- console.log("\u2139\uFE0F Using pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
205
+ console.log(`â„šī¸ Using pipeline for deployment with revision ${deploymentPipeline.vcs.revision}.`);
211
206
  break;
212
207
  }
213
208
  }
@@ -222,7 +217,7 @@ async function collectDeploymentPipelines(_ref6) {
222
217
  let nextPageToken;
223
218
  // eslint-disable-next-line no-plusplus
224
219
  for (let i = 0; i < pagesForPipelineSelection; i++) {
225
- var _context9, _context10;
220
+ var _context4, _context5;
226
221
  // eslint-disable-next-line no-await-in-loop
227
222
  const pipelinesRequest = circleCiApis.pipelines({
228
223
  pageToken: nextPageToken,
@@ -231,7 +226,7 @@ async function collectDeploymentPipelines(_ref6) {
231
226
  const pipelines = await pipelinesRequest.execute({
232
227
  debug
233
228
  });
234
- const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context9 = _filterInstanceProperty__default["default"](_context10 = pipelines.items).call(_context10, isNonScheduledPipeline)).call(_context9, isNonErroredPipeline);
229
+ const nonScheduledPipelines = _filterInstanceProperty__default["default"](_context4 = _filterInstanceProperty__default["default"](_context5 = pipelines.items).call(_context5, isNonScheduledPipeline)).call(_context4, isNonErroredPipeline);
235
230
  deploymentPipelines = _concatInstanceProperty__default["default"](deploymentPipelines).call(deploymentPipelines, nonScheduledPipelines);
236
231
  }
237
232
  return deploymentPipelines;
@@ -270,12 +265,11 @@ async function waitForConfirmationPrompt(_ref8) {
270
265
  }));
271
266
  }
272
267
  function getJobUrl(_ref9) {
273
- var _context11, _context12, _context13;
274
268
  let pipelineNumber = _ref9.pipelineNumber,
275
269
  workflowId = _ref9.workflowId,
276
270
  jobNumber = _ref9.jobNumber,
277
271
  projectName = _ref9.projectName;
278
- return _concatInstanceProperty__default["default"](_context11 = _concatInstanceProperty__default["default"](_context12 = _concatInstanceProperty__default["default"](_context13 = "https://app.circleci.com/pipelines/github/commercetools/".concat(projectName, "/")).call(_context13, pipelineNumber, "/workflows/")).call(_context12, workflowId, "/jobs/")).call(_context11, jobNumber);
272
+ return `https://app.circleci.com/pipelines/github/commercetools/${projectName}/${pipelineNumber}/workflows/${workflowId}/jobs/${jobNumber}`;
279
273
  }
280
274
  function isNonScheduledPipeline(pipeline) {
281
275
  return pipeline.trigger.type !== 'schedule' && pipeline.trigger.type !== 'scheduled_pipeline';
@@ -289,14 +283,14 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
289
283
  circleCiApis = _ref10.circleCiApis;
290
284
  let debug = _ref11.debug;
291
285
  const fetchDeploymentJobNumber = async () => {
292
- var _context14;
286
+ var _context6;
293
287
  const jobsRequest = circleCiApis.jobs({
294
288
  workflowId
295
289
  });
296
290
  const jobs = await jobsRequest.execute({
297
291
  debug
298
292
  });
299
- const applicationDeploymentJob = _findInstanceProperty__default["default"](_context14 = jobs.items).call(_context14, job => job.name === deploymentJob);
293
+ const applicationDeploymentJob = _findInstanceProperty__default["default"](_context6 = jobs.items).call(_context6, job => job.name === deploymentJob);
300
294
  if (!applicationDeploymentJob || applicationDeploymentJob.status === 'blocked') {
301
295
  throw new Error('Deployment job not yet running. Retrying.');
302
296
  }
@@ -304,8 +298,7 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
304
298
  };
305
299
  const deploymentJobNumber = await pRetry__default["default"](fetchDeploymentJobNumber, {
306
300
  onFailedAttempt: error => {
307
- var _context15;
308
- console.log(_concatInstanceProperty__default["default"](_context15 = "\uD83D\uDD04 Trying to find deployment job. Attempt ".concat(error.attemptNumber, " with ")).call(_context15, error.retriesLeft, " retries left."));
301
+ console.log(`🔄 Trying to find deployment job. Attempt ${error.attemptNumber} with ${error.retriesLeft} retries left.`);
309
302
  },
310
303
  retries: 10
311
304
  });
@@ -313,65 +306,63 @@ async function waitForDeploymentJobNumber(_ref10, _ref11) {
313
306
  }
314
307
 
315
308
  async function approve(cliFlags, config, circleCiApis) {
316
- var _config$CircleCI$pagi, _config$CircleCI$pagi2, _config$CircleCI$pagi3, _config$CircleCI$pagi4, _context2, _context3, _context5, _confirmationPrompt;
309
+ var _context, _context2;
317
310
  let approvalJob;
318
311
  let deploymentJob;
319
312
  if (cliFlags.deployment) {
320
- var _config$deployments, _context;
321
- const requestedDeployment = (_config$deployments = config.deployments) === null || _config$deployments === void 0 ? void 0 : _config$deployments[cliFlags.deployment];
313
+ const requestedDeployment = config.deployments?.[cliFlags.deployment];
322
314
  if (!requestedDeployment) {
323
- throw new Error("\u26A0\uFE0F Deployment ".concat(cliFlags.deployment, " not found in configuration. Make sure it exists."));
315
+ throw new Error(`âš ī¸ Deployment ${cliFlags.deployment} not found in configuration. Make sure it exists.`);
324
316
  }
325
317
  approvalJob = requestedDeployment.jobs.approval;
326
318
  deploymentJob = requestedDeployment.jobs.deployment;
327
- console.log(_concatInstanceProperty__default["default"](_context = "\u2139\uFE0F Approving requested deployment ".concat(cliFlags.deployment, " with approval job ")).call(_context, approvalJob, "."));
319
+ console.log(`â„šī¸ Approving requested deployment ${cliFlags.deployment} with approval job ${approvalJob}.`);
328
320
  } else {
329
321
  approvalJob = cliFlags.approvalJob;
330
322
  deploymentJob = cliFlags.deploymentJob;
331
- console.log("\u2139\uFE0F Approving with approval job ".concat(approvalJob, "."));
323
+ console.log(`â„šī¸ Approving with approval job ${approvalJob}.`);
332
324
  }
333
325
  const deploymentPipeline = cliFlags.yes ? await paginateToDeploymentPipeline({
334
326
  circleCiApis,
335
327
  buildRevision: cliFlags.buildRevision,
336
328
  branch: cliFlags.branch,
337
329
  debug: cliFlags.debug,
338
- maxPages: (_config$CircleCI$pagi = (_config$CircleCI$pagi2 = config.CircleCI.pagination) === null || _config$CircleCI$pagi2 === void 0 ? void 0 : _config$CircleCI$pagi2.maxPages) !== null && _config$CircleCI$pagi !== void 0 ? _config$CircleCI$pagi : 1
330
+ maxPages: config.CircleCI.pagination?.maxPages ?? 1
339
331
  }) : await waitForDeploymentPipelinePrompt({
340
332
  branch: cliFlags.branch,
341
333
  circleCiApis,
342
- pagesForPipelineSelection: (_config$CircleCI$pagi3 = (_config$CircleCI$pagi4 = config.CircleCI.pagination) === null || _config$CircleCI$pagi4 === void 0 ? void 0 : _config$CircleCI$pagi4.pagesForPipelineSelection) !== null && _config$CircleCI$pagi3 !== void 0 ? _config$CircleCI$pagi3 : 1,
334
+ pagesForPipelineSelection: config.CircleCI.pagination?.pagesForPipelineSelection ?? 1,
343
335
  debug: cliFlags.debug
344
336
  });
345
337
  if (!deploymentPipeline) {
346
- throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found in any pipeline for deployment."));
338
+ throw new Error(`âš ī¸ No workflow called ${config.CircleCI.deploymentWorkflowName} found in any pipeline for deployment.`);
347
339
  }
348
- console.log("\u2139\uFE0F Found pipeline for deployment with revision ".concat(deploymentPipeline.vcs.revision, "."));
340
+ console.log(`â„šī¸ Found pipeline for deployment with revision ${deploymentPipeline.vcs.revision}.`);
349
341
  const workflowsRequest = circleCiApis.workflows({
350
342
  pipelineId: deploymentPipeline.id
351
343
  });
352
344
  const workflows = await workflowsRequest.execute({
353
345
  debug: cliFlags.debug
354
346
  });
355
- const buildAndDeployWorkflow = _findInstanceProperty__default["default"](_context2 = workflows.items).call(_context2, workflow => workflow.name === config.CircleCI.deploymentWorkflowName);
347
+ const buildAndDeployWorkflow = _findInstanceProperty__default["default"](_context = workflows.items).call(_context, workflow => workflow.name === config.CircleCI.deploymentWorkflowName);
356
348
  if (!buildAndDeployWorkflow) {
357
- throw new Error("\u26A0\uFE0F No workflow called ".concat(config.CircleCI.deploymentWorkflowName, " found for deployment."));
349
+ throw new Error(`âš ī¸ No workflow called ${config.CircleCI.deploymentWorkflowName} found for deployment.`);
358
350
  }
359
351
  const workflowId = buildAndDeployWorkflow.id;
360
- console.log("\u2139\uFE0F Found workflow to build and deploy with id ".concat(workflowId, "."));
352
+ console.log(`â„šī¸ Found workflow to build and deploy with id ${workflowId}.`);
361
353
  const jobsRequest = circleCiApis.jobs({
362
354
  workflowId
363
355
  });
364
356
  const jobs = await jobsRequest.execute({
365
357
  debug: cliFlags.debug
366
358
  });
367
- console.log("\u2139\uFE0F Found jobs for workflow.");
368
- const applicationApprovalJob = _findInstanceProperty__default["default"](_context3 = jobs.items).call(_context3, job => job.name === approvalJob);
369
- const applicationApprovalJobId = applicationApprovalJob === null || applicationApprovalJob === void 0 ? void 0 : applicationApprovalJob.id;
359
+ console.log(`â„šī¸ Found jobs for workflow.`);
360
+ const applicationApprovalJob = _findInstanceProperty__default["default"](_context2 = jobs.items).call(_context2, job => job.name === approvalJob);
361
+ const applicationApprovalJobId = applicationApprovalJob?.id;
370
362
  if (!applicationApprovalJobId) {
371
- var _context4;
372
- throw new Error(_concatInstanceProperty__default["default"](_context4 = "\u270C\uFE0F Could not find deployment approval job named ".concat(approvalJob, " at revision ")).call(_context4, deploymentPipeline.vcs.revision, ". Maybe try again later."));
363
+ throw new Error(`âœŒī¸ Could not find deployment approval job named ${approvalJob} at revision ${deploymentPipeline.vcs.revision}. Maybe try again later.`);
373
364
  }
374
- console.log(_concatInstanceProperty__default["default"](_context5 = "\u2139\uFE0F Found deployment approval job named ".concat(approvalJob, " with id ")).call(_context5, applicationApprovalJobId, "."));
365
+ console.log(`â„šī¸ Found deployment approval job named ${approvalJob} with id ${applicationApprovalJobId}.`);
375
366
  let confirmationPrompt;
376
367
  if (!cliFlags.yes) {
377
368
  confirmationPrompt = await waitForConfirmationPrompt({
@@ -379,11 +370,11 @@ async function approve(cliFlags, config, circleCiApis) {
379
370
  revision: deploymentPipeline.vcs.revision
380
371
  });
381
372
  }
382
- if (cliFlags.yes || (_confirmationPrompt = confirmationPrompt) !== null && _confirmationPrompt !== void 0 && _confirmationPrompt.confirmed) {
373
+ if (cliFlags.yes || confirmationPrompt?.confirmed) {
383
374
  if (cliFlags.dryRun) {
384
- console.log("\uD83D\uDE4A Not approving deployment job due to dry run.");
375
+ console.log(`🙊 Not approving deployment job due to dry run.`);
385
376
  } else {
386
- console.log("\u2139\uFE0F Approving deployment job.");
377
+ console.log(`â„šī¸ Approving deployment job.`);
387
378
  }
388
379
  const approvalRequest = circleCiApis.approve({
389
380
  workflowId,
@@ -394,11 +385,10 @@ async function approve(cliFlags, config, circleCiApis) {
394
385
  skip: cliFlags.dryRun
395
386
  });
396
387
  if (cliFlags.yes) {
397
- console.log("\u2139\uFE0F Skipping determining deployment job approved by ".concat(approvalJob, " due to '--yes' flag. Please check CircleCI manually."));
388
+ console.log(`â„šī¸ Skipping determining deployment job approved by ${approvalJob} due to '--yes' flag. Please check CircleCI manually.`);
398
389
  } else if (cliFlags.dryRun) {
399
- console.log("\u270C\uFE0F Dry running hence could not determine deployment job approved by ".concat(approvalJob, "."));
390
+ console.log(`âœŒī¸ Dry running hence could not determine deployment job approved by ${approvalJob}.`);
400
391
  } else if (deploymentJob) {
401
- var _context6, _context7;
402
392
  const deploymentJobNumber = await waitForDeploymentJobNumber({
403
393
  workflowId,
404
394
  deploymentJob,
@@ -408,23 +398,22 @@ async function approve(cliFlags, config, circleCiApis) {
408
398
  dryRun: cliFlags.dryRun,
409
399
  yes: cliFlags.yes
410
400
  });
411
- console.log(_concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = "\uD83D\uDE4C The deployment via ".concat(approvalJob, " at revision ")).call(_context7, deploymentPipeline.vcs.revision, " is running at: ")).call(_context6, getJobUrl({
401
+ console.log(`🙌 The deployment via ${approvalJob} at revision ${deploymentPipeline.vcs.revision} is running at: ${getJobUrl({
412
402
  projectName: config.CircleCI.projectName,
413
403
  pipelineNumber: deploymentPipeline.number,
414
404
  workflowId,
415
405
  jobNumber: deploymentJobNumber
416
- })));
406
+ })}`);
417
407
  } else {
418
- console.log("\u2139\uFE0F Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.");
408
+ console.log(`â„šī¸ Skipping determining deployment job as no '--deployment-job' name to wait for was passed. Please check CircleCI manually.`);
419
409
  }
420
410
  } else {
421
- console.log("\u2139\uFE0F Not approving deployment job. Confirm the prompt or use '--yes' option.");
411
+ console.log(`â„šī¸ Not approving deployment job. Confirm the prompt or use '--yes' option.`);
422
412
  }
423
413
  }
424
414
 
425
415
  async function processCircleCiResponse(response) {
426
416
  if (!response.ok) {
427
- var _context, _context2;
428
417
  /**
429
418
  * NOTE:
430
419
  * Trying to handle known but undocumented responses of the CircleCI API.
@@ -450,7 +439,8 @@ async function processCircleCiResponse(response) {
450
439
  } catch {
451
440
  // Ignore JSON parsing errors
452
441
  }
453
- throw new Error(_concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(response.status, ": Network response was not ok.\n\n Status text is ")).call(_context2, response.statusText, " and text is ")).call(_context, error, "."));
442
+ throw new Error(`${response.status}: Network response was not ok.\n
443
+ Status text is ${response.statusText} and text is ${error}.`);
454
444
  }
455
445
  return response.json();
456
446
  }
@@ -458,11 +448,10 @@ function createCircleCiClient(_ref) {
458
448
  let projectName = _ref.projectName,
459
449
  apiBaseUrl = _ref.apiBaseUrl;
460
450
  async function execute(api) {
461
- var _context3;
462
451
  let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
463
452
  skip = _ref2.skip,
464
453
  debug = _ref2.debug;
465
- let url = _concatInstanceProperty__default["default"](_context3 = "".concat(apiBaseUrl)).call(_context3, api.url);
454
+ let url = `${apiBaseUrl}${api.url}`;
466
455
  if (api.params && api.method === 'GET') {
467
456
  const urlSearchParams = new _URLSearchParams__default["default"]();
468
457
  for (const _ref3 of _Object$entries__default["default"](api.params)) {
@@ -473,18 +462,18 @@ function createCircleCiClient(_ref) {
473
462
  urlSearchParams.append(key, value);
474
463
  }
475
464
  }
476
- url += "?".concat(urlSearchParams.toString());
465
+ url += `?${urlSearchParams.toString()}`;
477
466
  }
478
467
  if (skip) {
479
468
  if (debug) {
480
- console.log("\uD83C\uDFED Skipping CircleCI call API at: ".concat(url, "."));
469
+ console.log(`🏭 Skipping CircleCI call API at: ${url}.`);
481
470
  }
482
471
 
483
472
  // @ts-expect-error
484
473
  return _Promise__default["default"].resolve();
485
474
  }
486
475
  if (debug) {
487
- console.log("\uD83C\uDFED Calling CircleCI API at: ".concat(url, "."));
476
+ console.log(`🏭 Calling CircleCI API at: ${url}.`);
488
477
  }
489
478
  try {
490
479
  const response = await fetch(url, {
@@ -495,7 +484,7 @@ function createCircleCiClient(_ref) {
495
484
  const processedCircleCiResponse = await processCircleCiResponse(response);
496
485
  return processedCircleCiResponse;
497
486
  } catch (error) {
498
- console.log("\u26A0\uFE0F Calling CircleCI API at: ".concat(url, " failed."));
487
+ console.log(`âš ī¸ Calling CircleCI API at: ${url} failed.`);
499
488
  throw error;
500
489
  }
501
490
  }
@@ -504,12 +493,12 @@ function createCircleCiClient(_ref) {
504
493
  let _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
505
494
  pageToken = _ref5.pageToken,
506
495
  _ref5$projectSlug = _ref5.projectSlug,
507
- projectSlug = _ref5$projectSlug === void 0 ? "gh/commercetools/".concat(projectName) : _ref5$projectSlug,
496
+ projectSlug = _ref5$projectSlug === void 0 ? `gh/commercetools/${projectName}` : _ref5$projectSlug,
508
497
  _ref5$branch = _ref5.branch,
509
498
  branch = _ref5$branch === void 0 ? 'main' : _ref5$branch;
510
499
  return {
511
500
  execute: options => execute({
512
- url: "/project/".concat(projectSlug, "/pipeline"),
501
+ url: `/project/${projectSlug}/pipeline`,
513
502
  headers: {
514
503
  'Content-Type': 'application/json',
515
504
  // The CLI throws if this is not present on environment
@@ -527,7 +516,7 @@ function createCircleCiClient(_ref) {
527
516
  let pipelineId = _ref6.pipelineId;
528
517
  return {
529
518
  execute: options => execute({
530
- url: "/pipeline/".concat(pipelineId, "/workflow"),
519
+ url: `/pipeline/${pipelineId}/workflow`,
531
520
  headers: {
532
521
  'Content-Type': 'application/json',
533
522
  // The CLI throws if this is not present on environment
@@ -541,7 +530,7 @@ function createCircleCiClient(_ref) {
541
530
  let workflowId = _ref7.workflowId;
542
531
  return {
543
532
  execute: options => execute({
544
- url: "/workflow/".concat(workflowId, "/job"),
533
+ url: `/workflow/${workflowId}/job`,
545
534
  headers: {
546
535
  'Content-Type': 'application/json',
547
536
  // The CLI throws if this is not present on environment
@@ -555,18 +544,15 @@ function createCircleCiClient(_ref) {
555
544
  let workflowId = _ref8.workflowId,
556
545
  approvalRequestId = _ref8.approvalRequestId;
557
546
  return {
558
- execute: options => {
559
- var _context4;
560
- return execute({
561
- url: _concatInstanceProperty__default["default"](_context4 = "/workflow/".concat(workflowId, "/approve/")).call(_context4, approvalRequestId, " "),
562
- headers: {
563
- 'Content-Type': 'application/json',
564
- // The CLI throws if this is not present on environment
565
- 'Circle-Token': process.env.CIRCLE_TOKEN
566
- },
567
- method: 'POST'
568
- }, options);
569
- }
547
+ execute: options => execute({
548
+ url: `/workflow/${workflowId}/approve/${approvalRequestId} `,
549
+ headers: {
550
+ 'Content-Type': 'application/json',
551
+ // The CLI throws if this is not present on environment
552
+ 'Circle-Token': process.env.CIRCLE_TOKEN
553
+ },
554
+ method: 'POST'
555
+ }, options)
570
556
  };
571
557
  }
572
558
  };
@@ -594,13 +580,13 @@ async function run() {
594
580
 
595
581
  // Command: Approve
596
582
  const usageApprove = 'Approves a job and by this triggers a deployment of a component. It requires a "CIRCLE_TOKEN" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).';
597
- cli.command('approve', usageApprove).usage("approve \n\n ".concat(usageApprove)).option('--approval-job <string>', 'The name of the approval job to approve a deployment with.').option('--deployment-job [string]', '(optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.').option('--deployment [string]', '(optional) The name of a deployment configured in the configuration file.').option('--build-revision [git-sha]', '(optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.').option('--branch [string]', '(optional) The git branch to deploy from. If not specified.', {
583
+ cli.command('approve', usageApprove).usage(`approve \n\n ${usageApprove}`).option('--approval-job <string>', 'The name of the approval job to approve a deployment with.').option('--deployment-job [string]', '(optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.').option('--deployment [string]', '(optional) The name of a deployment configured in the configuration file.').option('--build-revision [git-sha]', '(optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.').option('--branch [string]', '(optional) The git branch to deploy from. If not specified.', {
598
584
  default: 'main'
599
585
  }).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
600
586
  default: false
601
587
  }).action(async options => {
602
588
  if (options.dryRun) {
603
- console.log("\uD83D\uDE4A Do not worry. This is a dry run!");
589
+ console.log(`🙊 Do not worry. This is a dry run!`);
604
590
  }
605
591
  throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
606
592
  await approve(options, config, circleCiApis);