UNPKG

eas-cli

Version:
101 lines (100 loc) 3.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag")); const queries_1 = require("../../channel/queries"); const EasCommand_1 = tslib_1.__importDefault(require("../../commandUtils/EasCommand")); const flags_1 = require("../../commandUtils/flags"); const client_1 = require("../../graphql/client"); const ChannelQuery_1 = require("../../graphql/queries/ChannelQuery"); const log_1 = tslib_1.__importDefault(require("../../log")); const prompts_1 = require("../../prompts"); const json_1 = require("../../utils/json"); class ChannelDelete extends EasCommand_1.default { static hidden = true; static description = 'Delete a channel'; static args = [ { name: 'name', required: false, description: 'Name of the channel to delete', }, ]; static flags = { ...flags_1.EasNonInteractiveAndJsonFlags, }; static contextDefinition = { ...this.ContextOptions.ProjectId, ...this.ContextOptions.LoggedIn, }; async runAsync() { const { args: { name: nameArg }, flags: { json: jsonFlag, 'non-interactive': nonInteractive }, } = await this.parse(ChannelDelete); const { projectId, loggedIn: { graphqlClient }, } = await this.getContextAsync(ChannelDelete, { nonInteractive, }); if (jsonFlag) { (0, json_1.enableJsonOutput)(); } let channelId, channelName; if (nameArg) { const { id, name } = await ChannelQuery_1.ChannelQuery.viewUpdateChannelAsync(graphqlClient, { appId: projectId, channelName: nameArg, }); channelId = id; channelName = name; } else { if (nonInteractive) { throw new Error('Channel name must be set when running in non-interactive mode'); } const { id, name } = await (0, queries_1.selectChannelOnAppAsync)(graphqlClient, { projectId, selectionPromptTitle: 'Select a channel to delete', paginatedQueryOptions: { json: jsonFlag, nonInteractive, offset: 0, }, }); channelId = id; channelName = name; } if (!nonInteractive) { log_1.default.addNewLineIfNone(); log_1.default.warn(`You are about to permanently delete channel: "${channelName}".\nThis action is irreversible.`); log_1.default.newLine(); const confirmed = await (0, prompts_1.toggleConfirmAsync)({ message: 'Are you sure you wish to proceed?' }); if (!confirmed) { log_1.default.error(`Canceled deletion of channel: "${channelName}".`); process.exit(1); } } const deletionResult = await deleteChannelOnAppAsync(graphqlClient, { channelId, }); if (jsonFlag) { (0, json_1.printJsonOnlyOutput)(deletionResult); } else { log_1.default.withTick(`️Deleted channel "${channelName}".`); } } } exports.default = ChannelDelete; async function deleteChannelOnAppAsync(graphqlClient, { channelId }) { const data = await (0, client_1.withErrorHandlingAsync)(graphqlClient .mutation((0, graphql_tag_1.default) ` mutation DeleteUpdateChannel($channelId: ID!) { updateChannel { deleteUpdateChannel(channelId: $channelId) { id } } } `, { channelId, }) .toPromise()); return data.updateChannel.deleteUpdateChannel; }