From c7d3a08191f58a85c934bcfeb2e62fafe17fc0cd Mon Sep 17 00:00:00 2001 From: Dominik Sokal Date: Fri, 16 Apr 2021 15:43:41 +0200 Subject: [PATCH 1/2] allow for registering devices when building app for internal distribution --- .../new/SetupAdhocProvisioningProfile.ts | 57 +++++++++++++++---- .../src/credentials/ios/api/GraphqlClient.ts | 15 ++--- .../api/graphql/queries/AppleDeviceQuery.ts | 8 ++- .../src/devices/actions/create/action.ts | 3 +- 4 files changed, 62 insertions(+), 21 deletions(-) diff --git a/packages/eas-cli/src/credentials/ios/actions/new/SetupAdhocProvisioningProfile.ts b/packages/eas-cli/src/credentials/ios/actions/new/SetupAdhocProvisioningProfile.ts index cc3c80033c..363aa60112 100644 --- a/packages/eas-cli/src/credentials/ios/actions/new/SetupAdhocProvisioningProfile.ts +++ b/packages/eas-cli/src/credentials/ios/actions/new/SetupAdhocProvisioningProfile.ts @@ -1,16 +1,19 @@ import assert from 'assert'; +import chalk from 'chalk'; import differenceBy from 'lodash/differenceBy'; import isEqual from 'lodash/isEqual'; import nullthrows from 'nullthrows'; +import DeviceCreateAction, { RegistrationMethod } from '../../../../devices/actions/create/action'; import { + AppleDeviceFragment, AppleProvisioningProfileFragment, AppleTeamFragment, IosAppBuildCredentialsFragment, IosDistributionType, } from '../../../../graphql/generated'; import Log from '../../../../log'; -import { confirmAsync } from '../../../../prompts'; +import { confirmAsync, pressAnyKeyToContinueAsync } from '../../../../prompts'; import { Context } from '../../../context'; import { AppLookupParams } from '../../api/GraphqlClient'; import { MissingCredentialsNonInteractiveError } from '../../errors'; @@ -63,16 +66,18 @@ export class SetupAdhocProvisioningProfile { assert(appleTeam, 'Apple Team must be defined here'); // 2. Fetch devices registered on EAS servers - const registeredAppleDevices = await ctx.newIos.getDevicesForAppleTeamAsync( - this.app, - appleTeam - ); - const registeredAppleDeviceIdentifiers = registeredAppleDevices.map( - ({ identifier }) => identifier - ); - if (registeredAppleDeviceIdentifiers.length === 0) { - // TODO: implement device registration - throw new Error(`Run 'eas device:create' to register your devices first`); + let registeredAppleDevices = await ctx.newIos.getDevicesForAppleTeamAsync(this.app, appleTeam); + if (registeredAppleDevices.length === 0) { + const shouldRegisterDevices = await confirmAsync({ + message: `You don't have any registered devices yet. Would you like to register them now?`, + initial: true, + }); + + if (shouldRegisterDevices) { + registeredAppleDevices = await this.registerDevicesAsync(ctx, appleTeam); + } else { + throw new Error(`Run 'eas device:create' to register your devices first`); + } } // 3. Choose devices for internal distribution @@ -181,6 +186,36 @@ export class SetupAdhocProvisioningProfile { })); } } + + private async registerDevicesAsync( + ctx: Context, + appleTeam: AppleTeamFragment + ): Promise { + const action = new DeviceCreateAction(this.app.account, appleTeam); + const method = await action.runAsync(); + + while (true) { + if (method !== RegistrationMethod.INPUT) { + Log.newLine(); + Log.log(chalk.bold("Press any key if you've already finished device registration.")); + await pressAnyKeyToContinueAsync(); + } + Log.newLine(); + + const devices = await ctx.newIos.getDevicesForAppleTeamAsync(this.app, appleTeam, { + useCache: false, + }); + if (devices.length === 0) { + Log.warn('There are still no registered devices.'); + // if the user used the input method there should be some devices available + if (method === RegistrationMethod.INPUT) { + throw new Error('Input registration method has failed'); + } + } else { + return devices; + } + } + } } function doUDIDsMatch(udidsA: string[], udidsB: string[]): boolean { diff --git a/packages/eas-cli/src/credentials/ios/api/GraphqlClient.ts b/packages/eas-cli/src/credentials/ios/api/GraphqlClient.ts index e91fceb4c9..cf29bc2a3f 100644 --- a/packages/eas-cli/src/credentials/ios/api/GraphqlClient.ts +++ b/packages/eas-cli/src/credentials/ios/api/GraphqlClient.ts @@ -3,6 +3,7 @@ import nullthrows from 'nullthrows'; import { AppFragment, AppleAppIdentifierFragment, + AppleDeviceFragment, AppleDistributionCertificateFragment, AppleTeamFragment, CommonIosAppCredentialsFragment, @@ -26,10 +27,7 @@ import { IosAppBuildCredentialsMutation } from './graphql/mutations/IosAppBuildC import { IosAppCredentialsMutation } from './graphql/mutations/IosAppCredentialsMutation'; import { AppQuery } from './graphql/queries/AppQuery'; import { AppleAppIdentifierQuery } from './graphql/queries/AppleAppIdentifierQuery'; -import { - AppleDeviceFragmentWithAppleTeam, - AppleDeviceQuery, -} from './graphql/queries/AppleDeviceQuery'; +import { AppleDeviceQuery } from './graphql/queries/AppleDeviceQuery'; import { AppleDistributionCertificateQuery } from './graphql/queries/AppleDistributionCertificateQuery'; import { AppleProvisioningProfileQuery, @@ -215,9 +213,12 @@ export async function createOrGetExistingAppleAppIdentifierAsync( export async function getDevicesForAppleTeamAsync( { account }: AppLookupParams, - { appleTeamIdentifier }: AppleTeamFragment -): Promise { - return await AppleDeviceQuery.getAllByAppleTeamIdentifierAsync(account.id, appleTeamIdentifier); + { appleTeamIdentifier }: AppleTeamFragment, + { useCache = true }: { useCache?: boolean } = {} +): Promise { + return await AppleDeviceQuery.getAllByAppleTeamIdentifierAsync(account.id, appleTeamIdentifier, { + useCache, + }); } export async function createProvisioningProfileAsync( diff --git a/packages/eas-cli/src/credentials/ios/api/graphql/queries/AppleDeviceQuery.ts b/packages/eas-cli/src/credentials/ios/api/graphql/queries/AppleDeviceQuery.ts index 3017075a6a..73208a42fc 100644 --- a/packages/eas-cli/src/credentials/ios/api/graphql/queries/AppleDeviceQuery.ts +++ b/packages/eas-cli/src/credentials/ios/api/graphql/queries/AppleDeviceQuery.ts @@ -34,7 +34,8 @@ export type AppleDevicesByIdentifierQueryResult = AppleDeviceQueryResult & { const AppleDeviceQuery = { async getAllByAppleTeamIdentifierAsync( accountId: string, - appleTeamIdentifier: string + appleTeamIdentifier: string, + { useCache = true }: { useCache?: boolean } = {} ): Promise { const data = await withErrorHandlingAsync( graphqlClient @@ -63,7 +64,10 @@ const AppleDeviceQuery = { accountId, appleTeamIdentifier, }, - { additionalTypenames: ['AppleDevice'] } + { + additionalTypenames: ['AppleDevice'], + requestPolicy: useCache ? 'cache-first' : 'network-only', + } ) .toPromise() ); diff --git a/packages/eas-cli/src/devices/actions/create/action.ts b/packages/eas-cli/src/devices/actions/create/action.ts index c4866434bd..85c63efded 100644 --- a/packages/eas-cli/src/devices/actions/create/action.ts +++ b/packages/eas-cli/src/devices/actions/create/action.ts @@ -19,7 +19,7 @@ export default class DeviceCreateAction { private appleTeam: Pick ) {} - public async runAsync(): Promise { + public async runAsync(): Promise { const method = await this.askForRegistrationMethodAsync(); if (method === RegistrationMethod.WEBSITE) { await runRegistrationUrlMethodAsync(this.account.id, this.appleTeam); @@ -29,6 +29,7 @@ export default class DeviceCreateAction { Log.log('Bye!'); process.exit(0); } + return method; } private async askForRegistrationMethodAsync(): Promise { From 93670bd1cb4882f5d57472d282825eb5be0a8a51 Mon Sep 17 00:00:00 2001 From: Dominik Sokal Date: Mon, 19 Apr 2021 12:35:41 +0200 Subject: [PATCH 2/2] update CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5a944b98a..a4762647f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ This is the log of notable changes to EAS CLI and related packages. ### ๐ŸŽ‰ New features +- Add validation when setting up ad-hoc provisioning profile in non-interactive mode. ([#338](https://github.com/expo/eas-cli/pull/338)) +- Allow for registering devices when running an ad-hoc build for the first time. ([#340](https://github.com/expo/eas-cli/pull/340) by [@dsokal](https://github.com/dsokal)) + ### ๐Ÿ› Bug fixes ### ๐Ÿงน Chores @@ -22,7 +25,6 @@ This is the log of notable changes to EAS CLI and related packages. ### ๐ŸŽ‰ New features - Use special Expo SDK runtime version for managed projects ([#336](https://github.com/expo/eas-cli/pull/336)) by [@wschurman](https://github.com/wschurman)) -- Add validation when setting up ad-hoc provisioning profile in non-interactive mode. ([#338](https://github.com/expo/eas-cli/pull/338) by [@dsokal](https://github.com/dsokal)) ### ๐Ÿ› Bug fixes