@capawesome/cli 4.25.0 → 4.26.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.
- package/CHANGELOG.md +19 -0
- package/dist/commands/apps/automations/create.js +6 -9
- package/dist/commands/apps/automations/update.js +11 -26
- package/dist/commands/apps/automations/update.test.js +18 -1
- package/dist/commands/apps/builds/create.js +10 -9
- package/dist/commands/apps/builds/create.test.js +16 -0
- package/dist/commands/apps/create.js +3 -2
- package/dist/commands/apps/deployments/create.js +6 -4
- package/dist/commands/apps/deployments/create.test.js +17 -0
- package/dist/commands/apps/destinations/create.js +2 -5
- package/dist/commands/apps/destinations/update.js +3 -6
- package/dist/commands/apps/destinations/update.test.js +1 -1
- package/dist/commands/apps/import.js +9 -8
- package/dist/commands/apps/link.js +3 -2
- package/dist/commands/apps/liveupdates/create.js +10 -7
- package/dist/commands/apps/liveupdates/generate-signing-key.js +3 -2
- package/dist/commands/apps/liveupdates/register.js +21 -4
- package/dist/commands/apps/liveupdates/register.test.js +39 -0
- package/dist/commands/apps/liveupdates/rollback.js +3 -2
- package/dist/commands/apps/liveupdates/rollout.js +3 -2
- package/dist/commands/apps/liveupdates/upload.js +22 -4
- package/dist/commands/apps/liveupdates/upload.test.js +60 -0
- package/dist/commands/apps/update.js +7 -16
- package/dist/commands/apps/update.test.js +1 -1
- package/dist/utils/cli-options.js +11 -0
- package/dist/utils/cli-options.test.js +29 -1
- package/dist/utils/file.js +14 -13
- package/dist/utils/file.test.js +28 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [4.26.1](https://github.com/capawesome-team/cli/compare/v4.26.0...v4.26.1) (2026-10-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **apps:liveupdates:generate-signing-key:** show actionable error message if key files cannot be written ([#246](https://github.com/capawesome-team/cli/issues/246)) ([14f477e](https://github.com/capawesome-team/cli/commit/14f477e5ac84bb3a62d94c959c30f84cbf524e84))
|
|
11
|
+
|
|
12
|
+
## [4.26.0](https://github.com/capawesome-team/cli/compare/v4.25.0...v4.26.0) (2026-10-05)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add Electron app version constraint flags for live update bundles ([#185](https://github.com/capawesome-team/cli/issues/185)) ([b1109d6](https://github.com/capawesome-team/cli/commit/b1109d6b40c01325e35cbd9f0a2aa0d6c8123e7a))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* use the configured console URL in printed links ([#241](https://github.com/capawesome-team/cli/issues/241)) ([511d220](https://github.com/capawesome-team/cli/commit/511d2201643aed8733f36a1ca9edef67b24cd850))
|
|
23
|
+
|
|
5
24
|
## [4.25.0](https://github.com/capawesome-team/cli/compare/v4.24.0...v4.25.0) (2026-10-04)
|
|
6
25
|
|
|
7
26
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import appAutomationsService from '../../../services/app-automations.js';
|
|
2
2
|
import appsService from '../../../services/apps.js';
|
|
3
3
|
import { withAuth } from '../../../utils/auth.js';
|
|
4
|
-
import { parseListOption } from '../../../utils/cli-options.js';
|
|
4
|
+
import { parseListOption, stringOption } from '../../../utils/cli-options.js';
|
|
5
5
|
import { isInteractive } from '../../../utils/environment.js';
|
|
6
6
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
7
7
|
import consola from 'consola';
|
|
@@ -11,18 +11,15 @@ export default defineCommand({
|
|
|
11
11
|
description: 'Create a new app automation.',
|
|
12
12
|
options: defineOptions(z.object({
|
|
13
13
|
appId: z.string().optional().describe('ID of the app.'),
|
|
14
|
-
certificate:
|
|
14
|
+
certificate: stringOption.describe('The name of the certificate to use for the build.'),
|
|
15
15
|
channel: z
|
|
16
16
|
.array(z.string())
|
|
17
17
|
.optional()
|
|
18
18
|
.describe('The name of a channel to deploy to (Web only). Can be specified multiple times or comma-separated.'),
|
|
19
|
-
commitMessagePattern:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
configuration: z.string().optional().describe('The name of the native configuration (Android/iOS only).'),
|
|
24
|
-
destination: z.string().optional().describe('The name of the destination to deploy to (Android/iOS only).'),
|
|
25
|
-
environment: z.string().optional().describe('The name of the environment to use for the build.'),
|
|
19
|
+
commitMessagePattern: stringOption.describe('Only trigger for commits whose message matches this pattern (branch triggers only).'),
|
|
20
|
+
configuration: stringOption.describe('The name of the native configuration (Android/iOS only).'),
|
|
21
|
+
destination: stringOption.describe('The name of the destination to deploy to (Android/iOS only).'),
|
|
22
|
+
environment: stringOption.describe('The name of the environment to use for the build.'),
|
|
26
23
|
json: z.boolean().optional().describe('Output in JSON format.'),
|
|
27
24
|
name: z.string().optional().describe('Name of the automation.'),
|
|
28
25
|
platform: z
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import appAutomationsService from '../../../services/app-automations.js';
|
|
2
2
|
import { withAuth } from '../../../utils/auth.js';
|
|
3
|
-
import { clearableValue, parseListOption } from '../../../utils/cli-options.js';
|
|
3
|
+
import { clearableStringOption, clearableValue, parseListOption } from '../../../utils/cli-options.js';
|
|
4
4
|
import { isInteractive } from '../../../utils/environment.js';
|
|
5
5
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
6
6
|
import consola from 'consola';
|
|
@@ -12,30 +12,15 @@ export default defineCommand({
|
|
|
12
12
|
options: defineOptions(z.object({
|
|
13
13
|
appId: z.string().optional().describe('ID of the app.'),
|
|
14
14
|
automationId: z.string().optional().describe('ID of the automation.'),
|
|
15
|
-
certificate:
|
|
16
|
-
.string()
|
|
17
|
-
.optional()
|
|
18
|
-
.describe('The name of the certificate to use for the build. Pass an empty string to clear it.'),
|
|
15
|
+
certificate: clearableStringOption.describe('The name of the certificate to use for the build. Pass an empty string to clear it.'),
|
|
19
16
|
channel: z
|
|
20
17
|
.array(z.string())
|
|
21
18
|
.optional()
|
|
22
19
|
.describe('The name of a channel to deploy to (Web only). Can be specified multiple times or comma-separated. Pass an empty string to clear them.'),
|
|
23
|
-
commitMessagePattern:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
configuration: z
|
|
28
|
-
.string()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe('The name of the native configuration (Android/iOS only). Pass an empty string to clear it.'),
|
|
31
|
-
destination: z
|
|
32
|
-
.string()
|
|
33
|
-
.optional()
|
|
34
|
-
.describe('The name of the destination to deploy to (Android/iOS only). Pass an empty string to clear it.'),
|
|
35
|
-
environment: z
|
|
36
|
-
.string()
|
|
37
|
-
.optional()
|
|
38
|
-
.describe('The name of the environment to use for the build. Pass an empty string to clear it.'),
|
|
20
|
+
commitMessagePattern: clearableStringOption.describe('Only trigger for commits whose message matches this pattern (branch triggers only). Pass an empty string to clear it.'),
|
|
21
|
+
configuration: clearableStringOption.describe('The name of the native configuration (Android/iOS only). Pass an empty string to clear it.'),
|
|
22
|
+
destination: clearableStringOption.describe('The name of the destination to deploy to (Android/iOS only). Pass an empty string to clear it.'),
|
|
23
|
+
environment: clearableStringOption.describe('The name of the environment to use for the build. Pass an empty string to clear it.'),
|
|
39
24
|
json: z.boolean().optional().describe('Output in JSON format.'),
|
|
40
25
|
name: z.string().optional().describe('Name of the automation.'),
|
|
41
26
|
platform: z
|
|
@@ -94,16 +79,16 @@ export default defineCommand({
|
|
|
94
79
|
});
|
|
95
80
|
}
|
|
96
81
|
await appAutomationsService.update({
|
|
97
|
-
appCertificateName:
|
|
82
|
+
appCertificateName: options.certificate,
|
|
98
83
|
appChannelNames: parseListOption(options.channel),
|
|
99
|
-
appConfigurationName:
|
|
100
|
-
appDestinationName:
|
|
101
|
-
appEnvironmentName:
|
|
84
|
+
appConfigurationName: options.configuration,
|
|
85
|
+
appDestinationName: options.destination,
|
|
86
|
+
appEnvironmentName: options.environment,
|
|
102
87
|
appId,
|
|
103
88
|
automationId,
|
|
104
89
|
buildStack: clearableValue(options.stack),
|
|
105
90
|
buildType: options.type,
|
|
106
|
-
commitMessagePattern:
|
|
91
|
+
commitMessagePattern: options.commitMessagePattern,
|
|
107
92
|
name: options.name,
|
|
108
93
|
platform: options.platform,
|
|
109
94
|
triggerPatterns: clearableValues(options.triggerPattern),
|
|
@@ -59,7 +59,12 @@ describe('apps-automations-update', () => {
|
|
|
59
59
|
it('should clear a reference when an empty string is passed', async () => {
|
|
60
60
|
const appId = 'app-123';
|
|
61
61
|
const automationId = 'automation-456';
|
|
62
|
-
const options = {
|
|
62
|
+
const options = updateAutomationCommand.options.schema.parse({
|
|
63
|
+
appId,
|
|
64
|
+
automationId,
|
|
65
|
+
certificate: '',
|
|
66
|
+
triggerPattern: [''],
|
|
67
|
+
});
|
|
63
68
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
64
69
|
.patch(`/v1/apps/${appId}/automations/${automationId}`, {
|
|
65
70
|
appCertificateName: null,
|
|
@@ -71,6 +76,18 @@ describe('apps-automations-update', () => {
|
|
|
71
76
|
expect(scope.isDone()).toBe(true);
|
|
72
77
|
expect(mockConsola.success).toHaveBeenCalledWith('Automation updated successfully.');
|
|
73
78
|
});
|
|
79
|
+
it('should clear a reference when a whitespace-only string is passed', async () => {
|
|
80
|
+
const appId = 'app-123';
|
|
81
|
+
const automationId = 'automation-456';
|
|
82
|
+
const options = updateAutomationCommand.options.schema.parse({ appId, automationId, certificate: ' ' });
|
|
83
|
+
const scope = nock(DEFAULT_API_BASE_URL)
|
|
84
|
+
.patch(`/v1/apps/${appId}/automations/${automationId}`, { appCertificateName: null })
|
|
85
|
+
.matchHeader('Authorization', 'Bearer test-token')
|
|
86
|
+
.reply(204);
|
|
87
|
+
await updateAutomationCommand.action(options, undefined);
|
|
88
|
+
expect(scope.isDone()).toBe(true);
|
|
89
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Automation updated successfully.');
|
|
90
|
+
});
|
|
74
91
|
it('should send the channels as appChannelNames', async () => {
|
|
75
92
|
const appId = 'app-123';
|
|
76
93
|
const automationId = 'automation-456';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
1
|
import appBuildSourcesService from '../../../services/app-build-sources.js';
|
|
3
2
|
import appBuildsService from '../../../services/app-builds.js';
|
|
4
3
|
import appCertificatesService from '../../../services/app-certificates.js';
|
|
5
4
|
import appConfigurationsService from '../../../services/app-configurations.js';
|
|
6
5
|
import appEnvironmentsService from '../../../services/app-environments.js';
|
|
7
6
|
import appsService from '../../../services/apps.js';
|
|
7
|
+
import configService from '../../../services/config.js';
|
|
8
8
|
import { APP_BUILD_ARTIFACT_FORM_FACTORS, APP_BUILD_ARTIFACT_TYPES_BY_PLATFORM, handleAppBuildArtifactDownload, } from '../../../utils/app-build-artifacts.js';
|
|
9
9
|
import { getAppBuildShareUrls } from '../../../utils/app-build-shares.js';
|
|
10
10
|
import { parseKeyValuePairs } from '../../../utils/app-environments.js';
|
|
11
11
|
import { withAuth } from '../../../utils/auth.js';
|
|
12
12
|
import { createBufferFromPath } from '../../../utils/buffer.js';
|
|
13
|
-
import { parseListOption } from '../../../utils/cli-options.js';
|
|
13
|
+
import { parseListOption, stringOption } from '../../../utils/cli-options.js';
|
|
14
14
|
import { isInteractive } from '../../../utils/environment.js';
|
|
15
15
|
import { offerJobFailureSummary } from '../../../utils/job-failure-summary.js';
|
|
16
16
|
import { isDirectory, isReadable } from '../../../utils/file.js';
|
|
@@ -46,18 +46,18 @@ export default defineCommand({
|
|
|
46
46
|
})
|
|
47
47
|
.optional()
|
|
48
48
|
.describe('App ID to create the build for.'),
|
|
49
|
-
certificate:
|
|
49
|
+
certificate: stringOption.describe('The name of the certificate to use for the build.'),
|
|
50
50
|
channel: z
|
|
51
51
|
.array(z.string())
|
|
52
52
|
.optional()
|
|
53
53
|
.describe('The name of a channel to deploy to (Web only). Can be specified multiple times or comma-separated.'),
|
|
54
|
-
configuration:
|
|
55
|
-
destination:
|
|
54
|
+
configuration: stringOption.describe('The name of the native configuration (Android/iOS only).'),
|
|
55
|
+
destination: stringOption.describe('The name of the destination to deploy to (Android/iOS only).'),
|
|
56
56
|
detached: z
|
|
57
57
|
.boolean()
|
|
58
58
|
.optional()
|
|
59
59
|
.describe('Exit immediately after creating the build without waiting for completion.'),
|
|
60
|
-
environment:
|
|
60
|
+
environment: stringOption.describe('The name of the environment to use for the build.'),
|
|
61
61
|
failureSummary: z
|
|
62
62
|
.boolean()
|
|
63
63
|
.optional()
|
|
@@ -423,7 +423,8 @@ export default defineCommand({
|
|
|
423
423
|
});
|
|
424
424
|
consola.info(`Build ID: ${response.id}`);
|
|
425
425
|
consola.info(`Build Number: ${response.numberAsString}`);
|
|
426
|
-
|
|
426
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
427
|
+
consola.info(`Build URL: ${consoleBaseUrl}/apps/${appId}/builds/${response.id}`);
|
|
427
428
|
consola.success('Build created successfully.');
|
|
428
429
|
if (channels?.length) {
|
|
429
430
|
consola.info(`The build will be deployed to the following ${channels.length === 1 ? 'channel' : 'channels'} once it succeeds: ${channels.join(', ')}.`);
|
|
@@ -446,7 +447,7 @@ export default defineCommand({
|
|
|
446
447
|
});
|
|
447
448
|
consola.info(`Build ID: ${response.id}`);
|
|
448
449
|
consola.info(`Build Number: ${response.numberAsString}`);
|
|
449
|
-
consola.info(`Build URL: ${
|
|
450
|
+
consola.info(`Build URL: ${consoleBaseUrl}/apps/${appId}/builds/${response.id}`);
|
|
450
451
|
consola.success('Build completed successfully.');
|
|
451
452
|
console.log();
|
|
452
453
|
// Download artifacts if flags are set
|
|
@@ -517,7 +518,7 @@ export default defineCommand({
|
|
|
517
518
|
else {
|
|
518
519
|
consola.info(`Build ID: ${response.id}`);
|
|
519
520
|
consola.info(`Build Number: ${response.numberAsString}`);
|
|
520
|
-
consola.info(`Build URL: ${
|
|
521
|
+
consola.info(`Build URL: ${consoleBaseUrl}/apps/${appId}/builds/${response.id}`);
|
|
521
522
|
consola.success('Build started successfully.');
|
|
522
523
|
}
|
|
523
524
|
}
|
|
@@ -164,6 +164,22 @@ describe('apps-builds-create', () => {
|
|
|
164
164
|
expect(buildScope.isDone()).toBe(true);
|
|
165
165
|
expect(mockConsola.error).not.toHaveBeenCalled();
|
|
166
166
|
});
|
|
167
|
+
it('should not send an empty environment', async () => {
|
|
168
|
+
const options = createCommand.options.schema.parse({
|
|
169
|
+
appId: validAppId,
|
|
170
|
+
platform: 'web',
|
|
171
|
+
gitRef: 'main',
|
|
172
|
+
environment: '',
|
|
173
|
+
detached: true,
|
|
174
|
+
});
|
|
175
|
+
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
176
|
+
.post(`/v1/apps/${validAppId}/builds`, (body) => !('appEnvironmentName' in body))
|
|
177
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
178
|
+
.reply(201, { id: buildId, jobId: 'job-1', numberAsString: '42' });
|
|
179
|
+
await createCommand.action(options, undefined);
|
|
180
|
+
expect(buildScope.isDone()).toBe(true);
|
|
181
|
+
expect(mockConsola.error).not.toHaveBeenCalled();
|
|
182
|
+
});
|
|
167
183
|
it('should accept --channel combined with --detached', async () => {
|
|
168
184
|
const options = { appId, platform: 'web', gitRef: 'main', channel: ['beta'], detached: true };
|
|
169
185
|
const buildScope = nock(DEFAULT_API_BASE_URL)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../config/consts.js';
|
|
2
1
|
import appsService from '../../services/apps.js';
|
|
2
|
+
import configService from '../../services/config.js';
|
|
3
3
|
import { withAuth } from '../../utils/auth.js';
|
|
4
4
|
import { isInteractive } from '../../utils/environment.js';
|
|
5
5
|
import { prompt, promptOrganizationSelection } from '../../utils/prompt.js';
|
|
@@ -39,7 +39,8 @@ export default defineCommand({
|
|
|
39
39
|
const response = await appsService.create({ name, organizationId, type });
|
|
40
40
|
if (!json) {
|
|
41
41
|
consola.info(`App ID: ${response.id}`);
|
|
42
|
-
|
|
42
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
43
|
+
consola.info(`App URL: ${consoleBaseUrl}/apps/${response.id}`);
|
|
43
44
|
consola.success('App created successfully.');
|
|
44
45
|
}
|
|
45
46
|
let shouldLink = options.link ?? false;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
1
|
import appBuildsService from '../../../services/app-builds.js';
|
|
3
2
|
import appDeploymentsService from '../../../services/app-deployments.js';
|
|
4
3
|
import appDestinationsService from '../../../services/app-destinations.js';
|
|
4
|
+
import configService from '../../../services/config.js';
|
|
5
5
|
import { withAuth } from '../../../utils/auth.js';
|
|
6
|
+
import { stringOption } from '../../../utils/cli-options.js';
|
|
6
7
|
import { isInteractive } from '../../../utils/environment.js';
|
|
7
8
|
import { offerJobFailureSummary } from '../../../utils/job-failure-summary.js';
|
|
8
9
|
import { waitForJobCompletion } from '../../../utils/job.js';
|
|
@@ -27,8 +28,8 @@ export default defineCommand({
|
|
|
27
28
|
.optional()
|
|
28
29
|
.describe('Build ID to deploy.'),
|
|
29
30
|
buildNumber: z.string().optional().describe('Build number to deploy (e.g., "1", "42").'),
|
|
30
|
-
channel:
|
|
31
|
-
destination:
|
|
31
|
+
channel: stringOption.describe('The name of the channel to deploy to (Web only).'),
|
|
32
|
+
destination: stringOption.describe('The name of the destination to deploy to (Android/iOS only).'),
|
|
32
33
|
detached: z
|
|
33
34
|
.boolean()
|
|
34
35
|
.optional()
|
|
@@ -171,7 +172,8 @@ export default defineCommand({
|
|
|
171
172
|
releaseNotes,
|
|
172
173
|
});
|
|
173
174
|
consola.info(`Deployment ID: ${response.id}`);
|
|
174
|
-
|
|
175
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
176
|
+
consola.info(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${response.id}`);
|
|
175
177
|
consola.success('Deployment created successfully.');
|
|
176
178
|
// Wait for deployment job to complete by default, unless --detached flag is set
|
|
177
179
|
const shouldWait = !options.detached && build.platform !== 'web';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_API_BASE_URL } from '../../../config/consts.js';
|
|
2
2
|
import authorizationService from '../../../services/authorization-service.js';
|
|
3
|
+
import configService from '../../../services/config.js';
|
|
3
4
|
import userConfig from '../../../utils/user-config.js';
|
|
4
5
|
import consola from 'consola';
|
|
5
6
|
import nock from 'nock';
|
|
@@ -62,6 +63,22 @@ describe('apps-deployments-create', () => {
|
|
|
62
63
|
expect(deploymentScope.isDone()).toBe(true);
|
|
63
64
|
expect(mockConsola.success).toHaveBeenCalledWith('Deployment created successfully.');
|
|
64
65
|
});
|
|
66
|
+
it('should print the deployment url using the configured console base url', async () => {
|
|
67
|
+
const consoleBaseUrl = 'https://console.example.com';
|
|
68
|
+
const getValueForKey = configService.getValueForKey.bind(configService);
|
|
69
|
+
vi.spyOn(configService, 'getValueForKey').mockImplementation((key) => key === 'CONSOLE_BASE_URL' ? Promise.resolve(consoleBaseUrl) : getValueForKey(key));
|
|
70
|
+
const options = { appId, buildId, destination: 'Google Play', detached: true };
|
|
71
|
+
nock(DEFAULT_API_BASE_URL)
|
|
72
|
+
.get(`/v1/apps/${appId}/builds/${buildId}`)
|
|
73
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
74
|
+
.reply(200, { id: buildId, platform: 'android' });
|
|
75
|
+
nock(DEFAULT_API_BASE_URL)
|
|
76
|
+
.post(`/v1/apps/${appId}/deployments`)
|
|
77
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
78
|
+
.reply(201, { id: deploymentId, jobId: 'job-1' });
|
|
79
|
+
await createCommand.action(options, undefined);
|
|
80
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${deploymentId}`);
|
|
81
|
+
});
|
|
65
82
|
it('should reject translated release notes without a default text', async () => {
|
|
66
83
|
const options = { appId, buildId, destination: 'Google Play', releaseNotesLocale: ['de-DE=Fehlerbehebungen'] };
|
|
67
84
|
await expect(createCommand.action(options, undefined)).rejects.toThrow('Process exited with code 1');
|
|
@@ -3,7 +3,7 @@ import appDestinationsService from '../../../services/app-destinations.js';
|
|
|
3
3
|
import appGoogleServiceAccountKeysService from '../../../services/app-google-service-account-keys.js';
|
|
4
4
|
import appsService from '../../../services/apps.js';
|
|
5
5
|
import { withAuth } from '../../../utils/auth.js';
|
|
6
|
-
import { parseListOption } from '../../../utils/cli-options.js';
|
|
6
|
+
import { parseListOption, stringOption } from '../../../utils/cli-options.js';
|
|
7
7
|
import { isInteractive } from '../../../utils/environment.js';
|
|
8
8
|
import { isReadable } from '../../../utils/file.js';
|
|
9
9
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
@@ -74,10 +74,7 @@ export default defineCommand({
|
|
|
74
74
|
.string()
|
|
75
75
|
.optional()
|
|
76
76
|
.describe('Huawei AppGallery Connect API client secret for the destination.'),
|
|
77
|
-
defaultLanguage:
|
|
78
|
-
.string()
|
|
79
|
-
.optional()
|
|
80
|
-
.describe('Language of the default release notes text, e.g. `en-US` (Google Play and Huawei AppGallery only).'),
|
|
77
|
+
defaultLanguage: stringOption.describe('Language of the default release notes text, e.g. `en-US` (Google Play and Huawei AppGallery only).'),
|
|
81
78
|
})),
|
|
82
79
|
action: withAuth(async (options, args) => {
|
|
83
80
|
let { appId, json, name, platform, type, appleId, appleAppId, appleTeamId, appleAppPassword, appleApiKeyFile, appleIssuerId, appleBetaGroup, appleSubmitForReview, appleReleaseType, appleRejectIfPossible, androidPackageName, androidBuildArtifactType, androidReleaseStatus, googleServiceAccountKeyFile, googlePlayTrack, firebaseAppId, firebaseTesterGroup, huaweiAppId, huaweiClientId, huaweiClientSecret, defaultLanguage, } = options;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import appDestinationsService from '../../../services/app-destinations.js';
|
|
2
2
|
import { withAuth } from '../../../utils/auth.js';
|
|
3
|
-
import {
|
|
3
|
+
import { clearableStringOption, parseListOption } from '../../../utils/cli-options.js';
|
|
4
4
|
import { isInteractive } from '../../../utils/environment.js';
|
|
5
5
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
6
6
|
import consola from 'consola';
|
|
@@ -61,10 +61,7 @@ export default defineCommand({
|
|
|
61
61
|
.string()
|
|
62
62
|
.optional()
|
|
63
63
|
.describe('Huawei AppGallery Connect API client secret for the destination.'),
|
|
64
|
-
defaultLanguage:
|
|
65
|
-
.string()
|
|
66
|
-
.optional()
|
|
67
|
-
.describe('Language of the default release notes text, e.g. `en-US` (Google Play and Huawei AppGallery only). Pass `--default-language=` to clear it.'),
|
|
64
|
+
defaultLanguage: clearableStringOption.describe('Language of the default release notes text, e.g. `en-US` (Google Play and Huawei AppGallery only). Pass `--default-language=` to clear it.'),
|
|
68
65
|
})),
|
|
69
66
|
action: withAuth(async (options, args) => {
|
|
70
67
|
let { appId, destinationId, name, appleId, appleAppId, appleTeamId, appleAppPassword, appleApiKeyId, appleIssuerId, appAppleApiKeyId, appleBetaGroup, appleSubmitForReview, appleReleaseType, appleRejectIfPossible, androidPackageName, androidBuildArtifactType, androidReleaseStatus, appGoogleServiceAccountKeyId, googlePlayTrack, firebaseAppId, firebaseTesterGroup, huaweiAppId, huaweiClientId, huaweiClientSecret, defaultLanguage, } = options;
|
|
@@ -108,7 +105,7 @@ export default defineCommand({
|
|
|
108
105
|
huaweiAppId,
|
|
109
106
|
huaweiClientId,
|
|
110
107
|
huaweiClientSecret,
|
|
111
|
-
defaultLanguage
|
|
108
|
+
defaultLanguage,
|
|
112
109
|
});
|
|
113
110
|
consola.success('Destination updated successfully.');
|
|
114
111
|
}),
|
|
@@ -92,7 +92,7 @@ describe('apps-destinations-update', () => {
|
|
|
92
92
|
expect(scope.isDone()).toBe(true);
|
|
93
93
|
});
|
|
94
94
|
it('should clear the default language when `--default-language=` is passed', async () => {
|
|
95
|
-
const options = { appId, destinationId, defaultLanguage: '' };
|
|
95
|
+
const options = updateDestinationCommand.options.schema.parse({ appId, destinationId, defaultLanguage: '' });
|
|
96
96
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
97
97
|
.patch(`/v1/apps/${appId}/destinations/${destinationId}`, { appId, destinationId, defaultLanguage: null })
|
|
98
98
|
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../config/consts.js';
|
|
2
1
|
import appAutomationsService from '../../services/app-automations.js';
|
|
3
2
|
import appCertificatesService from '../../services/app-certificates.js';
|
|
4
3
|
import appChannelsService from '../../services/app-channels.js';
|
|
@@ -8,6 +7,7 @@ import appEnvironmentsService from '../../services/app-environments.js';
|
|
|
8
7
|
import appGoogleServiceAccountKeysService from '../../services/app-google-service-account-keys.js';
|
|
9
8
|
import appProvisioningProfilesService from '../../services/app-provisioning-profiles.js';
|
|
10
9
|
import appsService from '../../services/apps.js';
|
|
10
|
+
import configService from '../../services/config.js';
|
|
11
11
|
import gitConnectionsService from '../../services/git-connections.js';
|
|
12
12
|
import { generateUniqueName, isNameTaken } from '../../utils/app-import.js';
|
|
13
13
|
import { parseAppflowExport } from '../../utils/appflow-export.js';
|
|
@@ -103,12 +103,13 @@ export default defineCommand({
|
|
|
103
103
|
selectedSkippedApps.push(...unresolvedApps);
|
|
104
104
|
await assignUniqueAppNames(resolvedApps, organizationId);
|
|
105
105
|
const gitConnectionIds = await findGitConnectionIds(resolvedApps, organizationId);
|
|
106
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
106
107
|
for (const provider of getGitProviders(resolvedApps)) {
|
|
107
108
|
if (gitConnectionIds.has(provider)) {
|
|
108
109
|
continue;
|
|
109
110
|
}
|
|
110
111
|
const appCount = resolvedApps.filter((app) => app.repository?.provider === provider).length;
|
|
111
|
-
consola.warn(`The organization has no \`${provider}\` git connection, so the repositories of ${appCount} app(s) will not be linked. Connect the git provider at ${
|
|
112
|
+
consola.warn(`The organization has no \`${provider}\` git connection, so the repositories of ${appCount} app(s) will not be linked. Connect the git provider at ${consoleBaseUrl}/organizations/${organizationId}/git before running the import to link them automatically, or link the repositories manually in the Capawesome Cloud Console afterwards.`);
|
|
112
113
|
}
|
|
113
114
|
const outcomes = [];
|
|
114
115
|
for (const app of resolvedApps) {
|
|
@@ -132,10 +133,10 @@ export default defineCommand({
|
|
|
132
133
|
}
|
|
133
134
|
const errorCount = outcomes.reduce((count, outcome) => count + outcome.errors.length, 0);
|
|
134
135
|
if (json) {
|
|
135
|
-
printJsonSummary(outcomes, selectedSkippedApps, warnings, dryRun === true);
|
|
136
|
+
printJsonSummary(outcomes, selectedSkippedApps, warnings, dryRun === true, consoleBaseUrl);
|
|
136
137
|
}
|
|
137
138
|
else {
|
|
138
|
-
printSummary(outcomes, selectedSkippedApps, dryRun === true, file);
|
|
139
|
+
printSummary(outcomes, selectedSkippedApps, dryRun === true, file, consoleBaseUrl);
|
|
139
140
|
}
|
|
140
141
|
if (errorCount > 0) {
|
|
141
142
|
process.exitCode = 1;
|
|
@@ -444,7 +445,7 @@ const importApp = async (organizationId, outcome, gitConnectionIds) => {
|
|
|
444
445
|
}
|
|
445
446
|
}
|
|
446
447
|
};
|
|
447
|
-
const printSummary = (outcomes, skippedApps, dryRun, file) => {
|
|
448
|
+
const printSummary = (outcomes, skippedApps, dryRun, file, consoleBaseUrl) => {
|
|
448
449
|
consola.log('');
|
|
449
450
|
if (dryRun) {
|
|
450
451
|
consola.info('Dry run. No resources were created.');
|
|
@@ -477,7 +478,7 @@ const printSummary = (outcomes, skippedApps, dryRun, file) => {
|
|
|
477
478
|
}
|
|
478
479
|
for (const outcome of outcomes) {
|
|
479
480
|
if (outcome.id) {
|
|
480
|
-
consola.info(`App URL: ${
|
|
481
|
+
consola.info(`App URL: ${consoleBaseUrl}/apps/${outcome.id}`);
|
|
481
482
|
}
|
|
482
483
|
}
|
|
483
484
|
const retryLaterApps = skippedApps.filter((app) => app.retryLater);
|
|
@@ -498,7 +499,7 @@ const printSummary = (outcomes, skippedApps, dryRun, file) => {
|
|
|
498
499
|
const formatCount = (created, total, dryRun) => {
|
|
499
500
|
return dryRun ? `${total}` : `${created}/${total}`;
|
|
500
501
|
};
|
|
501
|
-
const printJsonSummary = (outcomes, skippedApps, warnings, dryRun) => {
|
|
502
|
+
const printJsonSummary = (outcomes, skippedApps, warnings, dryRun, consoleBaseUrl) => {
|
|
502
503
|
console.log(JSON.stringify({
|
|
503
504
|
dryRun,
|
|
504
505
|
warnings,
|
|
@@ -507,7 +508,7 @@ const printJsonSummary = (outcomes, skippedApps, warnings, dryRun) => {
|
|
|
507
508
|
name: outcome.app.name,
|
|
508
509
|
sourceId: outcome.app.sourceId,
|
|
509
510
|
sourceName: outcome.app.sourceName,
|
|
510
|
-
webUrl: outcome.id ? `${
|
|
511
|
+
webUrl: outcome.id ? `${consoleBaseUrl}/apps/${outcome.id}` : null,
|
|
511
512
|
created: outcome.created,
|
|
512
513
|
notes: outcome.app.notes,
|
|
513
514
|
renames: outcome.app.renames,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../config/consts.js';
|
|
2
1
|
import appsService from '../../services/apps.js';
|
|
2
|
+
import configService from '../../services/config.js';
|
|
3
3
|
import gitConnectionsService from '../../services/git-connections.js';
|
|
4
4
|
import { withAuth } from '../../utils/auth.js';
|
|
5
5
|
import { isInteractive } from '../../utils/environment.js';
|
|
@@ -37,7 +37,8 @@ export default defineCommand({
|
|
|
37
37
|
limit: 1,
|
|
38
38
|
});
|
|
39
39
|
if (!gitConnection) {
|
|
40
|
-
|
|
40
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
41
|
+
consola.error(`No \`${gitRemoteInfo.provider}\` git connection found in the organization. Connect the git provider first at ${consoleBaseUrl}/organizations/${app.organizationId}/git.`);
|
|
41
42
|
process.exit(1);
|
|
42
43
|
}
|
|
43
44
|
gitConnectionId = gitConnection.id;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
1
|
import appBuildSourcesService from '../../../services/app-build-sources.js';
|
|
3
2
|
import appBuildsService from '../../../services/app-builds.js';
|
|
4
3
|
import appCertificatesService from '../../../services/app-certificates.js';
|
|
5
4
|
import appDeploymentsService from '../../../services/app-deployments.js';
|
|
6
5
|
import appEnvironmentsService from '../../../services/app-environments.js';
|
|
6
|
+
import configService from '../../../services/config.js';
|
|
7
7
|
import { parseKeyValuePairs } from '../../../utils/app-environments.js';
|
|
8
8
|
import { withAuth } from '../../../utils/auth.js';
|
|
9
|
+
import { parseListOption, stringOption } from '../../../utils/cli-options.js';
|
|
9
10
|
import { parseCustomProperties } from '../../../utils/custom-properties.js';
|
|
10
11
|
import { isInteractive } from '../../../utils/environment.js';
|
|
11
12
|
import { isReadable } from '../../../utils/file.js';
|
|
@@ -29,17 +30,17 @@ export default defineCommand({
|
|
|
29
30
|
})
|
|
30
31
|
.optional()
|
|
31
32
|
.describe('App ID to create the live update for.'),
|
|
32
|
-
certificate:
|
|
33
|
+
certificate: stringOption.describe('The name of the certificate to use for the build.'),
|
|
33
34
|
channel: z
|
|
34
35
|
.array(z.string())
|
|
35
36
|
.optional()
|
|
36
|
-
.describe('The name of the channel to deploy to. Can be specified multiple times.'),
|
|
37
|
+
.describe('The name of the channel to deploy to. Can be specified multiple times or comma-separated.'),
|
|
37
38
|
customProperty: z
|
|
38
39
|
.array(z.string().min(1).max(100))
|
|
39
40
|
.max(10)
|
|
40
41
|
.optional()
|
|
41
42
|
.describe('A custom property to assign to the build. Must be in the format `key=value`. Can be specified multiple times.'),
|
|
42
|
-
environment:
|
|
43
|
+
environment: stringOption.describe('The name of the environment to use for the build.'),
|
|
43
44
|
gitRef: z.string().optional().describe('The Git reference (branch, tag, or commit SHA) to build.'),
|
|
44
45
|
iosEq: z.string().optional().describe('The exact iOS CFBundleVersion for the live update.'),
|
|
45
46
|
iosMax: z.string().optional().describe('The maximum iOS CFBundleVersion for the live update.'),
|
|
@@ -71,7 +72,8 @@ export default defineCommand({
|
|
|
71
72
|
yes: z.boolean().optional().describe('Skip confirmation prompts.'),
|
|
72
73
|
}), { y: 'yes' }),
|
|
73
74
|
action: withAuth(async (options) => {
|
|
74
|
-
let { appId, certificate,
|
|
75
|
+
let { appId, certificate, gitRef, environment, json, stack, path: sourcePath, url } = options;
|
|
76
|
+
let channel = parseListOption(options.channel);
|
|
75
77
|
// Validate that path, url, and gitRef cannot be used together
|
|
76
78
|
if (sourcePath && gitRef) {
|
|
77
79
|
consola.error('The --path and --git-ref flags cannot be used together.');
|
|
@@ -241,7 +243,8 @@ export default defineCommand({
|
|
|
241
243
|
});
|
|
242
244
|
consola.info(`Build ID: ${response.id}`);
|
|
243
245
|
consola.info(`Build Number: ${response.numberAsString}`);
|
|
244
|
-
|
|
246
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
247
|
+
consola.info(`Build URL: ${consoleBaseUrl}/apps/${appId}/builds/${response.id}`);
|
|
245
248
|
consola.success('Build created successfully.');
|
|
246
249
|
// Wait for build to complete
|
|
247
250
|
await waitForJobCompletion({ jobId: response.jobId });
|
|
@@ -284,7 +287,7 @@ export default defineCommand({
|
|
|
284
287
|
});
|
|
285
288
|
appDeploymentIds.push(deployment.id);
|
|
286
289
|
consola.info(`Deployment ID: ${deployment.id}`);
|
|
287
|
-
consola.info(`Deployment URL: ${
|
|
290
|
+
consola.info(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${deployment.id}`);
|
|
288
291
|
consola.success('Deployment created successfully.');
|
|
289
292
|
}
|
|
290
293
|
// Output JSON if json flag is set
|
|
@@ -3,6 +3,7 @@ import { promises as fs } from 'fs';
|
|
|
3
3
|
import pathModule from 'path';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { isInteractive } from '../../../utils/environment.js';
|
|
6
|
+
import { writeFile } from '../../../utils/file.js';
|
|
6
7
|
import { prompt } from '../../../utils/prompt.js';
|
|
7
8
|
import { defineCommand, defineOptions } from 'zodline';
|
|
8
9
|
const APP_TYPES = ['capacitor', 'cordova'];
|
|
@@ -54,8 +55,8 @@ export default defineCommand({
|
|
|
54
55
|
await fs.mkdir(pathModule.dirname(absolutePublicKeyPath), { recursive: true });
|
|
55
56
|
await fs.mkdir(pathModule.dirname(absolutePrivateKeyPath), { recursive: true });
|
|
56
57
|
// Write the keys to files
|
|
57
|
-
await
|
|
58
|
-
await
|
|
58
|
+
await writeFile(absolutePublicKeyPath, publicKey);
|
|
59
|
+
await writeFile(absolutePrivateKeyPath, privateKey);
|
|
59
60
|
consola.log('');
|
|
60
61
|
consola.log('Public key saved to: ' + absolutePublicKeyPath);
|
|
61
62
|
consola.log('Private key saved to: ' + absolutePrivateKeyPath);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
1
|
import appBundlesService from '../../../services/app-bundles.js';
|
|
3
2
|
import appsService from '../../../services/apps.js';
|
|
3
|
+
import configService from '../../../services/config.js';
|
|
4
4
|
import { withAuth } from '../../../utils/auth.js';
|
|
5
|
+
import { stringOption } from '../../../utils/cli-options.js';
|
|
5
6
|
import { parseCustomProperties } from '../../../utils/custom-properties.js';
|
|
6
7
|
import { createBufferFromPath, createBufferFromString, isPrivateKeyContent } from '../../../utils/buffer.js';
|
|
7
8
|
import { isInteractive } from '../../../utils/environment.js';
|
|
@@ -38,7 +39,7 @@ export default defineCommand({
|
|
|
38
39
|
})
|
|
39
40
|
.optional()
|
|
40
41
|
.describe('App ID to deploy to.'),
|
|
41
|
-
channel:
|
|
42
|
+
channel: stringOption.describe('Channel to associate the bundle with.'),
|
|
42
43
|
commitMessage: z
|
|
43
44
|
.string()
|
|
44
45
|
.optional()
|
|
@@ -56,6 +57,18 @@ export default defineCommand({
|
|
|
56
57
|
.max(10)
|
|
57
58
|
.optional()
|
|
58
59
|
.describe('A custom property to assign to the bundle. Must be in the format `key=value`. Can be specified multiple times.'),
|
|
60
|
+
electronMax: z
|
|
61
|
+
.string()
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('The maximum Electron app version (`app.getVersion()`, from `electron/package.json`) that the bundle supports. Must be in the format `major[.minor[.patch]]`. Prerelease suffixes are not supported.'),
|
|
64
|
+
electronMin: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe('The minimum Electron app version (`app.getVersion()`, from `electron/package.json`) that the bundle supports. Must be in the format `major[.minor[.patch]]`. Prerelease suffixes are not supported.'),
|
|
68
|
+
electronEq: z
|
|
69
|
+
.string()
|
|
70
|
+
.optional()
|
|
71
|
+
.describe('The exact Electron app version (`app.getVersion()`, from `electron/package.json`) that the bundle does not support. Must be in the format `major[.minor[.patch]]`. Prerelease suffixes are not supported.'),
|
|
59
72
|
expiresInDays: z.coerce
|
|
60
73
|
.number({
|
|
61
74
|
message: 'Expiration days must be an integer.',
|
|
@@ -104,7 +117,7 @@ export default defineCommand({
|
|
|
104
117
|
yes: z.boolean().optional().describe('Skip confirmation prompts.'),
|
|
105
118
|
}), { y: 'yes' }),
|
|
106
119
|
action: withAuth(async (options, args) => {
|
|
107
|
-
let { androidEq, androidMax, androidMin, appId, channel, commitMessage, commitRef, commitSha, customProperty, expiresInDays, gitRef, iosEq, iosMax, iosMin, json, path, privateKey, rolloutPercentage, url, } = options;
|
|
120
|
+
let { androidEq, androidMax, androidMin, appId, channel, commitMessage, commitRef, commitSha, customProperty, electronEq, electronMax, electronMin, expiresInDays, gitRef, iosEq, iosMax, iosMin, json, path, privateKey, rolloutPercentage, url, } = options;
|
|
108
121
|
if (expiresInDays) {
|
|
109
122
|
consola.warn('The `--expires-in-days` option is deprecated and will be removed in a future version. Bundle expiration is now managed by the data retention policy of your organization billing plan.');
|
|
110
123
|
}
|
|
@@ -225,6 +238,7 @@ export default defineCommand({
|
|
|
225
238
|
channelName: channel,
|
|
226
239
|
checksum,
|
|
227
240
|
eqAndroidAppVersionCode: androidEq,
|
|
241
|
+
eqElectronAppVersionCode: electronEq,
|
|
228
242
|
eqIosAppVersionCode: iosEq,
|
|
229
243
|
gitCommitMessage: commitMessage,
|
|
230
244
|
gitCommitRef: commitRef,
|
|
@@ -233,15 +247,18 @@ export default defineCommand({
|
|
|
233
247
|
customProperties: parseCustomProperties(customProperty),
|
|
234
248
|
url,
|
|
235
249
|
maxAndroidAppVersionCode: androidMax,
|
|
250
|
+
maxElectronAppVersionCode: electronMax,
|
|
236
251
|
maxIosAppVersionCode: iosMax,
|
|
237
252
|
minAndroidAppVersionCode: androidMin,
|
|
253
|
+
minElectronAppVersionCode: electronMin,
|
|
238
254
|
minIosAppVersionCode: iosMin,
|
|
239
255
|
rolloutPercentage: (rolloutPercentage ?? 100) / 100,
|
|
240
256
|
signature,
|
|
241
257
|
});
|
|
242
258
|
consola.info(`Bundle Artifact ID: ${response.id}`);
|
|
243
259
|
if (response.appDeploymentId) {
|
|
244
|
-
|
|
260
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
261
|
+
consola.info(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${response.appDeploymentId}`);
|
|
245
262
|
}
|
|
246
263
|
consola.success('Live Update successfully registered.');
|
|
247
264
|
if (json) {
|
|
@@ -134,6 +134,45 @@ describe('apps-liveupdates-register', () => {
|
|
|
134
134
|
expect(mockConsola.info).toHaveBeenCalledWith(`Bundle Artifact ID: ${bundleId}`);
|
|
135
135
|
expect(mockConsola.success).toHaveBeenCalledWith('Live Update successfully registered.');
|
|
136
136
|
});
|
|
137
|
+
it('should pass Electron version constraints to API when provided', async () => {
|
|
138
|
+
const appId = 'app-123';
|
|
139
|
+
const bundleUrl = 'https://example.com/bundle.zip';
|
|
140
|
+
const bundleId = 'bundle-456';
|
|
141
|
+
const testToken = 'test-token';
|
|
142
|
+
const electronEq = '1.0.0';
|
|
143
|
+
const electronMin = '2.0.0';
|
|
144
|
+
const electronMax = '3.0.0';
|
|
145
|
+
const options = {
|
|
146
|
+
appId,
|
|
147
|
+
url: bundleUrl,
|
|
148
|
+
rolloutPercentage: 1,
|
|
149
|
+
electronEq,
|
|
150
|
+
electronMin,
|
|
151
|
+
electronMax,
|
|
152
|
+
yes: true,
|
|
153
|
+
};
|
|
154
|
+
const appScope = nock(DEFAULT_API_BASE_URL)
|
|
155
|
+
.get(`/v1/apps/${appId}`)
|
|
156
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
157
|
+
.reply(200, { id: appId, name: 'Test App' });
|
|
158
|
+
const bundleScope = nock(DEFAULT_API_BASE_URL)
|
|
159
|
+
.post(`/v1/apps/${appId}/bundles`, {
|
|
160
|
+
appId,
|
|
161
|
+
url: bundleUrl,
|
|
162
|
+
artifactType: 'zip',
|
|
163
|
+
eqElectronAppVersionCode: electronEq,
|
|
164
|
+
minElectronAppVersionCode: electronMin,
|
|
165
|
+
maxElectronAppVersionCode: electronMax,
|
|
166
|
+
rolloutPercentage: 0.01,
|
|
167
|
+
})
|
|
168
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
169
|
+
.reply(201, { id: bundleId, appBuildId: 'build-789' });
|
|
170
|
+
await registerCommand.action(options, undefined);
|
|
171
|
+
expect(appScope.isDone()).toBe(true);
|
|
172
|
+
expect(bundleScope.isDone()).toBe(true);
|
|
173
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Bundle Artifact ID: ${bundleId}`);
|
|
174
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Live Update successfully registered.');
|
|
175
|
+
});
|
|
137
176
|
it('should register bundle with checksum when path is provided', async () => {
|
|
138
177
|
const appId = 'app-123';
|
|
139
178
|
const bundleUrl = 'https://example.com/bundle.zip';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
1
|
import appChannelsService from '../../../services/app-channels.js';
|
|
3
2
|
import appDeploymentsService from '../../../services/app-deployments.js';
|
|
3
|
+
import configService from '../../../services/config.js';
|
|
4
4
|
import { withAuth } from '../../../utils/auth.js';
|
|
5
5
|
import { isInteractive } from '../../../utils/environment.js';
|
|
6
6
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
@@ -130,7 +130,8 @@ export default defineCommand({
|
|
|
130
130
|
appChannelName: channel,
|
|
131
131
|
});
|
|
132
132
|
consola.info(`Deployment ID: ${response.id}`);
|
|
133
|
-
|
|
133
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
134
|
+
consola.info(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${response.id}`);
|
|
134
135
|
consola.success(`Rolled back to Build #${selectedAppDeployment.appBuild?.numberAsString} (${selectedIndex} step${selectedIndex === 1 ? '' : 's'} back).`);
|
|
135
136
|
}),
|
|
136
137
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DEFAULT_CONSOLE_BASE_URL } from '../../../config/consts.js';
|
|
2
1
|
import appChannelsService from '../../../services/app-channels.js';
|
|
3
2
|
import appDeploymentsService from '../../../services/app-deployments.js';
|
|
3
|
+
import configService from '../../../services/config.js';
|
|
4
4
|
import { withAuth } from '../../../utils/auth.js';
|
|
5
5
|
import { isInteractive } from '../../../utils/environment.js';
|
|
6
6
|
import { prompt, promptAppSelection, promptOrganizationSelection } from '../../../utils/prompt.js';
|
|
@@ -106,7 +106,8 @@ export default defineCommand({
|
|
|
106
106
|
rolloutPercentage: percentage / 100,
|
|
107
107
|
});
|
|
108
108
|
consola.info(`Deployment ID: ${response.id}`);
|
|
109
|
-
|
|
109
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
110
|
+
consola.info(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${response.id}`);
|
|
110
111
|
consola.success(`Rolled out to ${percentage}%.`);
|
|
111
112
|
}),
|
|
112
113
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MAX_CONCURRENT_FILE_UPLOADS } from '../../../config/index.js';
|
|
2
2
|
import appBundleFilesService from '../../../services/app-bundle-files.js';
|
|
3
3
|
import appBundlesService from '../../../services/app-bundles.js';
|
|
4
4
|
import appsService from '../../../services/apps.js';
|
|
5
|
+
import configService from '../../../services/config.js';
|
|
5
6
|
import { withAuth } from '../../../utils/auth.js';
|
|
7
|
+
import { stringOption } from '../../../utils/cli-options.js';
|
|
6
8
|
import { parseCustomProperties } from '../../../utils/custom-properties.js';
|
|
7
9
|
import { defineCommand, defineOptions } from 'zodline';
|
|
8
10
|
import { createBufferFromPath, createBufferFromReadStream, createBufferFromString, isPrivateKeyContent, } from '../../../utils/buffer.js';
|
|
@@ -49,7 +51,7 @@ export default defineCommand({
|
|
|
49
51
|
.optional()
|
|
50
52
|
.describe('The type of artifact to deploy. Must be either `manifest` or `zip`. The default is `zip`.')
|
|
51
53
|
.default('zip'),
|
|
52
|
-
channel:
|
|
54
|
+
channel: stringOption.describe('Channel to associate the bundle with.'),
|
|
53
55
|
commitMessage: z
|
|
54
56
|
.string()
|
|
55
57
|
.optional()
|
|
@@ -67,6 +69,18 @@ export default defineCommand({
|
|
|
67
69
|
.max(10)
|
|
68
70
|
.optional()
|
|
69
71
|
.describe('A custom property to assign to the bundle. Must be in the format `key=value`. Can be specified multiple times.'),
|
|
72
|
+
electronMax: z
|
|
73
|
+
.string()
|
|
74
|
+
.optional()
|
|
75
|
+
.describe('The maximum Electron app version (`app.getVersion()`, from `electron/package.json`) that the bundle supports. Must be in the format `major[.minor[.patch]]`. Prerelease suffixes are not supported.'),
|
|
76
|
+
electronMin: z
|
|
77
|
+
.string()
|
|
78
|
+
.optional()
|
|
79
|
+
.describe('The minimum Electron app version (`app.getVersion()`, from `electron/package.json`) that the bundle supports. Must be in the format `major[.minor[.patch]]`. Prerelease suffixes are not supported.'),
|
|
80
|
+
electronEq: z
|
|
81
|
+
.string()
|
|
82
|
+
.optional()
|
|
83
|
+
.describe('The exact Electron app version (`app.getVersion()`, from `electron/package.json`) that the bundle does not support. Must be in the format `major[.minor[.patch]]`. Prerelease suffixes are not supported.'),
|
|
70
84
|
expiresInDays: z.coerce
|
|
71
85
|
.number({
|
|
72
86
|
message: 'Expiration days must be an integer.',
|
|
@@ -117,7 +131,7 @@ export default defineCommand({
|
|
|
117
131
|
yes: z.boolean().optional().describe('Skip confirmation prompt.'),
|
|
118
132
|
}), { y: 'yes' }),
|
|
119
133
|
action: withAuth(async (options, args) => {
|
|
120
|
-
let { androidEq, androidMax, androidMin, appId, artifactType, channel, commitMessage, commitRef, commitSha, customProperty, expiresInDays, gitRef, iosEq, iosMax, iosMin, json, path, privateKey, rolloutPercentage, } = options;
|
|
134
|
+
let { androidEq, androidMax, androidMin, appId, artifactType, channel, commitMessage, commitRef, commitSha, customProperty, electronEq, electronMax, electronMin, expiresInDays, gitRef, iosEq, iosMax, iosMin, json, path, privateKey, rolloutPercentage, } = options;
|
|
121
135
|
if (expiresInDays) {
|
|
122
136
|
consola.warn('The `--expires-in-days` option is deprecated and will be removed in a future version. Bundle expiration is now managed by the data retention policy of your organization billing plan.');
|
|
123
137
|
}
|
|
@@ -255,6 +269,7 @@ export default defineCommand({
|
|
|
255
269
|
artifactType,
|
|
256
270
|
channelName: channel,
|
|
257
271
|
eqAndroidAppVersionCode: androidEq,
|
|
272
|
+
eqElectronAppVersionCode: electronEq,
|
|
258
273
|
eqIosAppVersionCode: iosEq,
|
|
259
274
|
gitCommitMessage: commitMessage,
|
|
260
275
|
gitCommitRef: commitRef,
|
|
@@ -262,8 +277,10 @@ export default defineCommand({
|
|
|
262
277
|
gitRef,
|
|
263
278
|
customProperties: parseCustomProperties(customProperty),
|
|
264
279
|
maxAndroidAppVersionCode: androidMax,
|
|
280
|
+
maxElectronAppVersionCode: electronMax,
|
|
265
281
|
maxIosAppVersionCode: iosMax,
|
|
266
282
|
minAndroidAppVersionCode: androidMin,
|
|
283
|
+
minElectronAppVersionCode: electronMin,
|
|
267
284
|
minIosAppVersionCode: iosMin,
|
|
268
285
|
// Convert percentage from 0-100 to 0-1 for API
|
|
269
286
|
rolloutPercentage: (rolloutPercentage ?? 100) / 100,
|
|
@@ -287,7 +304,8 @@ export default defineCommand({
|
|
|
287
304
|
});
|
|
288
305
|
consola.info(`Build Artifact ID: ${createBundleResponse.id}`);
|
|
289
306
|
if (updateBundleResponse.appDeploymentId) {
|
|
290
|
-
|
|
307
|
+
const consoleBaseUrl = await configService.getValueForKey('CONSOLE_BASE_URL');
|
|
308
|
+
consola.info(`Deployment URL: ${consoleBaseUrl}/apps/${appId}/deployments/${updateBundleResponse.appDeploymentId}`);
|
|
291
309
|
}
|
|
292
310
|
consola.success('Live Update successfully uploaded.');
|
|
293
311
|
if (json) {
|
|
@@ -211,6 +211,66 @@ describe('apps-liveupdates-upload', () => {
|
|
|
211
211
|
expect(mockConsola.info).toHaveBeenCalledWith(`Build Artifact ID: ${bundleId}`);
|
|
212
212
|
expect(mockConsola.success).toHaveBeenCalledWith('Live Update successfully uploaded.');
|
|
213
213
|
});
|
|
214
|
+
it('should pass Electron version constraints to API when provided', async () => {
|
|
215
|
+
const appId = 'app-123';
|
|
216
|
+
const bundlePath = './dist';
|
|
217
|
+
const bundleId = 'bundle-456';
|
|
218
|
+
const testToken = 'test-token';
|
|
219
|
+
const testBuffer = Buffer.from('test');
|
|
220
|
+
const electronEq = '1.0.0';
|
|
221
|
+
const electronMin = '2.0.0';
|
|
222
|
+
const electronMax = '3.0.0';
|
|
223
|
+
const options = {
|
|
224
|
+
appId,
|
|
225
|
+
path: bundlePath,
|
|
226
|
+
artifactType: 'zip',
|
|
227
|
+
rollout: 1,
|
|
228
|
+
electronEq,
|
|
229
|
+
electronMin,
|
|
230
|
+
electronMax,
|
|
231
|
+
};
|
|
232
|
+
mockIsReadable.mockResolvedValue(true);
|
|
233
|
+
mockIsDirectory.mockResolvedValue(true);
|
|
234
|
+
mockGetFilesInDirectoryAndSubdirectories.mockResolvedValue([
|
|
235
|
+
{ href: 'index.html', mimeType: 'text/html', name: 'index.html', path: 'index.html' },
|
|
236
|
+
]);
|
|
237
|
+
// Mock utility functions
|
|
238
|
+
const mockZip = await import('../../../utils/zip.js');
|
|
239
|
+
const mockHash = await import('../../../utils/hash.js');
|
|
240
|
+
vi.mocked(mockZip.default.isZipped).mockReturnValue(false);
|
|
241
|
+
vi.mocked(mockZip.default.zipFolder).mockResolvedValue(testBuffer);
|
|
242
|
+
vi.mocked(mockHash.createHash).mockResolvedValue('test-hash');
|
|
243
|
+
const appScope = nock(DEFAULT_API_BASE_URL)
|
|
244
|
+
.get(`/v1/apps/${appId}`)
|
|
245
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
246
|
+
.reply(200, { id: appId, name: 'Test App' });
|
|
247
|
+
const bundleScope = nock(DEFAULT_API_BASE_URL)
|
|
248
|
+
.post(`/v1/apps/${appId}/bundles`, {
|
|
249
|
+
appId,
|
|
250
|
+
artifactType: 'zip',
|
|
251
|
+
eqElectronAppVersionCode: electronEq,
|
|
252
|
+
minElectronAppVersionCode: electronMin,
|
|
253
|
+
maxElectronAppVersionCode: electronMax,
|
|
254
|
+
rolloutPercentage: 1,
|
|
255
|
+
})
|
|
256
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
257
|
+
.reply(201, { id: bundleId, appBuildId: 'build-789' });
|
|
258
|
+
const uploadScope = nock(DEFAULT_API_BASE_URL)
|
|
259
|
+
.post(`/v1/apps/${appId}/bundles/${bundleId}/files`)
|
|
260
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
261
|
+
.reply(201, { id: 'file-123' });
|
|
262
|
+
const updateScope = nock(DEFAULT_API_BASE_URL)
|
|
263
|
+
.patch(`/v1/apps/${appId}/bundles/${bundleId}`)
|
|
264
|
+
.matchHeader('Authorization', `Bearer ${testToken}`)
|
|
265
|
+
.reply(200, { id: bundleId });
|
|
266
|
+
await uploadCommand.action(options, undefined);
|
|
267
|
+
expect(appScope.isDone()).toBe(true);
|
|
268
|
+
expect(bundleScope.isDone()).toBe(true);
|
|
269
|
+
expect(uploadScope.isDone()).toBe(true);
|
|
270
|
+
expect(updateScope.isDone()).toBe(true);
|
|
271
|
+
expect(mockConsola.info).toHaveBeenCalledWith(`Build Artifact ID: ${bundleId}`);
|
|
272
|
+
expect(mockConsola.success).toHaveBeenCalledWith('Live Update successfully uploaded.');
|
|
273
|
+
});
|
|
214
274
|
it('should output JSON when json flag is set', async () => {
|
|
215
275
|
const appId = 'app-123';
|
|
216
276
|
const bundlePath = './dist';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import appsService from '../../services/apps.js';
|
|
2
2
|
import { withAuth } from '../../utils/auth.js';
|
|
3
|
-
import { clearableValue } from '../../utils/cli-options.js';
|
|
3
|
+
import { clearableStringOption, clearableValue } from '../../utils/cli-options.js';
|
|
4
4
|
import { isInteractive } from '../../utils/environment.js';
|
|
5
5
|
import { promptAppSelection, promptOrganizationSelection } from '../../utils/prompt.js';
|
|
6
6
|
import consola from 'consola';
|
|
@@ -10,24 +10,15 @@ export default defineCommand({
|
|
|
10
10
|
description: 'Update an existing app.',
|
|
11
11
|
options: defineOptions(z.object({
|
|
12
12
|
appId: z.string().optional().describe('ID of the app.'),
|
|
13
|
-
channel:
|
|
14
|
-
.string()
|
|
15
|
-
.optional()
|
|
16
|
-
.describe('The name of the default channel for live updates. Pass an empty string to clear it.'),
|
|
13
|
+
channel: clearableStringOption.describe('The name of the default channel for live updates. Pass an empty string to clear it.'),
|
|
17
14
|
channelDiscovery: z
|
|
18
15
|
.union([z.boolean(), z.stringbool()], {
|
|
19
16
|
message: 'Channel discovery must be either `true` or `false`.',
|
|
20
17
|
})
|
|
21
18
|
.optional()
|
|
22
19
|
.describe('Enable or disable channel discovery. Supported values are `true` and `false`.'),
|
|
23
|
-
configuration:
|
|
24
|
-
|
|
25
|
-
.optional()
|
|
26
|
-
.describe('The name of the default native configuration. Pass an empty string to clear it.'),
|
|
27
|
-
environment: z
|
|
28
|
-
.string()
|
|
29
|
-
.optional()
|
|
30
|
-
.describe('The name of the default environment. Pass an empty string to clear it.'),
|
|
20
|
+
configuration: clearableStringOption.describe('The name of the default native configuration. Pass an empty string to clear it.'),
|
|
21
|
+
environment: clearableStringOption.describe('The name of the default environment. Pass an empty string to clear it.'),
|
|
31
22
|
json: z.boolean().optional().describe('Output in JSON format.'),
|
|
32
23
|
name: z.string().optional().describe('Name of the app.'),
|
|
33
24
|
nextBuildNumber: z.coerce
|
|
@@ -60,9 +51,9 @@ export default defineCommand({
|
|
|
60
51
|
}
|
|
61
52
|
const app = await appsService.update({
|
|
62
53
|
appChannelDiscoveryEnabled: options.channelDiscovery,
|
|
63
|
-
appChannelName:
|
|
64
|
-
appConfigurationName:
|
|
65
|
-
appEnvironmentName:
|
|
54
|
+
appChannelName: options.channel,
|
|
55
|
+
appConfigurationName: options.configuration,
|
|
56
|
+
appEnvironmentName: options.environment,
|
|
66
57
|
appId,
|
|
67
58
|
buildStack: clearableValue(options.stack),
|
|
68
59
|
name: options.name,
|
|
@@ -61,7 +61,7 @@ describe('apps-update', () => {
|
|
|
61
61
|
});
|
|
62
62
|
it('should clear defaults when an empty string is passed', async () => {
|
|
63
63
|
const appId = 'app-123';
|
|
64
|
-
const options = { appId, channel: '', environment: '', stack: '' };
|
|
64
|
+
const options = updateAppCommand.options.schema.parse({ appId, channel: '', environment: '', stack: '' });
|
|
65
65
|
const scope = nock(DEFAULT_API_BASE_URL)
|
|
66
66
|
.patch(`/v1/apps/${appId}`, {
|
|
67
67
|
appChannelName: null,
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const stringOption = z
|
|
3
|
+
.string()
|
|
4
|
+
.trim()
|
|
5
|
+
.transform((value) => value || undefined)
|
|
6
|
+
.optional();
|
|
7
|
+
export const clearableStringOption = z
|
|
8
|
+
.string()
|
|
9
|
+
.trim()
|
|
10
|
+
.transform((value) => value || null)
|
|
11
|
+
.optional();
|
|
1
12
|
export const clearableValue = (value) => value === '' ? null : value;
|
|
2
13
|
export const parseListOption = (values) => {
|
|
3
14
|
return values
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { parseListOption } from './cli-options.js';
|
|
2
|
+
import { clearableStringOption, parseListOption, stringOption } from './cli-options.js';
|
|
3
|
+
describe('stringOption', () => {
|
|
4
|
+
it('should return undefined if the option is not passed', () => {
|
|
5
|
+
expect(stringOption.parse(undefined)).toBeUndefined();
|
|
6
|
+
});
|
|
7
|
+
it('should return undefined for an empty value', () => {
|
|
8
|
+
expect(stringOption.parse('')).toBeUndefined();
|
|
9
|
+
});
|
|
10
|
+
it('should return undefined for a whitespace-only value', () => {
|
|
11
|
+
expect(stringOption.parse(' ')).toBeUndefined();
|
|
12
|
+
});
|
|
13
|
+
it('should trim the value', () => {
|
|
14
|
+
expect(stringOption.parse(' production ')).toBe('production');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('clearableStringOption', () => {
|
|
18
|
+
it('should return undefined if the option is not passed', () => {
|
|
19
|
+
expect(clearableStringOption.parse(undefined)).toBeUndefined();
|
|
20
|
+
});
|
|
21
|
+
it('should return null for an empty value', () => {
|
|
22
|
+
expect(clearableStringOption.parse('')).toBeNull();
|
|
23
|
+
});
|
|
24
|
+
it('should return null for a whitespace-only value', () => {
|
|
25
|
+
expect(clearableStringOption.parse(' ')).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
it('should trim the value', () => {
|
|
28
|
+
expect(clearableStringOption.parse(' production ')).toBe('production');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
3
31
|
describe('parseListOption', () => {
|
|
4
32
|
it('should return undefined if the option is not passed', () => {
|
|
5
33
|
expect(parseListOption(undefined)).toBeUndefined();
|
package/dist/utils/file.js
CHANGED
|
@@ -4,12 +4,13 @@ import pathModule from 'path';
|
|
|
4
4
|
import { createBufferFromPath } from './buffer.js';
|
|
5
5
|
import { getCodeFromUnknownError, UserError } from './error.js';
|
|
6
6
|
const concurrentModificationHint = 'Make sure that no other process (e.g. a build or file sync client) modifies the folder while the command is running.';
|
|
7
|
-
const
|
|
7
|
+
const readPermissionHint = 'Make sure that you have permission to read the file.';
|
|
8
|
+
const writePermissionHint = 'Make sure that you have permission to write to the folder or choose a different path.';
|
|
8
9
|
const unreadableFileErrorHints = {
|
|
9
|
-
EACCES:
|
|
10
|
+
EACCES: readPermissionHint,
|
|
10
11
|
EBUSY: concurrentModificationHint,
|
|
11
12
|
ENOENT: concurrentModificationHint,
|
|
12
|
-
EPERM:
|
|
13
|
+
EPERM: readPermissionHint,
|
|
13
14
|
};
|
|
14
15
|
export const getFilesInDirectoryAndSubdirectories = async (path) => {
|
|
15
16
|
const files = [];
|
|
@@ -95,14 +96,14 @@ export const isDirectory = async (path) => {
|
|
|
95
96
|
});
|
|
96
97
|
};
|
|
97
98
|
export const writeFile = async (path, data) => {
|
|
98
|
-
|
|
99
|
-
fs.writeFile(path, data
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
99
|
+
try {
|
|
100
|
+
await fs.promises.writeFile(path, data);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const code = getCodeFromUnknownError(error);
|
|
104
|
+
if (code === 'EACCES' || code === 'EPERM') {
|
|
105
|
+
throw new UserError(`The file could not be written: ${path}. ${writePermissionHint}`);
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
108
109
|
};
|
package/dist/utils/file.test.js
CHANGED
|
@@ -3,7 +3,7 @@ import os from 'os';
|
|
|
3
3
|
import pathModule from 'path';
|
|
4
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
import { UserError } from './error.js';
|
|
6
|
-
import { readFileFromDirectory } from './file.js';
|
|
6
|
+
import { readFileFromDirectory, writeFile } from './file.js';
|
|
7
7
|
const { mockCreateBufferFromPath } = vi.hoisted(() => ({ mockCreateBufferFromPath: vi.fn() }));
|
|
8
8
|
vi.mock('./buffer.js', async (importOriginal) => {
|
|
9
9
|
const actual = await importOriginal();
|
|
@@ -44,3 +44,30 @@ describe('readFileFromDirectory', () => {
|
|
|
44
44
|
await expect(readFileFromDirectory(pathModule.join(directory, 'assets'))).rejects.toBe(error);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
|
+
describe('writeFile', () => {
|
|
48
|
+
let directory;
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
directory = fs.mkdtempSync(pathModule.join(os.tmpdir(), 'file-'));
|
|
51
|
+
});
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
vi.restoreAllMocks();
|
|
54
|
+
fs.rmSync(directory, { force: true, recursive: true });
|
|
55
|
+
});
|
|
56
|
+
it('should write the file', async () => {
|
|
57
|
+
const path = pathModule.join(directory, 'public.pem');
|
|
58
|
+
await writeFile(path, 'key');
|
|
59
|
+
expect(fs.readFileSync(path, 'utf8')).toBe('key');
|
|
60
|
+
});
|
|
61
|
+
it.each(['EACCES', 'EPERM'])('should throw a user error if the file is not writable (%s)', async (code) => {
|
|
62
|
+
const path = pathModule.join(directory, 'public.pem');
|
|
63
|
+
vi.spyOn(fs.promises, 'writeFile').mockRejectedValueOnce(createErrorWithCode(code));
|
|
64
|
+
const promise = writeFile(path, 'key');
|
|
65
|
+
await expect(promise).rejects.toThrow(UserError);
|
|
66
|
+
await expect(promise).rejects.toThrow(`The file could not be written: ${path}. Make sure that you have permission to write to the folder or choose a different path.`);
|
|
67
|
+
});
|
|
68
|
+
it('should rethrow errors that are not related to permissions', async () => {
|
|
69
|
+
const error = createErrorWithCode('EISDIR');
|
|
70
|
+
vi.spyOn(fs.promises, 'writeFile').mockRejectedValueOnce(error);
|
|
71
|
+
await expect(writeFile(directory, 'key')).rejects.toBe(error);
|
|
72
|
+
});
|
|
73
|
+
});
|