eas-cli
Version:
EAS command line tool
115 lines (114 loc) • 5.32 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateChannelBranchMappingAsync = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const graphql_1 = require("graphql");
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
const queries_1 = require("../../branch/queries");
const branch_mapping_1 = require("../../channel/branch-mapping");
const queries_2 = 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 BranchQuery_1 = require("../../graphql/queries/BranchQuery");
const ChannelQuery_1 = require("../../graphql/queries/ChannelQuery");
const UpdateChannelBasicInfo_1 = require("../../graphql/types/UpdateChannelBasicInfo");
const log_1 = tslib_1.__importDefault(require("../../log"));
const branch_mapping_2 = require("../../rollout/branch-mapping");
const json_1 = require("../../utils/json");
async function updateChannelBranchMappingAsync(graphqlClient, { channelId, branchMapping }) {
const data = await (0, client_1.withErrorHandlingAsync)(graphqlClient
.mutation((0, graphql_tag_1.default) `
mutation UpdateChannelBranchMapping($channelId: ID!, $branchMapping: String!) {
updateChannel {
editUpdateChannel(channelId: $channelId, branchMapping: $branchMapping) {
id
...UpdateChannelBasicInfoFragment
}
}
}
${(0, graphql_1.print)(UpdateChannelBasicInfo_1.UpdateChannelBasicInfoFragmentNode)}
`, { channelId, branchMapping })
.toPromise());
const channel = data.updateChannel.editUpdateChannel;
if (!channel) {
throw new Error(`Could not find a channel with id: ${channelId}`);
}
return channel;
}
exports.updateChannelBranchMappingAsync = updateChannelBranchMappingAsync;
class ChannelEdit extends EasCommand_1.default {
static description = 'point a channel at a new branch';
static args = [
{
name: 'name',
required: false,
description: 'Name of the channel to edit',
},
];
static flags = {
branch: core_1.Flags.string({
description: 'Name of the branch to point to',
}),
...flags_1.EasNonInteractiveAndJsonFlags,
};
static contextDefinition = {
...this.ContextOptions.ProjectId,
...this.ContextOptions.LoggedIn,
};
async runAsync() {
const { args, flags: { branch: branchFlag, json, 'non-interactive': nonInteractive }, } = await this.parse(ChannelEdit);
const { projectId, loggedIn: { graphqlClient }, } = await this.getContextAsync(ChannelEdit, {
nonInteractive,
});
if (json) {
(0, json_1.enableJsonOutput)();
}
const existingChannel = args.name
? await ChannelQuery_1.ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName: args.name,
})
: await (0, queries_2.selectChannelOnAppAsync)(graphqlClient, {
projectId,
selectionPromptTitle: 'Select a channel to edit',
paginatedQueryOptions: { json, nonInteractive, offset: 0 },
});
if ((0, branch_mapping_2.isRollout)(existingChannel)) {
throw new Error('There is a rollout in progress. Manage it with "channel:rollout" instead.');
}
else if (!(0, branch_mapping_1.hasStandardBranchMap)(existingChannel) && !(0, branch_mapping_1.hasEmptyBranchMap)(existingChannel)) {
throw new Error('Only standard branch mappings can be edited with this command.');
}
const branch = branchFlag
? await BranchQuery_1.BranchQuery.getBranchByNameAsync(graphqlClient, {
appId: projectId,
name: branchFlag,
})
: await (0, queries_1.selectBranchOnAppAsync)(graphqlClient, {
projectId,
promptTitle: `Which branch would you like ${existingChannel.name} to point at?`,
displayTextForListItem: updateBranch => ({ title: updateBranch.name }),
paginatedQueryOptions: {
json,
nonInteractive,
offset: 0,
},
});
const channel = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: existingChannel.id,
branchMapping: JSON.stringify((0, branch_mapping_1.getAlwaysTrueBranchMapping)(branch.id)),
});
if (json) {
(0, json_1.printJsonOnlyOutput)(channel);
}
else {
log_1.default.withTick((0, chalk_1.default) `Channel {bold ${channel.name}} is now set to branch {bold ${branch.name}}.\n`);
log_1.default.addNewLineIfNone();
log_1.default.log((0, chalk_1.default) `Users with builds on channel {bold ${channel.name}} will now receive the active update on {bold ${branch.name}}.`);
}
}
}
exports.default = ChannelEdit;