@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
|
@@ -10,11 +10,11 @@ export default defineCommand({
|
|
|
10
10
|
description: 'Force a device to use a specific channel.',
|
|
11
11
|
options: defineOptions(z.object({
|
|
12
12
|
appId: z.string().uuid({ message: 'App ID must be a UUID.' }).optional().describe('ID of the app.'),
|
|
13
|
-
deviceId: z.string().optional().describe('ID of the device.'),
|
|
13
|
+
deviceId: z.array(z.string()).optional().describe('ID of the device. Can be specified multiple times.'),
|
|
14
14
|
channel: z.string().optional().describe('Name of the channel to force.'),
|
|
15
15
|
})),
|
|
16
16
|
action: withAuth(async (options, args) => {
|
|
17
|
-
let { appId, deviceId, channel } = options;
|
|
17
|
+
let { appId, deviceId: deviceIds, channel } = options;
|
|
18
18
|
if (!appId) {
|
|
19
19
|
if (!isInteractive()) {
|
|
20
20
|
consola.error('You must provide an app ID when running in non-interactive environment.');
|
|
@@ -23,14 +23,15 @@ export default defineCommand({
|
|
|
23
23
|
const organizationId = await promptOrganizationSelection();
|
|
24
24
|
appId = await promptAppSelection(organizationId);
|
|
25
25
|
}
|
|
26
|
-
if (!
|
|
26
|
+
if (!deviceIds || deviceIds.length === 0) {
|
|
27
27
|
if (!isInteractive()) {
|
|
28
28
|
consola.error('You must provide the device ID when running in non-interactive environment.');
|
|
29
29
|
process.exit(1);
|
|
30
30
|
}
|
|
31
|
-
deviceId = await prompt('Enter the device ID:', {
|
|
31
|
+
const deviceId = await prompt('Enter the device ID:', {
|
|
32
32
|
type: 'text',
|
|
33
33
|
});
|
|
34
|
+
deviceIds = [deviceId];
|
|
34
35
|
}
|
|
35
36
|
if (!channel) {
|
|
36
37
|
if (!isInteractive()) {
|
|
@@ -56,11 +57,12 @@ export default defineCommand({
|
|
|
56
57
|
consola.error('Channel ID not found.');
|
|
57
58
|
process.exit(1);
|
|
58
59
|
}
|
|
59
|
-
await appDevicesService.
|
|
60
|
+
await appDevicesService.updateMany({
|
|
60
61
|
appId,
|
|
61
|
-
|
|
62
|
+
deviceIds,
|
|
62
63
|
forcedAppChannelId: channelId,
|
|
63
64
|
});
|
|
64
|
-
|
|
65
|
+
const deviceCount = deviceIds.length;
|
|
66
|
+
consola.success(`${deviceCount === 1 ? 'Device' : `${deviceCount} devices`} forced to channel successfully.`);
|
|
65
67
|
}),
|
|
66
68
|
});
|
|
@@ -9,10 +9,10 @@ export default defineCommand({
|
|
|
9
9
|
description: 'Remove the forced channel from a device.',
|
|
10
10
|
options: defineOptions(z.object({
|
|
11
11
|
appId: z.string().uuid({ message: 'App ID must be a UUID.' }).optional().describe('ID of the app.'),
|
|
12
|
-
deviceId: z.string().optional().describe('ID of the device.'),
|
|
12
|
+
deviceId: z.array(z.string()).optional().describe('ID of the device. Can be specified multiple times.'),
|
|
13
13
|
})),
|
|
14
14
|
action: withAuth(async (options, args) => {
|
|
15
|
-
let { appId, deviceId } = options;
|
|
15
|
+
let { appId, deviceId: deviceIds } = options;
|
|
16
16
|
if (!appId) {
|
|
17
17
|
if (!isInteractive()) {
|
|
18
18
|
consola.error('You must provide an app ID when running in non-interactive environment.');
|
|
@@ -21,20 +21,22 @@ export default defineCommand({
|
|
|
21
21
|
const organizationId = await promptOrganizationSelection();
|
|
22
22
|
appId = await promptAppSelection(organizationId);
|
|
23
23
|
}
|
|
24
|
-
if (!
|
|
24
|
+
if (!deviceIds || deviceIds.length === 0) {
|
|
25
25
|
if (!isInteractive()) {
|
|
26
26
|
consola.error('You must provide the device ID when running in non-interactive environment.');
|
|
27
27
|
process.exit(1);
|
|
28
28
|
}
|
|
29
|
-
deviceId = await prompt('Enter the device ID:', {
|
|
29
|
+
const deviceId = await prompt('Enter the device ID:', {
|
|
30
30
|
type: 'text',
|
|
31
31
|
});
|
|
32
|
+
deviceIds = [deviceId];
|
|
32
33
|
}
|
|
33
|
-
await appDevicesService.
|
|
34
|
+
await appDevicesService.updateMany({
|
|
34
35
|
appId,
|
|
35
|
-
|
|
36
|
+
deviceIds,
|
|
36
37
|
forcedAppChannelId: null,
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
+
const deviceCount = deviceIds.length;
|
|
40
|
+
consola.success(`Forced channel removed from ${deviceCount === 1 ? 'device' : `${deviceCount} devices`} successfully.`);
|
|
39
41
|
}),
|
|
40
42
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isInteractive } from '../../../utils/environment.js';
|
|
2
|
-
import { directoryContainsSourceMaps, fileExistsAtPath, isDirectory } from '../../../utils/file.js';
|
|
2
|
+
import { directoryContainsSourceMaps, directoryContainsSymlinks, fileExistsAtPath, isDirectory } from '../../../utils/file.js';
|
|
3
3
|
import { generateManifestJson } from '../../../utils/manifest.js';
|
|
4
4
|
import { prompt } from '../../../utils/prompt.js';
|
|
5
5
|
import zip from '../../../utils/zip.js';
|
|
@@ -9,7 +9,7 @@ import fs from 'fs';
|
|
|
9
9
|
import pathModule from 'path';
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
export default defineCommand({
|
|
12
|
-
description: 'Generate manifest file and compress web assets into a bundle.zip file.',
|
|
12
|
+
description: 'Generate manifest file and compress locally built web assets into a bundle.zip file.',
|
|
13
13
|
options: defineOptions(z.object({
|
|
14
14
|
inputPath: z.string().optional().describe('Path to the web assets directory.'),
|
|
15
15
|
outputPath: z
|
|
@@ -62,6 +62,11 @@ export default defineCommand({
|
|
|
62
62
|
consola.error(`Directory must contain an index.html file: ${inputPath}`);
|
|
63
63
|
process.exit(1);
|
|
64
64
|
}
|
|
65
|
+
// Check for symlinks
|
|
66
|
+
const containsSymlinks = await directoryContainsSymlinks(inputPath);
|
|
67
|
+
if (containsSymlinks) {
|
|
68
|
+
consola.warn('Symbolic links were detected in the specified path. Symbolic links are skipped during bundling.');
|
|
69
|
+
}
|
|
65
70
|
// Check for source maps
|
|
66
71
|
const containsSourceMaps = await directoryContainsSourceMaps(inputPath);
|
|
67
72
|
if (containsSourceMaps) {
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
|
+
import appBuildSourcesService from '../../../services/app-build-sources.js';
|
|
3
|
+
import appBuildsService from '../../../services/app-builds.js';
|
|
4
|
+
import appCertificatesService from '../../../services/app-certificates.js';
|
|
5
|
+
import appDeploymentsService from '../../../services/app-deployments.js';
|
|
6
|
+
import appEnvironmentsService from '../../../services/app-environments.js';
|
|
7
|
+
import { parseKeyValuePairs } from '../../../utils/app-environments.js';
|
|
8
|
+
import { withAuth } from '../../../utils/auth.js';
|
|
9
|
+
import { parseCustomProperties } from '../../../utils/custom-properties.js';
|
|
10
|
+
import { isInteractive } from '../../../utils/environment.js';
|
|
11
|
+
import { waitForJobCompletion } from '../../../utils/job.js';
|
|
12
|
+
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
13
|
+
import zip from '../../../utils/zip.js';
|
|
14
|
+
import { defineCommand, defineOptions } from '@robingenz/zli';
|
|
15
|
+
import consola from 'consola';
|
|
16
|
+
import fs from 'fs/promises';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
export default defineCommand({
|
|
20
|
+
description: 'Create a new live update by building and deploying web assets using Capawesome Cloud Runners.',
|
|
21
|
+
options: defineOptions(z.object({
|
|
22
|
+
androidEq: z.string().optional().describe('The exact Android versionCode for the live update.'),
|
|
23
|
+
androidMax: z.string().optional().describe('The maximum Android versionCode for the live update.'),
|
|
24
|
+
androidMin: z.string().optional().describe('The minimum Android versionCode for the live update.'),
|
|
25
|
+
appId: z
|
|
26
|
+
.uuid({
|
|
27
|
+
message: 'App ID must be a UUID.',
|
|
28
|
+
})
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('App ID to create the live update for.'),
|
|
31
|
+
certificate: z.string().optional().describe('The name of the certificate to use for the build.'),
|
|
32
|
+
channel: z.string().optional().describe('The name of the channel to deploy to.'),
|
|
33
|
+
customProperty: z
|
|
34
|
+
.array(z.string().min(1).max(100))
|
|
35
|
+
.max(10)
|
|
36
|
+
.optional()
|
|
37
|
+
.describe('A custom property to assign to the build. Must be in the format `key=value`. Can be specified multiple times.'),
|
|
38
|
+
environment: z.string().optional().describe('The name of the environment to use for the build.'),
|
|
39
|
+
gitRef: z.string().optional().describe('The Git reference (branch, tag, or commit SHA) to build.'),
|
|
40
|
+
iosEq: z.string().optional().describe('The exact iOS CFBundleVersion for the live update.'),
|
|
41
|
+
iosMax: z.string().optional().describe('The maximum iOS CFBundleVersion for the live update.'),
|
|
42
|
+
iosMin: z.string().optional().describe('The minimum iOS CFBundleVersion for the live update.'),
|
|
43
|
+
json: z.boolean().optional().describe('Output in JSON format.'),
|
|
44
|
+
path: z.string().optional().describe('Path to local source files to upload.'),
|
|
45
|
+
rolloutPercentage: z.coerce
|
|
46
|
+
.number()
|
|
47
|
+
.int()
|
|
48
|
+
.min(0)
|
|
49
|
+
.max(100)
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('The rollout percentage for the deployment (0-100). Default: 100.'),
|
|
52
|
+
stack: z
|
|
53
|
+
.enum(['macos-sequoia', 'macos-tahoe'], {
|
|
54
|
+
message: 'Build stack must be either `macos-sequoia` or `macos-tahoe`.',
|
|
55
|
+
})
|
|
56
|
+
.optional()
|
|
57
|
+
.describe('The build stack to use for the build process.'),
|
|
58
|
+
url: z.string().optional().describe('URL to a zip file to use as build source.'),
|
|
59
|
+
variable: z
|
|
60
|
+
.array(z.string())
|
|
61
|
+
.optional()
|
|
62
|
+
.describe('Ad hoc environment variable in key=value format. Can be specified multiple times.'),
|
|
63
|
+
variableFile: z
|
|
64
|
+
.string()
|
|
65
|
+
.optional()
|
|
66
|
+
.describe('Path to a file containing ad hoc environment variables in .env format.'),
|
|
67
|
+
yes: z.boolean().optional().describe('Skip confirmation prompts.'),
|
|
68
|
+
}), { y: 'yes' }),
|
|
69
|
+
action: withAuth(async (options) => {
|
|
70
|
+
let { appId, certificate, channel, gitRef, environment, json, stack, path: sourcePath, url } = options;
|
|
71
|
+
// Validate that path, url, and gitRef cannot be used together
|
|
72
|
+
if (sourcePath && gitRef) {
|
|
73
|
+
consola.error('The --path and --git-ref flags cannot be used together.');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
if (url && gitRef) {
|
|
77
|
+
consola.error('The --url and --git-ref flags cannot be used together.');
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
if (url && sourcePath) {
|
|
81
|
+
consola.error('The --url and --path flags cannot be used together.');
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
// Validate url if provided
|
|
85
|
+
if (url) {
|
|
86
|
+
consola.warn('The --url option is experimental and may change in the future.');
|
|
87
|
+
}
|
|
88
|
+
// Validate path if provided
|
|
89
|
+
if (sourcePath) {
|
|
90
|
+
consola.warn('The --path option is experimental and may change in the future.');
|
|
91
|
+
const resolvedPath = path.resolve(sourcePath);
|
|
92
|
+
const stat = await fs.stat(resolvedPath).catch(() => null);
|
|
93
|
+
if (!stat || !stat.isDirectory()) {
|
|
94
|
+
consola.error('The --path must point to an existing directory.');
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
const packageJsonPath = path.join(resolvedPath, 'package.json');
|
|
98
|
+
const packageJsonStat = await fs.stat(packageJsonPath).catch(() => null);
|
|
99
|
+
if (!packageJsonStat || !packageJsonStat.isFile()) {
|
|
100
|
+
consola.error('The directory specified by --path must contain a package.json file.');
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Prompt for app ID if not provided
|
|
105
|
+
if (!appId) {
|
|
106
|
+
if (!isInteractive()) {
|
|
107
|
+
consola.error('You must provide an app ID when running in non-interactive environment.');
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
const organizationId = await promptOrganizationSelection({ allowCreate: true });
|
|
111
|
+
appId = await promptAppSelection(organizationId, { allowCreate: true });
|
|
112
|
+
}
|
|
113
|
+
// Prompt for git ref if not provided and no path or url specified
|
|
114
|
+
if (!sourcePath && !url && !gitRef) {
|
|
115
|
+
if (!isInteractive()) {
|
|
116
|
+
consola.error('You must provide a git ref, path, or url when running in non-interactive environment.');
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
gitRef = await prompt('Enter the Git reference (branch, tag, or commit SHA):', {
|
|
120
|
+
type: 'text',
|
|
121
|
+
});
|
|
122
|
+
if (!gitRef) {
|
|
123
|
+
consola.error('You must provide a git ref.');
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Prompt for channel if not provided
|
|
128
|
+
if (!channel) {
|
|
129
|
+
if (!isInteractive()) {
|
|
130
|
+
consola.error('You must provide a channel when running in non-interactive environment.');
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
channel = await prompt('Enter the channel name to deploy to:', {
|
|
134
|
+
type: 'text',
|
|
135
|
+
});
|
|
136
|
+
if (!channel) {
|
|
137
|
+
consola.error('You must provide a channel.');
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Prompt for environment if not provided
|
|
142
|
+
if (!environment && !options.yes && isInteractive()) {
|
|
143
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
144
|
+
const selectEnvironment = await prompt('Do you want to select an environment?', {
|
|
145
|
+
type: 'confirm',
|
|
146
|
+
initial: false,
|
|
147
|
+
});
|
|
148
|
+
if (selectEnvironment) {
|
|
149
|
+
const environments = await appEnvironmentsService.findAll({ appId });
|
|
150
|
+
if (environments.length === 0) {
|
|
151
|
+
consola.warn('No environments found for this app.');
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
155
|
+
environment = await prompt('Select the environment for the build:', {
|
|
156
|
+
type: 'select',
|
|
157
|
+
options: environments.map((env) => ({ label: env.name, value: env.name })),
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Prompt for certificate if not provided
|
|
163
|
+
if (!certificate && !options.yes && isInteractive()) {
|
|
164
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
165
|
+
const selectCertificate = await prompt('Do you want to select a certificate?', {
|
|
166
|
+
type: 'confirm',
|
|
167
|
+
initial: false,
|
|
168
|
+
});
|
|
169
|
+
if (selectCertificate) {
|
|
170
|
+
const certificates = await appCertificatesService.findAll({ appId, platform: 'web' });
|
|
171
|
+
if (certificates.length === 0) {
|
|
172
|
+
consola.warn('No certificates found for this app.');
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged
|
|
176
|
+
certificate = await prompt('Select the certificate for the build:', {
|
|
177
|
+
type: 'select',
|
|
178
|
+
options: certificates.map((cert) => ({ label: cert.name, value: cert.name })),
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Parse ad hoc environment variables from inline and file
|
|
184
|
+
const variablesMap = new Map();
|
|
185
|
+
if (options.variableFile) {
|
|
186
|
+
const fileContent = await fs.readFile(options.variableFile, 'utf-8');
|
|
187
|
+
const fileVariables = parseKeyValuePairs(fileContent);
|
|
188
|
+
fileVariables.forEach((v) => variablesMap.set(v.key, v.value));
|
|
189
|
+
}
|
|
190
|
+
if (options.variable) {
|
|
191
|
+
const inlineVariables = parseKeyValuePairs(options.variable.join('\n'));
|
|
192
|
+
inlineVariables.forEach((v) => variablesMap.set(v.key, v.value));
|
|
193
|
+
}
|
|
194
|
+
const adHocEnvironmentVariables = variablesMap.size > 0 ? Object.fromEntries(variablesMap) : undefined;
|
|
195
|
+
// Create build source from URL if provided
|
|
196
|
+
let appBuildSourceId;
|
|
197
|
+
if (url) {
|
|
198
|
+
consola.start('Creating build source from URL...');
|
|
199
|
+
const appBuildSource = await appBuildSourcesService.createFromUrl({ appId, fileUrl: url });
|
|
200
|
+
appBuildSourceId = appBuildSource.id;
|
|
201
|
+
consola.success('Build source created successfully.');
|
|
202
|
+
}
|
|
203
|
+
// Upload source files if path is provided
|
|
204
|
+
if (sourcePath) {
|
|
205
|
+
const resolvedPath = path.resolve(sourcePath);
|
|
206
|
+
consola.start('Zipping source files...');
|
|
207
|
+
const buffer = await zip.zipFolderWithGitignore(resolvedPath);
|
|
208
|
+
consola.start('Uploading source files...');
|
|
209
|
+
const appBuildSource = await appBuildSourcesService.createFromFile({
|
|
210
|
+
appId,
|
|
211
|
+
fileSizeInBytes: buffer.byteLength,
|
|
212
|
+
buffer,
|
|
213
|
+
name: 'source.zip',
|
|
214
|
+
}, (currentPart, totalParts) => {
|
|
215
|
+
consola.start(`Uploading source files (${currentPart}/${totalParts})...`);
|
|
216
|
+
});
|
|
217
|
+
appBuildSourceId = appBuildSource.id;
|
|
218
|
+
consola.success('Source files uploaded successfully.');
|
|
219
|
+
}
|
|
220
|
+
// Create the web build
|
|
221
|
+
consola.start('Creating build...');
|
|
222
|
+
const response = await appBuildsService.create({
|
|
223
|
+
adHocEnvironmentVariables,
|
|
224
|
+
appBuildSourceId,
|
|
225
|
+
appCertificateName: certificate,
|
|
226
|
+
appEnvironmentName: environment,
|
|
227
|
+
appId,
|
|
228
|
+
stack,
|
|
229
|
+
gitRef,
|
|
230
|
+
platform: 'web',
|
|
231
|
+
});
|
|
232
|
+
consola.info(`Build ID: ${response.id}`);
|
|
233
|
+
consola.info(`Build Number: ${response.numberAsString}`);
|
|
234
|
+
consola.info(`Build URL: ${DEFAULT_CONSOLE_BASE_URL}/apps/${appId}/builds/${response.id}`);
|
|
235
|
+
consola.success('Build created successfully.');
|
|
236
|
+
// Wait for build to complete
|
|
237
|
+
await waitForJobCompletion({ jobId: response.jobId });
|
|
238
|
+
consola.success('Build completed successfully.');
|
|
239
|
+
console.log();
|
|
240
|
+
// Update build with custom properties and version constraints if any are provided
|
|
241
|
+
const customProperties = parseCustomProperties(options.customProperty);
|
|
242
|
+
const hasUpdateFields = customProperties ||
|
|
243
|
+
options.androidMin ||
|
|
244
|
+
options.androidMax ||
|
|
245
|
+
options.androidEq ||
|
|
246
|
+
options.iosMin ||
|
|
247
|
+
options.iosMax ||
|
|
248
|
+
options.iosEq;
|
|
249
|
+
if (hasUpdateFields) {
|
|
250
|
+
consola.start('Updating build...');
|
|
251
|
+
await appBuildsService.update({
|
|
252
|
+
appId,
|
|
253
|
+
appBuildId: response.id,
|
|
254
|
+
customProperties,
|
|
255
|
+
minAndroidAppVersionCode: options.androidMin,
|
|
256
|
+
maxAndroidAppVersionCode: options.androidMax,
|
|
257
|
+
eqAndroidAppVersionCode: options.androidEq,
|
|
258
|
+
minIosAppVersionCode: options.iosMin,
|
|
259
|
+
maxIosAppVersionCode: options.iosMax,
|
|
260
|
+
eqIosAppVersionCode: options.iosEq,
|
|
261
|
+
});
|
|
262
|
+
consola.success('Build updated successfully.');
|
|
263
|
+
}
|
|
264
|
+
// Deploy to channel
|
|
265
|
+
consola.start('Creating deployment...');
|
|
266
|
+
const rolloutPercentage = (options.rolloutPercentage ?? 100) / 100;
|
|
267
|
+
const deployment = await appDeploymentsService.create({
|
|
268
|
+
appId,
|
|
269
|
+
appBuildId: response.id,
|
|
270
|
+
appChannelName: channel,
|
|
271
|
+
rolloutPercentage,
|
|
272
|
+
});
|
|
273
|
+
consola.info(`Deployment ID: ${deployment.id}`);
|
|
274
|
+
consola.info(`Deployment URL: ${DEFAULT_CONSOLE_BASE_URL}/apps/${appId}/deployments/${deployment.id}`);
|
|
275
|
+
consola.success('Deployment created successfully.');
|
|
276
|
+
// Output JSON if json flag is set
|
|
277
|
+
if (json) {
|
|
278
|
+
console.log(JSON.stringify({
|
|
279
|
+
buildId: response.id,
|
|
280
|
+
buildNumberAsString: response.numberAsString,
|
|
281
|
+
deploymentId: deployment.id,
|
|
282
|
+
}, null, 2));
|
|
283
|
+
}
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { DEFAULT_API_BASE_URL, DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
|
+
import authorizationService from '../../../services/authorization-service.js';
|
|
3
|
+
import userConfig from '../../../utils/user-config.js';
|
|
4
|
+
import consola from 'consola';
|
|
5
|
+
import nock from 'nock';
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
import createCommand from './create.js';
|
|
8
|
+
// Mock dependencies
|
|
9
|
+
vi.mock('@/utils/user-config.js');
|
|
10
|
+
vi.mock('@/utils/prompt.js');
|
|
11
|
+
vi.mock('@/services/authorization-service.js');
|
|
12
|
+
vi.mock('@/utils/job.js');
|
|
13
|
+
vi.mock('consola');
|
|
14
|
+
vi.mock('@/utils/environment.js', () => ({
|
|
15
|
+
isInteractive: () => false,
|
|
16
|
+
}));
|
|
17
|
+
describe('apps-liveupdates-create', () => {
|
|
18
|
+
const mockUserConfig = vi.mocked(userConfig);
|
|
19
|
+
const mockAuthorizationService = vi.mocked(authorizationService);
|
|
20
|
+
const mockConsola = vi.mocked(consola);
|
|
21
|
+
const testToken = 'test-token';
|
|
22
|
+
const appId = '00000000-0000-0000-0000-000000000001';
|
|
23
|
+
const buildId = '00000000-0000-0000-0000-000000000002';
|
|
24
|
+
const deploymentId = '00000000-0000-0000-0000-000000000003';
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
vi.clearAllMocks();
|
|
27
|
+
mockUserConfig.read.mockReturnValue({ token: testToken });
|
|
28
|
+
mockAuthorizationService.hasAuthorizationToken.mockReturnValue(true);
|
|
29
|
+
mockAuthorizationService.getCurrentAuthorizationToken.mockReturnValue(testToken);
|
|
30
|
+
// Mock waitForJobCompletion to resolve immediately
|
|
31
|
+
const jobUtils = await import('../../../utils/job.js');
|
|
32
|
+
vi.mocked(jobUtils.waitForJobCompletion).mockResolvedValue({
|
|
33
|
+
id: 'job-1',
|
|
34
|
+
status: 'succeeded',
|
|
35
|
+
createdAt: '2024-01-01T00:00:00Z',
|
|
36
|
+
});
|
|
37
|
+
vi.spyOn(process, 'exit').mockImplementation((code) => {
|
|
38
|
+
throw new Error(`Process exited with code ${code}`);
|
|
39
|
+
});
|
|
40
|
+
vi.spyOn(console, 'log').mockImplementation(() => { });
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
nock.cleanAll();
|
|
44
|
+
vi.restoreAllMocks();
|
|
45
|
+
});
|
|
46
|
+
it('should require authentication', async () => {
|
|
47
|
+
mockAuthorizationService.hasAuthorizationToken.mockReturnValue(false);
|
|
48
|
+
const options = { appId, gitRef: 'main', channel: 'production' };
|
|
49
|
+
await expect(createCommand.action(options, undefined)).rejects.toThrow('Process exited with code 1');
|
|
50
|
+
expect(mockConsola.error).toHaveBeenCalledWith('You must be logged in to run this command. Set the `CAPAWESOME_TOKEN` environment variable or use the `--token` option.');
|
|
51
|
+
});
|
|
52
|
+
it('should create a live update with build and deployment', async () => {
|
|
53
|
+
const options = {
|
|
54
|
+
appId,
|
|
55
|
+
gitRef: 'main',
|
|
56
|
+
channel: 'production',
|
|
57
|
+
yes: true,
|
|
58
|
+
};
|
|
59
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
60
|
+
.post(`/v1/apps/${appId}/builds`, {
|
|
61
|
+
gitRef: 'main',
|
|
62
|
+
platform: 'web',
|
|
63
|
+
})
|
|
64
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
65
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '1' });
|
|
66
|
+
const deploymentScope = nock(DEFAULT_API_BASE_URL)
|
|
67
|
+
.post(`/v1/apps/${appId}/deployments`, {
|
|
68
|
+
appId,
|
|
69
|
+
appBuildId: buildId,
|
|
70
|
+
appChannelName: 'production',
|
|
71
|
+
rolloutPercentage: 1,
|
|
72
|
+
})
|
|
73
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
74
|
+
.reply(201, { id: deploymentId });
|
|
75
|
+
await createCommand.action(options, undefined);
|
|
76
|
+
expect(buildScope.isDone()).toBe(true);
|
|
77
|
+
expect(deploymentScope.isDone()).toBe(true);
|
|
78
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Build created successfully.');
|
|
79
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Build completed successfully.');
|
|
80
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Deployment created successfully.');
|
|
81
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Build ID: ${buildId}`);
|
|
82
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Deployment ID: ${deploymentId}`);
|
|
83
|
+
});
|
|
84
|
+
it('should pass environment and certificate to build', async () => {
|
|
85
|
+
const options = {
|
|
86
|
+
appId,
|
|
87
|
+
gitRef: 'v1.0.0',
|
|
88
|
+
channel: 'production',
|
|
89
|
+
environment: 'staging',
|
|
90
|
+
certificate: 'my-cert',
|
|
91
|
+
yes: true,
|
|
92
|
+
};
|
|
93
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
94
|
+
.post(`/v1/apps/${appId}/builds`, {
|
|
95
|
+
gitRef: 'v1.0.0',
|
|
96
|
+
platform: 'web',
|
|
97
|
+
appEnvironmentName: 'staging',
|
|
98
|
+
appCertificateName: 'my-cert',
|
|
99
|
+
})
|
|
100
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
101
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '1' });
|
|
102
|
+
const deploymentScope = nock(DEFAULT_API_BASE_URL)
|
|
103
|
+
.post(`/v1/apps/${appId}/deployments`)
|
|
104
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
105
|
+
.reply(201, { id: deploymentId });
|
|
106
|
+
await createCommand.action(options, undefined);
|
|
107
|
+
expect(buildScope.isDone()).toBe(true);
|
|
108
|
+
expect(deploymentScope.isDone()).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
it('should pass stack to build', async () => {
|
|
111
|
+
const options = {
|
|
112
|
+
appId,
|
|
113
|
+
gitRef: 'main',
|
|
114
|
+
channel: 'production',
|
|
115
|
+
stack: 'macos-tahoe',
|
|
116
|
+
yes: true,
|
|
117
|
+
};
|
|
118
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
119
|
+
.post(`/v1/apps/${appId}/builds`, {
|
|
120
|
+
gitRef: 'main',
|
|
121
|
+
platform: 'web',
|
|
122
|
+
stack: 'macos-tahoe',
|
|
123
|
+
})
|
|
124
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
125
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '1' });
|
|
126
|
+
const deploymentScope = nock(DEFAULT_API_BASE_URL)
|
|
127
|
+
.post(`/v1/apps/${appId}/deployments`)
|
|
128
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
129
|
+
.reply(201, { id: deploymentId });
|
|
130
|
+
await createCommand.action(options, undefined);
|
|
131
|
+
expect(buildScope.isDone()).toBe(true);
|
|
132
|
+
expect(deploymentScope.isDone()).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
it('should update version constraints when provided', async () => {
|
|
135
|
+
const options = {
|
|
136
|
+
appId,
|
|
137
|
+
gitRef: 'main',
|
|
138
|
+
channel: 'production',
|
|
139
|
+
androidMin: '10',
|
|
140
|
+
androidMax: '50',
|
|
141
|
+
iosEq: '42',
|
|
142
|
+
yes: true,
|
|
143
|
+
};
|
|
144
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
145
|
+
.post(`/v1/apps/${appId}/builds`)
|
|
146
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
147
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '1' });
|
|
148
|
+
const updateScope = nock(DEFAULT_API_BASE_URL)
|
|
149
|
+
.patch(`/v1/apps/${appId}/builds/${buildId}`, {
|
|
150
|
+
minAndroidAppVersionCode: '10',
|
|
151
|
+
maxAndroidAppVersionCode: '50',
|
|
152
|
+
eqIosAppVersionCode: '42',
|
|
153
|
+
})
|
|
154
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
155
|
+
.reply(200, { id: buildId });
|
|
156
|
+
const deploymentScope = nock(DEFAULT_API_BASE_URL)
|
|
157
|
+
.post(`/v1/apps/${appId}/deployments`)
|
|
158
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
159
|
+
.reply(201, { id: deploymentId });
|
|
160
|
+
await createCommand.action(options, undefined);
|
|
161
|
+
expect(buildScope.isDone()).toBe(true);
|
|
162
|
+
expect(updateScope.isDone()).toBe(true);
|
|
163
|
+
expect(deploymentScope.isDone()).toBe(true);
|
|
164
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Build updated successfully.');
|
|
165
|
+
});
|
|
166
|
+
it('should convert rollout percentage to decimal', async () => {
|
|
167
|
+
const options = {
|
|
168
|
+
appId,
|
|
169
|
+
gitRef: 'main',
|
|
170
|
+
channel: 'production',
|
|
171
|
+
rolloutPercentage: 50,
|
|
172
|
+
yes: true,
|
|
173
|
+
};
|
|
174
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
175
|
+
.post(`/v1/apps/${appId}/builds`)
|
|
176
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
177
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '1' });
|
|
178
|
+
const deploymentScope = nock(DEFAULT_API_BASE_URL)
|
|
179
|
+
.post(`/v1/apps/${appId}/deployments`, {
|
|
180
|
+
appId,
|
|
181
|
+
appBuildId: buildId,
|
|
182
|
+
appChannelName: 'production',
|
|
183
|
+
rolloutPercentage: 0.5,
|
|
184
|
+
})
|
|
185
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
186
|
+
.reply(201, { id: deploymentId });
|
|
187
|
+
await createCommand.action(options, undefined);
|
|
188
|
+
expect(buildScope.isDone()).toBe(true);
|
|
189
|
+
expect(deploymentScope.isDone()).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
it('should output JSON when json flag is set', async () => {
|
|
192
|
+
const options = {
|
|
193
|
+
appId,
|
|
194
|
+
gitRef: 'main',
|
|
195
|
+
channel: 'production',
|
|
196
|
+
json: true,
|
|
197
|
+
yes: true,
|
|
198
|
+
};
|
|
199
|
+
nock(DEFAULT_API_BASE_URL)
|
|
200
|
+
.post(`/v1/apps/${appId}/builds`)
|
|
201
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
202
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '42' });
|
|
203
|
+
nock(DEFAULT_API_BASE_URL)
|
|
204
|
+
.post(`/v1/apps/${appId}/deployments`)
|
|
205
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
206
|
+
.reply(201, { id: deploymentId });
|
|
207
|
+
await createCommand.action(options, undefined);
|
|
208
|
+
expect(console.log).toHaveBeenCalledWith(JSON.stringify({
|
|
209
|
+
buildId,
|
|
210
|
+
buildNumberAsString: '42',
|
|
211
|
+
deploymentId,
|
|
212
|
+
}, null, 2));
|
|
213
|
+
});
|
|
214
|
+
it('should require app ID in non-interactive mode', async () => {
|
|
215
|
+
const options = { gitRef: 'main', channel: 'production' };
|
|
216
|
+
await expect(createCommand.action(options, undefined)).rejects.toThrow('Process exited with code 1');
|
|
217
|
+
expect(mockConsola.error).toHaveBeenCalledWith('You must provide an app ID when running in non-interactive environment.');
|
|
218
|
+
});
|
|
219
|
+
it('should require git ref in non-interactive mode', async () => {
|
|
220
|
+
const options = { appId, channel: 'production' };
|
|
221
|
+
await expect(createCommand.action(options, undefined)).rejects.toThrow('Process exited with code 1');
|
|
222
|
+
expect(mockConsola.error).toHaveBeenCalledWith('You must provide a git ref, path, or url when running in non-interactive environment.');
|
|
223
|
+
});
|
|
224
|
+
it('should require channel in non-interactive mode', async () => {
|
|
225
|
+
const options = { appId, gitRef: 'main' };
|
|
226
|
+
await expect(createCommand.action(options, undefined)).rejects.toThrow('Process exited with code 1');
|
|
227
|
+
expect(mockConsola.error).toHaveBeenCalledWith('You must provide a channel when running in non-interactive environment.');
|
|
228
|
+
});
|
|
229
|
+
it('should handle build creation API error', async () => {
|
|
230
|
+
const options = {
|
|
231
|
+
appId,
|
|
232
|
+
gitRef: 'main',
|
|
233
|
+
channel: 'production',
|
|
234
|
+
yes: true,
|
|
235
|
+
};
|
|
236
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
237
|
+
.post(`/v1/apps/${appId}/builds`)
|
|
238
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
239
|
+
.reply(400, { message: 'Invalid build data' });
|
|
240
|
+
await expect(createCommand.action(options, undefined)).rejects.toThrow();
|
|
241
|
+
expect(buildScope.isDone()).toBe(true);
|
|
242
|
+
});
|
|
243
|
+
it('should include build URL in output', async () => {
|
|
244
|
+
const options = {
|
|
245
|
+
appId,
|
|
246
|
+
gitRef: 'main',
|
|
247
|
+
channel: 'production',
|
|
248
|
+
yes: true,
|
|
249
|
+
};
|
|
250
|
+
nock(DEFAULT_API_BASE_URL)
|
|
251
|
+
.post(`/v1/apps/${appId}/builds`)
|
|
252
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
253
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '1' });
|
|
254
|
+
nock(DEFAULT_API_BASE_URL)
|
|
255
|
+
.post(`/v1/apps/${appId}/deployments`)
|
|
256
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
257
|
+
.reply(201, { id: deploymentId });
|
|
258
|
+
await createCommand.action(options, undefined);
|
|
259
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Build URL: ${DEFAULT_CONSOLE_BASE_URL}/apps/${appId}/builds/${buildId}`);
|
|
260
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Deployment URL: ${DEFAULT_CONSOLE_BASE_URL}/apps/${appId}/deployments/${deploymentId}`);
|
|
261
|
+
});
|
|
262
|
+
});
|