eas-cli
Version:
EAS command line tool
125 lines (124 loc) • 5.98 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.listAndRenderAppleDevicesOnAppleTeamAsync = exports.selectAppleDeviceOnAppleTeamAsync = exports.selectAppleTeamOnAccountAsync = exports.DEVICES_LIMIT = exports.TEAMS_LIMIT = void 0;
const tslib_1 = require("tslib");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const formatDevice_1 = tslib_1.__importDefault(require("./utils/formatDevice"));
const AppleTeamFormatting_1 = require("../credentials/ios/actions/AppleTeamFormatting");
const DeviceUtils_1 = require("../credentials/ios/actions/DeviceUtils");
const AppleDeviceQuery_1 = require("../credentials/ios/api/graphql/queries/AppleDeviceQuery");
const AppleTeamQuery_1 = require("../credentials/ios/api/graphql/queries/AppleTeamQuery");
const log_1 = tslib_1.__importDefault(require("../log"));
const json_1 = require("../utils/json");
const queries_1 = require("../utils/queries");
exports.TEAMS_LIMIT = 50;
exports.DEVICES_LIMIT = 50;
async function selectAppleTeamOnAccountAsync(graphqlClient, { accountName, selectionPromptTitle, paginatedQueryOptions, }) {
if (paginatedQueryOptions.nonInteractive) {
throw new Error('Unable to select an Apple team in non-interactive mode.');
}
else {
const selectedAppleTeam = await (0, queries_1.paginatedQueryWithSelectPromptAsync)({
limit: paginatedQueryOptions.limit ?? exports.TEAMS_LIMIT,
offset: paginatedQueryOptions.offset,
queryToPerform: (limit, offset) => AppleTeamQuery_1.AppleTeamQuery.getAllForAccountAsync(graphqlClient, {
accountName,
limit,
offset,
}),
promptOptions: {
title: selectionPromptTitle,
makePartialChoiceObject: appleTeam => ({
title: appleTeam.appleTeamName
? `${appleTeam.appleTeamName} (ID: ${appleTeam.appleTeamIdentifier})`
: appleTeam.appleTeamIdentifier,
}),
getIdentifierForQueryItem: appleTeam => appleTeam.id,
},
});
if (!selectedAppleTeam) {
throw new Error(`Couldn't find any teams for the account ${accountName}`);
}
return selectedAppleTeam;
}
}
exports.selectAppleTeamOnAccountAsync = selectAppleTeamOnAccountAsync;
async function selectAppleDeviceOnAppleTeamAsync(graphqlClient, { accountName, appleTeamIdentifier, selectionPromptTitle, paginatedQueryOptions, }) {
if (paginatedQueryOptions.nonInteractive) {
throw new Error('Unable to select an Apple device in non-interactive mode.');
}
else {
const selectedAppleDevice = await (0, queries_1.paginatedQueryWithSelectPromptAsync)({
limit: paginatedQueryOptions.limit ?? exports.DEVICES_LIMIT,
offset: paginatedQueryOptions.offset,
queryToPerform: (limit, offset) => AppleDeviceQuery_1.AppleDeviceQuery.getAllForAppleTeamAsync(graphqlClient, {
accountName,
appleTeamIdentifier,
limit,
offset,
}),
promptOptions: {
title: selectionPromptTitle,
makePartialChoiceObject: appleDevice => ({
title: (0, DeviceUtils_1.formatDeviceLabel)(appleDevice),
}),
getIdentifierForQueryItem: appleTeam => appleTeam.id,
},
});
if (!selectedAppleDevice) {
throw new Error(`Couldn't find any devices on the Apple team with the id ${appleTeamIdentifier}`);
}
return selectedAppleDevice;
}
}
exports.selectAppleDeviceOnAppleTeamAsync = selectAppleDeviceOnAppleTeamAsync;
async function listAndRenderAppleDevicesOnAppleTeamAsync(graphqlClient, { accountName, appleTeam, paginatedQueryOptions, }) {
if (paginatedQueryOptions.nonInteractive) {
const devices = await AppleDeviceQuery_1.AppleDeviceQuery.getAllForAppleTeamAsync(graphqlClient, {
accountName,
appleTeamIdentifier: appleTeam.appleTeamIdentifier,
offset: paginatedQueryOptions.offset,
limit: paginatedQueryOptions.limit,
});
renderPageOfAppleDevices({ devices, appleTeam, paginatedQueryOptions });
}
else {
await (0, queries_1.paginatedQueryWithConfirmPromptAsync)({
limit: paginatedQueryOptions.limit ?? exports.DEVICES_LIMIT,
offset: paginatedQueryOptions.offset,
queryToPerform: (limit, offset) => AppleDeviceQuery_1.AppleDeviceQuery.getAllForAppleTeamAsync(graphqlClient, {
accountName,
appleTeamIdentifier: appleTeam.appleTeamIdentifier,
limit,
offset,
}),
promptOptions: {
title: 'Load more devices?',
renderListItems: devices => {
renderPageOfAppleDevices({ devices, appleTeam, paginatedQueryOptions });
},
},
});
}
}
exports.listAndRenderAppleDevicesOnAppleTeamAsync = listAndRenderAppleDevicesOnAppleTeamAsync;
function renderPageOfAppleDevices({ devices, appleTeam, paginatedQueryOptions, }) {
if (paginatedQueryOptions.json) {
(0, json_1.printJsonOnlyOutput)(devices);
}
else {
if (devices.length === 0) {
log_1.default.log(`Could not find devices on Apple team -- ${(0, AppleTeamFormatting_1.formatAppleTeam)({
appleTeamIdentifier: appleTeam.appleTeamIdentifier,
appleTeamName: appleTeam.appleTeamName,
})}`);
}
else {
const list = devices
.map(device => (0, formatDevice_1.default)(device, appleTeam))
.join(`\n\n${chalk_1.default.dim('———')}\n\n`);
log_1.default.log(`\n${list}`);
log_1.default.addNewLineIfNone();
}
}
}
;