UNPKG

@capawesome/cli

Version:

The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.

85 lines (84 loc) 3.65 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const citty_1 = require("citty"); const consola_1 = __importDefault(require("consola")); const app_channels_1 = __importDefault(require("../../../services/app-channels")); const apps_1 = __importDefault(require("../../../services/apps")); const error_1 = require("../../../utils/error"); const prompt_1 = require("../../../utils/prompt"); exports.default = (0, citty_1.defineCommand)({ meta: { description: 'Create a new app channel.', }, args: { appId: { 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: (ctx) => __awaiter(void 0, void 0, void 0, function* () { let appId = ctx.args.appId; let bundleLimitAsString = ctx.args.bundleLimit; let name = ctx.args.name; // Validate the app ID if (!appId) { const apps = yield apps_1.default.findAll(); if (!apps.length) { consola_1.default.error('You must create an app before creating a channel.'); process.exit(1); } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = yield (0, prompt_1.prompt)('Which app do you want to create the channel for?', { type: 'select', options: apps.map((app) => ({ label: app.name, value: app.id })), }); } // Validate the bundle limit let bundleLimit; if (bundleLimitAsString) { bundleLimit = parseInt(bundleLimitAsString, 10); if (isNaN(bundleLimit)) { consola_1.default.error('The bundle limit must be a number.'); process.exit(1); } } // Validate the channel name if (!name) { name = yield (0, prompt_1.prompt)('Enter the name of the channel:', { type: 'text' }); } try { const response = yield app_channels_1.default.create({ appId, name, totalAppBundleLimit: bundleLimit, }); consola_1.default.success('Channel created successfully.'); consola_1.default.info(`Channel ID: ${response.id}`); } catch (error) { const message = (0, error_1.getMessageFromUnknownError)(error); consola_1.default.error(message); process.exit(1); } }), });