@capawesome/cli 4.6.0-dev.0108a83.1774286472 → 4.6.0-dev.8ae803e.1775035527
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/dist/commands/apps/builds/create.js +106 -131
- package/dist/commands/apps/bundles/create.js +4 -2
- package/dist/commands/apps/bundles/delete.js +2 -3
- package/dist/commands/apps/bundles/update.js +2 -3
- package/dist/commands/apps/certificates/delete.js +28 -5
- package/dist/commands/apps/certificates/get.js +28 -5
- package/dist/commands/apps/deployments/create.js +5 -77
- package/dist/commands/apps/devices/forcechannel.js +9 -7
- package/dist/commands/apps/devices/unforcechannel.js +9 -7
- package/dist/commands/apps/liveupdates/bundle.js +7 -2
- package/dist/commands/apps/liveupdates/create.js +285 -0
- package/dist/commands/apps/liveupdates/create.test.js +262 -0
- package/dist/commands/apps/liveupdates/generate-manifest.js +12 -1
- package/dist/commands/apps/liveupdates/generate-manifest.test.js +21 -1
- package/dist/commands/apps/liveupdates/register.js +10 -15
- package/dist/commands/apps/liveupdates/upload.js +18 -16
- package/dist/commands/manifests/generate.js +1 -1
- package/dist/index.js +1 -0
- package/dist/services/app-build-sources.js +9 -1
- package/dist/services/app-devices.js +8 -0
- package/dist/services/authorization-service.js +5 -1
- package/dist/services/jobs.js +13 -0
- package/dist/utils/custom-properties.js +22 -0
- package/dist/utils/file.js +8 -1
- package/dist/utils/job.js +77 -0
- package/package.json +1 -1
|
@@ -3,11 +3,11 @@ import appBuildSourcesService from '../../../services/app-build-sources.js';
|
|
|
3
3
|
import appBuildsService from '../../../services/app-builds.js';
|
|
4
4
|
import appCertificatesService from '../../../services/app-certificates.js';
|
|
5
5
|
import appEnvironmentsService from '../../../services/app-environments.js';
|
|
6
|
-
import {
|
|
6
|
+
import { parseKeyValuePairs } from '../../../utils/app-environments.js';
|
|
7
7
|
import { withAuth } from '../../../utils/auth.js';
|
|
8
8
|
import { isInteractive } from '../../../utils/environment.js';
|
|
9
|
+
import { waitForJobCompletion } from '../../../utils/job.js';
|
|
9
10
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
10
|
-
import { wait } from '../../../utils/wait.js';
|
|
11
11
|
import zip from '../../../utils/zip.js';
|
|
12
12
|
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
13
13
|
import consola from 'consola';
|
|
@@ -17,7 +17,7 @@ import { z } from 'zod';
|
|
|
17
17
|
const IOS_BUILD_TYPES = ['simulator', 'development', 'ad-hoc', 'app-store', 'enterprise'];
|
|
18
18
|
const ANDROID_BUILD_TYPES = ['debug', 'release'];
|
|
19
19
|
export default defineCommand({
|
|
20
|
-
description: 'Create a new app build.',
|
|
20
|
+
description: 'Create a new app build on Capawesome Cloud Runners.',
|
|
21
21
|
options: defineOptions(z.object({
|
|
22
22
|
aab: z
|
|
23
23
|
.union([z.boolean(), z.string()])
|
|
@@ -60,10 +60,19 @@ export default defineCommand({
|
|
|
60
60
|
})
|
|
61
61
|
.optional()
|
|
62
62
|
.describe('The build stack to use for the build process.'),
|
|
63
|
+
url: z.string().optional().describe('URL to a zip file to use as build source.'),
|
|
63
64
|
type: z
|
|
64
65
|
.string()
|
|
65
66
|
.optional()
|
|
66
67
|
.describe('The type of build. For iOS, supported values are `simulator`, `development`, `ad-hoc`, `app-store`, and `enterprise`. For Android, supported values are `debug` and `release`. For Web, no type is required.'),
|
|
68
|
+
variable: z
|
|
69
|
+
.array(z.string())
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('Ad hoc environment variable in key=value format. Can be specified multiple times.'),
|
|
72
|
+
variableFile: z
|
|
73
|
+
.string()
|
|
74
|
+
.optional()
|
|
75
|
+
.describe('Path to a file containing ad hoc environment variables in .env format.'),
|
|
67
76
|
zip: z
|
|
68
77
|
.union([z.boolean(), z.string()])
|
|
69
78
|
.optional()
|
|
@@ -71,7 +80,7 @@ export default defineCommand({
|
|
|
71
80
|
yes: z.boolean().optional().describe('Skip confirmation prompts.'),
|
|
72
81
|
}), { y: 'yes' }),
|
|
73
82
|
action: withAuth(async (options) => {
|
|
74
|
-
let { appId, platform, type, gitRef, environment, certificate, json, stack, path: sourcePath } = options;
|
|
83
|
+
let { appId, platform, type, gitRef, environment, certificate, json, stack, path: sourcePath, url } = options;
|
|
75
84
|
// Validate that detached flag cannot be used with artifact flags
|
|
76
85
|
if (options.detached && (options.apk || options.aab || options.ipa || options.zip)) {
|
|
77
86
|
consola.error('The --detached flag cannot be used with --apk, --aab, --ipa, or --zip flags.');
|
|
@@ -87,13 +96,26 @@ export default defineCommand({
|
|
|
87
96
|
consola.error('The --channel and --destination flags cannot be used together.');
|
|
88
97
|
process.exit(1);
|
|
89
98
|
}
|
|
90
|
-
// Validate that path and gitRef cannot be used together
|
|
99
|
+
// Validate that path, url, and gitRef cannot be used together
|
|
91
100
|
if (sourcePath && gitRef) {
|
|
92
101
|
consola.error('The --path and --git-ref flags cannot be used together.');
|
|
93
102
|
process.exit(1);
|
|
94
103
|
}
|
|
104
|
+
if (url && gitRef) {
|
|
105
|
+
consola.error('The --url and --git-ref flags cannot be used together.');
|
|
106
|
+
process.exit(1);
|
|
107
|
+
}
|
|
108
|
+
if (url && sourcePath) {
|
|
109
|
+
consola.error('The --url and --path flags cannot be used together.');
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
// Validate url if provided
|
|
113
|
+
if (url) {
|
|
114
|
+
consola.warn('The --url option is experimental and may change in the future.');
|
|
115
|
+
}
|
|
95
116
|
// Validate path if provided
|
|
96
117
|
if (sourcePath) {
|
|
118
|
+
consola.warn('The --path option is experimental and may change in the future.');
|
|
97
119
|
const resolvedPath = path.resolve(sourcePath);
|
|
98
120
|
const stat = await fs.stat(resolvedPath).catch(() => null);
|
|
99
121
|
if (!stat || !stat.isDirectory()) {
|
|
@@ -136,10 +158,10 @@ export default defineCommand({
|
|
|
136
158
|
process.exit(1);
|
|
137
159
|
}
|
|
138
160
|
}
|
|
139
|
-
// Prompt for git ref if not provided and no path specified
|
|
140
|
-
if (!sourcePath && !gitRef) {
|
|
161
|
+
// Prompt for git ref if not provided and no path or url specified
|
|
162
|
+
if (!sourcePath && !url && !gitRef) {
|
|
141
163
|
if (!isInteractive()) {
|
|
142
|
-
consola.error('You must provide a git ref or
|
|
164
|
+
consola.error('You must provide a git ref, path, or url when running in non-interactive environment.');
|
|
143
165
|
process.exit(1);
|
|
144
166
|
}
|
|
145
167
|
gitRef = await prompt('Enter the Git reference (branch, tag, or commit SHA):', {
|
|
@@ -220,14 +242,33 @@ export default defineCommand({
|
|
|
220
242
|
}
|
|
221
243
|
}
|
|
222
244
|
}
|
|
223
|
-
//
|
|
245
|
+
// Parse ad hoc environment variables from inline and file
|
|
246
|
+
const variablesMap = new Map();
|
|
247
|
+
if (options.variableFile) {
|
|
248
|
+
const fileContent = await fs.readFile(options.variableFile, 'utf-8');
|
|
249
|
+
const fileVariables = parseKeyValuePairs(fileContent);
|
|
250
|
+
fileVariables.forEach((v) => variablesMap.set(v.key, v.value));
|
|
251
|
+
}
|
|
252
|
+
if (options.variable) {
|
|
253
|
+
const inlineVariables = parseKeyValuePairs(options.variable.join('\n'));
|
|
254
|
+
inlineVariables.forEach((v) => variablesMap.set(v.key, v.value));
|
|
255
|
+
}
|
|
256
|
+
const adHocEnvironmentVariables = variablesMap.size > 0 ? Object.fromEntries(variablesMap) : undefined;
|
|
257
|
+
// Create build source from URL if provided
|
|
224
258
|
let appBuildSourceId;
|
|
259
|
+
if (url) {
|
|
260
|
+
consola.start('Creating build source from URL...');
|
|
261
|
+
const appBuildSource = await appBuildSourcesService.createFromUrl({ appId, fileUrl: url });
|
|
262
|
+
appBuildSourceId = appBuildSource.id;
|
|
263
|
+
consola.success('Build source created successfully.');
|
|
264
|
+
}
|
|
265
|
+
// Upload source files if path is provided
|
|
225
266
|
if (sourcePath) {
|
|
226
267
|
const resolvedPath = path.resolve(sourcePath);
|
|
227
268
|
consola.start('Zipping source files...');
|
|
228
269
|
const buffer = await zip.zipFolderWithGitignore(resolvedPath);
|
|
229
270
|
consola.start('Uploading source files...');
|
|
230
|
-
const appBuildSource = await appBuildSourcesService.
|
|
271
|
+
const appBuildSource = await appBuildSourcesService.createFromFile({
|
|
231
272
|
appId,
|
|
232
273
|
fileSizeInBytes: buffer.byteLength,
|
|
233
274
|
buffer,
|
|
@@ -241,6 +282,7 @@ export default defineCommand({
|
|
|
241
282
|
// Create the app build
|
|
242
283
|
consola.start('Creating build...');
|
|
243
284
|
const response = await appBuildsService.create({
|
|
285
|
+
adHocEnvironmentVariables,
|
|
244
286
|
appBuildSourceId,
|
|
245
287
|
appCertificateName: certificate,
|
|
246
288
|
appEnvironmentName: environment,
|
|
@@ -257,127 +299,60 @@ export default defineCommand({
|
|
|
257
299
|
// Wait for build job to complete by default, unless --detached flag is set
|
|
258
300
|
const shouldWait = !options.detached;
|
|
259
301
|
if (shouldWait) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
appId,
|
|
315
|
-
buildId: response.id,
|
|
316
|
-
buildArtifacts: build.appBuildArtifacts,
|
|
317
|
-
artifactType: 'apk',
|
|
318
|
-
filePath: typeof options.apk === 'string' ? options.apk : undefined,
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
if (options.aab && platform === 'android') {
|
|
322
|
-
await handleArtifactDownload({
|
|
323
|
-
appId,
|
|
324
|
-
buildId: response.id,
|
|
325
|
-
buildArtifacts: build.appBuildArtifacts,
|
|
326
|
-
artifactType: 'aab',
|
|
327
|
-
filePath: typeof options.aab === 'string' ? options.aab : undefined,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
if (options.ipa && platform === 'ios') {
|
|
331
|
-
await handleArtifactDownload({
|
|
332
|
-
appId,
|
|
333
|
-
buildId: response.id,
|
|
334
|
-
buildArtifacts: build.appBuildArtifacts,
|
|
335
|
-
artifactType: 'ipa',
|
|
336
|
-
filePath: typeof options.ipa === 'string' ? options.ipa : undefined,
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
if (options.zip && platform === 'web') {
|
|
340
|
-
await handleArtifactDownload({
|
|
341
|
-
appId,
|
|
342
|
-
buildId: response.id,
|
|
343
|
-
buildArtifacts: build.appBuildArtifacts,
|
|
344
|
-
artifactType: 'zip',
|
|
345
|
-
filePath: typeof options.zip === 'string' ? options.zip : undefined,
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
// Output JSON if json flag is set
|
|
349
|
-
if (json) {
|
|
350
|
-
console.log(JSON.stringify({
|
|
351
|
-
id: response.id,
|
|
352
|
-
numberAsString: response.numberAsString,
|
|
353
|
-
}, null, 2));
|
|
354
|
-
}
|
|
355
|
-
break;
|
|
356
|
-
}
|
|
357
|
-
else if (jobStatus === 'failed') {
|
|
358
|
-
consola.error('Build failed.');
|
|
359
|
-
process.exit(1);
|
|
360
|
-
}
|
|
361
|
-
else if (jobStatus === 'canceled') {
|
|
362
|
-
consola.warn('Build was canceled.');
|
|
363
|
-
process.exit(1);
|
|
364
|
-
}
|
|
365
|
-
else if (jobStatus === 'rejected') {
|
|
366
|
-
consola.error('Build was rejected.');
|
|
367
|
-
process.exit(1);
|
|
368
|
-
}
|
|
369
|
-
else if (jobStatus === 'timed_out') {
|
|
370
|
-
consola.error('Build timed out.');
|
|
371
|
-
process.exit(1);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
// Wait before next poll (3 seconds)
|
|
375
|
-
await wait(3000);
|
|
376
|
-
}
|
|
377
|
-
catch (error) {
|
|
378
|
-
consola.error('Error polling build status:', error);
|
|
379
|
-
process.exit(1);
|
|
380
|
-
}
|
|
302
|
+
await waitForJobCompletion({ jobId: response.jobId });
|
|
303
|
+
const appBuild = await appBuildsService.findOne({
|
|
304
|
+
appId,
|
|
305
|
+
appBuildId: response.id,
|
|
306
|
+
relations: 'appBuildArtifacts',
|
|
307
|
+
});
|
|
308
|
+
consola.info(`Build ID: ${response.id}`);
|
|
309
|
+
consola.info(`Build Number: ${response.numberAsString}`);
|
|
310
|
+
consola.info(`Build URL: ${DEFAULT_CONSOLE_BASE_URL}/apps/${appId}/builds/${response.id}`);
|
|
311
|
+
consola.success('Build completed successfully.');
|
|
312
|
+
console.log();
|
|
313
|
+
// Download artifacts if flags are set
|
|
314
|
+
if (options.apk && platform === 'android') {
|
|
315
|
+
await handleArtifactDownload({
|
|
316
|
+
appId,
|
|
317
|
+
buildId: response.id,
|
|
318
|
+
buildArtifacts: appBuild.appBuildArtifacts,
|
|
319
|
+
artifactType: 'apk',
|
|
320
|
+
filePath: typeof options.apk === 'string' ? options.apk : undefined,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (options.aab && platform === 'android') {
|
|
324
|
+
await handleArtifactDownload({
|
|
325
|
+
appId,
|
|
326
|
+
buildId: response.id,
|
|
327
|
+
buildArtifacts: appBuild.appBuildArtifacts,
|
|
328
|
+
artifactType: 'aab',
|
|
329
|
+
filePath: typeof options.aab === 'string' ? options.aab : undefined,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
if (options.ipa && platform === 'ios') {
|
|
333
|
+
await handleArtifactDownload({
|
|
334
|
+
appId,
|
|
335
|
+
buildId: response.id,
|
|
336
|
+
buildArtifacts: appBuild.appBuildArtifacts,
|
|
337
|
+
artifactType: 'ipa',
|
|
338
|
+
filePath: typeof options.ipa === 'string' ? options.ipa : undefined,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (options.zip && platform === 'web') {
|
|
342
|
+
await handleArtifactDownload({
|
|
343
|
+
appId,
|
|
344
|
+
buildId: response.id,
|
|
345
|
+
buildArtifacts: appBuild.appBuildArtifacts,
|
|
346
|
+
artifactType: 'zip',
|
|
347
|
+
filePath: typeof options.zip === 'string' ? options.zip : undefined,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
// Output JSON if json flag is set
|
|
351
|
+
if (json) {
|
|
352
|
+
console.log(JSON.stringify({
|
|
353
|
+
id: response.id,
|
|
354
|
+
numberAsString: response.numberAsString,
|
|
355
|
+
}, null, 2));
|
|
381
356
|
}
|
|
382
357
|
}
|
|
383
358
|
else {
|
|
@@ -2,7 +2,7 @@ import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export default defineCommand({
|
|
5
|
-
description: 'Create a new app bundle.',
|
|
5
|
+
description: 'Create a new app bundle. Deprecated, use the `apps:liveupdates` commands instead.',
|
|
6
6
|
options: defineOptions(z.object({
|
|
7
7
|
androidMax: z.coerce
|
|
8
8
|
.string()
|
|
@@ -38,6 +38,7 @@ export default defineCommand({
|
|
|
38
38
|
commitSha: z.string().optional().describe('The commit sha related to the bundle.'),
|
|
39
39
|
customProperty: z
|
|
40
40
|
.array(z.string().min(1).max(100))
|
|
41
|
+
.max(10)
|
|
41
42
|
.optional()
|
|
42
43
|
.describe('A custom property to assign to the bundle. Must be in the format `key=value`. Can be specified multiple times.'),
|
|
43
44
|
expiresInDays: z.coerce
|
|
@@ -83,7 +84,8 @@ export default defineCommand({
|
|
|
83
84
|
action: async (options, args) => {
|
|
84
85
|
consola.warn('The `apps:bundles:create` command has been deprecated.');
|
|
85
86
|
consola.info('Please use one of the following commands instead:');
|
|
86
|
-
consola.info(' - `apps:liveupdates:
|
|
87
|
+
consola.info(' - `apps:liveupdates:create` to build and deploy using Capawesome Cloud Runners');
|
|
88
|
+
consola.info(' - `apps:liveupdates:upload` to upload a locally built bundle to Capawesome Cloud');
|
|
87
89
|
consola.info(' - `apps:liveupdates:register` to register a self-hosted bundle URL');
|
|
88
90
|
process.exit(1);
|
|
89
91
|
},
|
|
@@ -2,14 +2,13 @@ import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export default defineCommand({
|
|
5
|
-
description: 'Delete an app bundle.',
|
|
5
|
+
description: 'Delete an app bundle. Deprecated.',
|
|
6
6
|
options: defineOptions(z.object({
|
|
7
7
|
appId: z.string().optional().describe('ID of the app.'),
|
|
8
8
|
bundleId: z.string().optional().describe('ID of the bundle.'),
|
|
9
9
|
})),
|
|
10
10
|
action: async (options, args) => {
|
|
11
|
-
consola.warn('The `apps:bundles:delete` command has been deprecated
|
|
12
|
-
consola.info('Please refer to the official documentation for alternative approaches.');
|
|
11
|
+
consola.warn('The `apps:bundles:delete` command has been deprecated. Please use the `apps:liveupdates` commands instead.');
|
|
13
12
|
process.exit(1);
|
|
14
13
|
},
|
|
15
14
|
});
|
|
@@ -2,7 +2,7 @@ import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
|
2
2
|
import consola from 'consola';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
export default defineCommand({
|
|
5
|
-
description: 'Update an app bundle.',
|
|
5
|
+
description: 'Update an app bundle. Deprecated.',
|
|
6
6
|
options: defineOptions(z.object({
|
|
7
7
|
androidMax: z
|
|
8
8
|
.string()
|
|
@@ -40,8 +40,7 @@ export default defineCommand({
|
|
|
40
40
|
.describe('The exact iOS bundle version (`CFBundleVersion`) that the bundle should not support.'),
|
|
41
41
|
})),
|
|
42
42
|
action: async (options, args) => {
|
|
43
|
-
consola.warn('The `apps:bundles:update` command has been deprecated
|
|
44
|
-
consola.info('Please refer to the official documentation for alternative approaches.');
|
|
43
|
+
consola.warn('The `apps:bundles:update` command has been deprecated. Please use the `apps:liveupdates` commands instead.');
|
|
45
44
|
process.exit(1);
|
|
46
45
|
},
|
|
47
46
|
});
|
|
@@ -15,10 +15,14 @@ export default defineCommand({
|
|
|
15
15
|
.enum(['android', 'ios', 'web'])
|
|
16
16
|
.optional()
|
|
17
17
|
.describe('Platform of the certificate (android, ios, web).'),
|
|
18
|
+
type: z
|
|
19
|
+
.enum(['development', 'production'])
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Type of the certificate (development, production).'),
|
|
18
22
|
yes: z.boolean().optional().describe('Skip confirmation prompt.'),
|
|
19
23
|
}), { y: 'yes' }),
|
|
20
24
|
action: withAuth(async (options, args) => {
|
|
21
|
-
let { appId, certificateId, name, platform } = options;
|
|
25
|
+
let { appId, certificateId, name, platform, type } = options;
|
|
22
26
|
if (!appId) {
|
|
23
27
|
if (!isInteractive()) {
|
|
24
28
|
consola.error('You must provide an app ID when running in non-interactive environment.');
|
|
@@ -29,10 +33,19 @@ export default defineCommand({
|
|
|
29
33
|
}
|
|
30
34
|
if (!certificateId) {
|
|
31
35
|
if (name && platform) {
|
|
32
|
-
const certificates = await appCertificatesService.findAll({ appId, name, platform });
|
|
36
|
+
const certificates = await appCertificatesService.findAll({ appId, name, platform, type });
|
|
33
37
|
const firstCertificate = certificates[0];
|
|
34
38
|
if (!firstCertificate) {
|
|
35
|
-
|
|
39
|
+
if (type) {
|
|
40
|
+
consola.error(`No certificate found with name '${name}', platform '${platform}', and type '${type}'.`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
consola.error(`No certificate found with name '${name}' and platform '${platform}'.`);
|
|
44
|
+
}
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
if (certificates.length > 1 && !type) {
|
|
48
|
+
consola.error(`Multiple certificates found with name '${name}' and platform '${platform}'. Please specify --type or --certificate-id to disambiguate.`);
|
|
36
49
|
process.exit(1);
|
|
37
50
|
}
|
|
38
51
|
certificateId = firstCertificate.id;
|
|
@@ -49,9 +62,19 @@ export default defineCommand({
|
|
|
49
62
|
],
|
|
50
63
|
});
|
|
51
64
|
}
|
|
52
|
-
|
|
65
|
+
if (!type) {
|
|
66
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
67
|
+
type = await prompt('Select the type:', {
|
|
68
|
+
type: 'select',
|
|
69
|
+
options: [
|
|
70
|
+
{ label: 'Development', value: 'development' },
|
|
71
|
+
{ label: 'Production', value: 'production' },
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const certificates = await appCertificatesService.findAll({ appId, name, platform, type });
|
|
53
76
|
if (!certificates.length) {
|
|
54
|
-
consola.error(
|
|
77
|
+
consola.error(`No certificates found with platform '${platform}' and type '${type}'. Create one first.`);
|
|
55
78
|
process.exit(1);
|
|
56
79
|
}
|
|
57
80
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
@@ -16,9 +16,13 @@ export default defineCommand({
|
|
|
16
16
|
.enum(['android', 'ios', 'web'])
|
|
17
17
|
.optional()
|
|
18
18
|
.describe('Platform of the certificate (android, ios, web).'),
|
|
19
|
+
type: z
|
|
20
|
+
.enum(['development', 'production'])
|
|
21
|
+
.optional()
|
|
22
|
+
.describe('Type of the certificate (development, production).'),
|
|
19
23
|
})),
|
|
20
24
|
action: withAuth(async (options, args) => {
|
|
21
|
-
let { appId, certificateId, name, platform } = options;
|
|
25
|
+
let { appId, certificateId, name, platform, type } = options;
|
|
22
26
|
if (!appId) {
|
|
23
27
|
if (!isInteractive()) {
|
|
24
28
|
consola.error('You must provide an app ID when running in non-interactive environment.');
|
|
@@ -29,10 +33,19 @@ export default defineCommand({
|
|
|
29
33
|
}
|
|
30
34
|
if (!certificateId) {
|
|
31
35
|
if (name && platform) {
|
|
32
|
-
const certificates = await appCertificatesService.findAll({ appId, name, platform });
|
|
36
|
+
const certificates = await appCertificatesService.findAll({ appId, name, platform, type });
|
|
33
37
|
const firstCertificate = certificates[0];
|
|
34
38
|
if (!firstCertificate) {
|
|
35
|
-
|
|
39
|
+
if (type) {
|
|
40
|
+
consola.error(`No certificate found with name '${name}', platform '${platform}', and type '${type}'.`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
consola.error(`No certificate found with name '${name}' and platform '${platform}'.`);
|
|
44
|
+
}
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
if (certificates.length > 1 && !type) {
|
|
48
|
+
consola.error(`Multiple certificates found with name '${name}' and platform '${platform}'. Please specify --type or --certificate-id to disambiguate.`);
|
|
36
49
|
process.exit(1);
|
|
37
50
|
}
|
|
38
51
|
certificateId = firstCertificate.id;
|
|
@@ -49,9 +62,19 @@ export default defineCommand({
|
|
|
49
62
|
],
|
|
50
63
|
});
|
|
51
64
|
}
|
|
52
|
-
|
|
65
|
+
if (!type) {
|
|
66
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
67
|
+
type = await prompt('Select the type:', {
|
|
68
|
+
type: 'select',
|
|
69
|
+
options: [
|
|
70
|
+
{ label: 'Development', value: 'development' },
|
|
71
|
+
{ label: 'Production', value: 'production' },
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const certificates = await appCertificatesService.findAll({ appId, name, platform, type });
|
|
53
76
|
if (!certificates.length) {
|
|
54
|
-
consola.error(
|
|
77
|
+
consola.error(`No certificates found with platform '${platform}' and type '${type}'. Create one first.`);
|
|
55
78
|
process.exit(1);
|
|
56
79
|
}
|
|
57
80
|
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
@@ -2,16 +2,15 @@ import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
|
2
2
|
import appBuildsService from '../../../services/app-builds.js';
|
|
3
3
|
import appDeploymentsService from '../../../services/app-deployments.js';
|
|
4
4
|
import appDestinationsService from '../../../services/app-destinations.js';
|
|
5
|
-
import { unescapeAnsi } from '../../../utils/ansi.js';
|
|
6
5
|
import { withAuth } from '../../../utils/auth.js';
|
|
7
6
|
import { isInteractive } from '../../../utils/environment.js';
|
|
7
|
+
import { waitForJobCompletion } from '../../../utils/job.js';
|
|
8
8
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
9
|
-
import { wait } from '../../../utils/wait.js';
|
|
10
9
|
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
11
10
|
import consola from 'consola';
|
|
12
11
|
import { z } from 'zod';
|
|
13
12
|
export default defineCommand({
|
|
14
|
-
description: 'Create a new app deployment.',
|
|
13
|
+
description: 'Create a new app deployment on Capawesome Cloud.',
|
|
15
14
|
options: defineOptions(z.object({
|
|
16
15
|
appId: z
|
|
17
16
|
.uuid({
|
|
@@ -159,80 +158,9 @@ export default defineCommand({
|
|
|
159
158
|
// Wait for deployment job to complete by default, unless --detached flag is set
|
|
160
159
|
const shouldWait = !options.detached && build.platform !== 'web';
|
|
161
160
|
if (shouldWait) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
while (true) {
|
|
166
|
-
try {
|
|
167
|
-
const deployment = await appDeploymentsService.findOne({
|
|
168
|
-
appId,
|
|
169
|
-
appDeploymentId: response.id,
|
|
170
|
-
relations: 'job,job.jobLogs',
|
|
171
|
-
});
|
|
172
|
-
if (!deployment.job) {
|
|
173
|
-
await wait(3000);
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
const jobStatus = deployment.job.status;
|
|
177
|
-
// Show spinner while queued or pending
|
|
178
|
-
if (jobStatus === 'queued' || jobStatus === 'pending') {
|
|
179
|
-
if (isWaitingForStart) {
|
|
180
|
-
consola.start(`Waiting for deployment to start (status: ${jobStatus})...`);
|
|
181
|
-
}
|
|
182
|
-
await wait(3000);
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
// Stop spinner when job moves to in_progress
|
|
186
|
-
if (isWaitingForStart && jobStatus === 'in_progress') {
|
|
187
|
-
isWaitingForStart = false;
|
|
188
|
-
consola.success('Deployment started...');
|
|
189
|
-
}
|
|
190
|
-
// Print new logs
|
|
191
|
-
if (deployment.job.jobLogs && deployment.job.jobLogs.length > 0) {
|
|
192
|
-
const newLogs = deployment.job.jobLogs
|
|
193
|
-
.filter((log) => log.number > lastPrintedLogNumber)
|
|
194
|
-
.sort((a, b) => a.number - b.number);
|
|
195
|
-
for (const log of newLogs) {
|
|
196
|
-
console.log(unescapeAnsi(log.payload));
|
|
197
|
-
lastPrintedLogNumber = log.number;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
// Handle terminal states
|
|
201
|
-
if (jobStatus === 'succeeded' ||
|
|
202
|
-
jobStatus === 'failed' ||
|
|
203
|
-
jobStatus === 'canceled' ||
|
|
204
|
-
jobStatus === 'rejected' ||
|
|
205
|
-
jobStatus === 'timed_out') {
|
|
206
|
-
console.log(); // New line for better readability
|
|
207
|
-
if (jobStatus === 'succeeded') {
|
|
208
|
-
consola.success('Deployment completed successfully.');
|
|
209
|
-
process.exit(0);
|
|
210
|
-
}
|
|
211
|
-
else if (jobStatus === 'failed') {
|
|
212
|
-
consola.error('Deployment failed.');
|
|
213
|
-
process.exit(1);
|
|
214
|
-
}
|
|
215
|
-
else if (jobStatus === 'canceled') {
|
|
216
|
-
consola.warn('Deployment was canceled.');
|
|
217
|
-
process.exit(1);
|
|
218
|
-
}
|
|
219
|
-
else if (jobStatus === 'rejected') {
|
|
220
|
-
consola.error('Deployment was rejected.');
|
|
221
|
-
process.exit(1);
|
|
222
|
-
}
|
|
223
|
-
else if (jobStatus === 'timed_out') {
|
|
224
|
-
consola.error('Deployment timed out.');
|
|
225
|
-
process.exit(1);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
// Wait before next poll (3 seconds)
|
|
229
|
-
await wait(3000);
|
|
230
|
-
}
|
|
231
|
-
catch (error) {
|
|
232
|
-
consola.error('Error polling deployment status:', error);
|
|
233
|
-
process.exit(1);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
161
|
+
await waitForJobCompletion({ jobId: response.jobId });
|
|
162
|
+
consola.success('Deployment completed successfully.');
|
|
163
|
+
process.exit(0);
|
|
236
164
|
}
|
|
237
165
|
}),
|
|
238
166
|
});
|