UNPKG

eas-cli

Version:
96 lines (94 loc) 4.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccountResolver = void 0; const tslib_1 = require("tslib"); const assert_1 = tslib_1.__importDefault(require("assert")); const chalk_1 = tslib_1.__importDefault(require("chalk")); const action_1 = tslib_1.__importDefault(require("./actions/create/action")); const AppleTeamMutation_1 = require("../credentials/ios/api/graphql/mutations/AppleTeamMutation"); const AppleTeamQuery_1 = require("../credentials/ios/api/graphql/queries/AppleTeamQuery"); const log_1 = tslib_1.__importDefault(require("../log")); const projectUtils_1 = require("../project/projectUtils"); const prompts_1 = require("../prompts"); const CREATE_COMMAND_DESCRIPTION = `This command lets you register your Apple devices (iPhones, iPads and Macs) for internal distribution of your app. Internal distribution means that you won't need to upload your app archive to App Store / Testflight. Your app archive (.ipa) will be installable on your equipment as long as you sign your application with an adhoc provisioning profile. The provisioning profile needs to contain the UDIDs (unique identifiers) of your iPhones, iPads and Macs. First of all, choose the Expo account under which you want to register your devices. Later, authenticate with Apple and choose your desired Apple Team (if your Apple ID has access to multiple teams).`; class DeviceManager { ctx; constructor(ctx) { this.ctx = ctx; } async createAsync() { log_1.default.log(chalk_1.default.green(CREATE_COMMAND_DESCRIPTION)); log_1.default.addNewLineIfNone(); const account = await this.resolveAccountAsync(); const appleAuthCtx = await this.ctx.appStore.ensureAuthenticatedAsync(); const appleTeam = await ensureAppleTeamExistsAsync(this.ctx.graphqlClient, account.id, { appleTeamIdentifier: appleAuthCtx.team.id, appleTeamName: appleAuthCtx.team.name, }); const action = new action_1.default(this.ctx.graphqlClient, this.ctx.appStore, account, appleTeam); await action.runAsync(); } async resolveAccountAsync() { const resolver = new AccountResolver(this.ctx.graphqlClient, this.ctx.projectId, this.ctx.user); return await resolver.resolveAccountAsync(); } } exports.default = DeviceManager; class AccountResolver { graphqlClient; projectId; user; constructor(graphqlClient, projectId, user) { this.graphqlClient = graphqlClient; this.projectId = projectId; this.user = user; } async resolveAccountAsync() { if (this.projectId) { const account = await this.resolveProjectAccountAsync(); if (account) { return account; } } return await this.promptForAccountAsync(); } async resolveProjectAccountAsync() { (0, assert_1.default)(this.projectId, 'expo config is not set'); const account = await (0, projectUtils_1.getOwnerAccountForProjectIdAsync)(this.graphqlClient, this.projectId); const useProjectAccount = await (0, prompts_1.confirmAsync)({ message: `You're inside the project directory. Would you like to use the ${chalk_1.default.underline(account.name)} account?`, }); return useProjectAccount ? account : undefined; } async promptForAccountAsync() { const choices = this.user.accounts.map(account => ({ title: account.name, value: account, })); const { account } = await (0, prompts_1.promptAsync)({ type: 'select', name: 'account', message: 'Which account to use?', choices, }); return account; } } exports.AccountResolver = AccountResolver; async function ensureAppleTeamExistsAsync(graphqlClient, accountId, { appleTeamIdentifier, appleTeamName }) { const appleTeam = await AppleTeamQuery_1.AppleTeamQuery.getByAppleTeamIdentifierAsync(graphqlClient, accountId, appleTeamIdentifier); if (appleTeam) { return appleTeam; } else { return await AppleTeamMutation_1.AppleTeamMutation.createAppleTeamAsync(graphqlClient, { appleTeamIdentifier, appleTeamName, }, accountId); } }