@capawesome/cli 4.6.0-dev.0108a83.1774286472 → 4.6.0-dev.12df3ca.1775037612

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.
@@ -0,0 +1,77 @@
1
+ import jobsService from '../services/jobs.js';
2
+ import { unescapeAnsi } from '../utils/ansi.js';
3
+ import { wait } from '../utils/wait.js';
4
+ import consola from 'consola';
5
+ const getLabel = (job) => {
6
+ if (job.appBuildId) {
7
+ return 'build';
8
+ }
9
+ if (job.appDeploymentId) {
10
+ return 'deployment';
11
+ }
12
+ return 'job';
13
+ };
14
+ const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
15
+ export const waitForJobCompletion = async (options) => {
16
+ const { jobId } = options;
17
+ let lastPrintedLogNumber = 0;
18
+ let isWaitingForStart = true;
19
+ while (true) {
20
+ try {
21
+ const job = await jobsService.findOne({ jobId, relations: 'jobLogs' });
22
+ const label = getLabel(job);
23
+ const jobStatus = job.status;
24
+ if (jobStatus === 'queued' || jobStatus === 'pending') {
25
+ if (isWaitingForStart) {
26
+ consola.start(`Waiting for ${label} to start (status: ${jobStatus})...`);
27
+ }
28
+ await wait(3000);
29
+ continue;
30
+ }
31
+ if (isWaitingForStart && jobStatus === 'in_progress') {
32
+ isWaitingForStart = false;
33
+ consola.success(`${capitalize(label)} started...`);
34
+ }
35
+ if (job.jobLogs && job.jobLogs.length > 0) {
36
+ const newLogs = job.jobLogs
37
+ .filter((log) => log.number > lastPrintedLogNumber)
38
+ .sort((a, b) => a.number - b.number);
39
+ for (const log of newLogs) {
40
+ console.log(unescapeAnsi(log.payload));
41
+ lastPrintedLogNumber = log.number;
42
+ }
43
+ }
44
+ if (jobStatus === 'succeeded' ||
45
+ jobStatus === 'failed' ||
46
+ jobStatus === 'canceled' ||
47
+ jobStatus === 'rejected' ||
48
+ jobStatus === 'timed_out') {
49
+ console.log();
50
+ if (jobStatus === 'succeeded') {
51
+ return job;
52
+ }
53
+ else if (jobStatus === 'failed') {
54
+ consola.error(`${capitalize(label)} failed.`);
55
+ process.exit(1);
56
+ }
57
+ else if (jobStatus === 'canceled') {
58
+ consola.warn(`${capitalize(label)} was canceled.`);
59
+ process.exit(1);
60
+ }
61
+ else if (jobStatus === 'rejected') {
62
+ consola.error(`${capitalize(label)} was rejected.`);
63
+ process.exit(1);
64
+ }
65
+ else if (jobStatus === 'timed_out') {
66
+ consola.error(`${capitalize(label)} timed out.`);
67
+ process.exit(1);
68
+ }
69
+ }
70
+ await wait(3000);
71
+ }
72
+ catch (error) {
73
+ consola.error('Error polling job status:', error);
74
+ process.exit(1);
75
+ }
76
+ }
77
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/cli",
3
- "version": "4.6.0-dev.0108a83.1774286472",
3
+ "version": "4.6.0-dev.12df3ca.1775037612",
4
4
  "description": "The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.",
5
5
  "type": "module",
6
6
  "scripts": {