Skip to content

Commit

Permalink
feat(apps): add --bundle-limit option (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz authored Nov 1, 2024
1 parent c780be9 commit b20d33c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/commands/apps/channels/create.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineCommand } from 'citty';
import consola from 'consola';
import { prompt } from '../../../utils/prompt';
import appsService from '../../../services/apps';
import appChannelsService from '../../../services/app-channels';
import appsService from '../../../services/apps';
import { getMessageFromUnknownError } from '../../../utils/error';
import { prompt } from '../../../utils/prompt';

export default defineCommand({
meta: {
Expand All @@ -14,13 +14,21 @@ export default defineCommand({
type: 'string',
description: 'ID of the app.',
},
bundleLimit: {
type: 'string',
description:
'Maximum number of bundles that can be assigned to the channel. If more bundles are assigned, the oldest bundles will be automatically deleted.',
},
name: {
type: 'string',
description: 'Name of the channel.',
},
},
run: async (ctx) => {
let appId = ctx.args.appId;
let bundleLimitAsString = ctx.args.bundleLimit;
let name = ctx.args.name;
// Validate the app ID
if (!appId) {
const apps = await appsService.findAll();
if (!apps.length) {
Expand All @@ -33,14 +41,24 @@ export default defineCommand({
options: apps.map((app) => ({ label: app.name, value: app.id })),
});
}
let name = ctx.args.name;
// Validate the bundle limit
let bundleLimit: number | undefined;
if (bundleLimitAsString) {
bundleLimit = parseInt(bundleLimitAsString, 10);
if (isNaN(bundleLimit)) {
consola.error('The bundle limit must be a number.');
return;
}
}
// Validate the channel name
if (!name) {
name = await prompt('Enter the name of the channel:', { type: 'text' });
}
try {
const response = await appChannelsService.create({
appId,
name,
totalAppBundleLimit: bundleLimit,
});
consola.success('Channel created successfully.');
consola.info(`Channel ID: ${response.id}`);
Expand Down
1 change: 1 addition & 0 deletions src/types/app-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface AppChannelDto {
export interface CreateAppChannelDto {
appId: string;
name: string;
totalAppBundleLimit?: number;
}

export interface DeleteAppChannelDto {
Expand Down

0 comments on commit b20d33c

Please sign in to comment.