Skip to content

Commit

Permalink
feat(apps): add new --expires-in-days option to apps:bundles:create
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Nov 1, 2024
1 parent 844acc4 commit 5e83d14
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
48 changes: 18 additions & 30 deletions src/commands/apps/bundles/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineCommand } from 'citty';
import consola from 'consola';
import FormData from 'form-data';
import { createReadStream } from 'fs';
import appBundleFilesService from '../../../services/app-bundle-files';
import appBundlesService from '../../../services/app-bundles';
Expand Down Expand Up @@ -41,6 +40,10 @@ export default defineCommand({
type: 'string',
description: 'Channel to associate the bundle with.',
},
expiresInDays: {
type: 'string',
description: 'The number of days until the bundle is automatically deleted.',
},
iosMax: {
type: 'string',
description: 'The maximum iOS bundle version (`CFBundleVersion`) that the bundle supports.',
Expand Down Expand Up @@ -80,12 +83,25 @@ export default defineCommand({
? ctx.args.artifactType
: ('zip' as 'manifest' | 'zip');
let channelName = ctx.args.channel as string | undefined;
let expiresInDays = ctx.args.expiresInDays as string | undefined;
let iosMax = ctx.args.iosMax as string | undefined;
let iosMin = ctx.args.iosMin as string | undefined;
let path = ctx.args.path as string | undefined;
let privateKey = ctx.args.privateKey as string | undefined;
let rollout = ctx.args.rollout as string | undefined;
let url = ctx.args.url as string | undefined;
// Validate the expiration days
let expiresAt: string | undefined;
if (expiresInDays) {
const expiresInDaysAsNumber = parseInt(expiresInDays, 10);
if (isNaN(expiresInDaysAsNumber) || expiresInDaysAsNumber < 1) {
consola.error('Expires in days must be a number greater than 0.');
return;
}
const expiresAtDate = new Date();
expiresAtDate.setDate(expiresAtDate.getDate() + expiresInDaysAsNumber);
expiresAt = expiresAtDate.toISOString();
}
if (!path && !url) {
path = await prompt('Enter the path to the app bundle:', {
type: 'text',
Expand Down Expand Up @@ -155,35 +171,6 @@ export default defineCommand({
}
}

// Create form data
const formData = new FormData();
formData.append('artifactType', artifactType || 'zip');
if (url) {
formData.append('url', url);
}
if (channelName) {
formData.append('channelName', channelName);
}
if (androidMax) {
formData.append('maxAndroidAppVersionCode', androidMax);
}
if (androidMin) {
formData.append('minAndroidAppVersionCode', androidMin);
}
if (rollout) {
const rolloutAsNumber = parseFloat(rollout);
if (isNaN(rolloutAsNumber) || rolloutAsNumber < 0 || rolloutAsNumber > 1) {
consola.error('Rollout percentage must be a number between 0 and 1 (e.g. 0.5).');
return;
}
formData.append('rolloutPercentage', rolloutAsNumber);
}
if (iosMax) {
formData.append('maxIosAppVersionCode', iosMax);
}
if (iosMin) {
formData.append('minIosAppVersionCode', iosMin);
}
let appBundleId: string | undefined;
try {
// Create the app bundle
Expand All @@ -192,6 +179,7 @@ export default defineCommand({
appId,
artifactType,
channelName,
expiresAt: expiresAt,
url,
maxAndroidAppVersionCode: androidMax,
maxIosAppVersionCode: iosMax,
Expand Down
3 changes: 3 additions & 0 deletions src/services/app-bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class AppBundlesServiceImpl implements AppBundlesService {
if (dto.channelName) {
formData.append('channelName', dto.channelName);
}
if (dto.expiresAt) {
formData.append('expiresAt', dto.expiresAt);
}
if (dto.url) {
formData.append('url', dto.url);
}
Expand Down
1 change: 1 addition & 0 deletions src/types/app-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface CreateAppBundleDto {
appId: string;
artifactType: 'manifest' | 'zip';
channelName?: string;
expiresAt?: string;
url?: string;
maxAndroidAppVersionCode?: string;
maxIosAppVersionCode?: string;
Expand Down

0 comments on commit 5e83d14

Please sign in to comment.