UNPKG

@capawesome/cli

Version:

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

75 lines (74 loc) 3.06 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_devices_1 = __importDefault(require("../../../services/app-devices")); 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: 'Delete an app device.', }, args: { appId: { type: 'string', description: 'ID of the app.', }, deviceId: { type: 'string', description: 'ID of the device.', }, }, run: (ctx) => __awaiter(void 0, void 0, void 0, function* () { let appId = ctx.args.appId; if (!appId) { const apps = yield apps_1.default.findAll(); if (!apps.length) { consola_1.default.error('You must create an app before deleting a device.'); 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 delete the device from?', { type: 'select', options: apps.map((app) => ({ label: app.name, value: app.id })), }); } let deviceId = ctx.args.deviceId; if (!deviceId) { deviceId = yield (0, prompt_1.prompt)('Enter the device ID:', { type: 'text', }); } const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this device?', { type: 'confirm', }); if (!confirmed) { return; } try { yield app_devices_1.default.delete({ appId, deviceId, }); consola_1.default.success('Device deleted successfully.'); } catch (error) { const message = (0, error_1.getMessageFromUnknownError)(error); consola_1.default.error(message); process.exit(1); } }), });