@capawesome/cli
Version:
The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.
78 lines (77 loc) • 3.16 kB
JavaScript
;
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_bundles_1 = __importDefault(require("../../../services/app-bundles"));
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 bundle.',
},
args: {
appId: {
type: 'string',
description: 'ID of the app.',
},
bundleId: {
type: 'string',
description: 'ID of the bundle.',
},
},
run: (ctx) => __awaiter(void 0, void 0, void 0, function* () {
// Prompt for missing arguments
let appId = ctx.args.appId;
let bundleId = ctx.args.bundleId;
if (!appId) {
const apps = yield apps_1.default.findAll();
if (!apps.length) {
consola_1.default.error('You must create an app before deleting a bundle.');
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 bundle from?', {
type: 'select',
options: apps.map((app) => ({ label: app.name, value: app.id })),
});
}
if (!bundleId) {
bundleId = yield (0, prompt_1.prompt)('Enter the bundle ID:', {
type: 'text',
});
}
// Confirm deletion
const confirmed = yield (0, prompt_1.prompt)('Are you sure you want to delete this bundle?', {
type: 'confirm',
});
if (!confirmed) {
return;
}
// Delete bundle
try {
yield app_bundles_1.default.delete({
appId,
appBundleId: bundleId,
});
consola_1.default.success('Bundle deleted successfully.');
}
catch (error) {
const message = (0, error_1.getMessageFromUnknownError)(error);
consola_1.default.error(message);
process.exit(1);
}
}),
});