diff --git a/CHANGELOG.md b/CHANGELOG.md index a752a22496..bf0adff588 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages. ### ๐ŸŽ‰ New features +- Add channel configurations to **eas.json** during `eas update:configure`. ([#1570](https://github.com/expo/eas-cli/pull/1570) by [@jonsamp](https://github.com/jonsamp)) + ### ๐Ÿ› Bug fixes ### ๐Ÿงน Chores diff --git a/packages/eas-cli/src/commands/update/configure.ts b/packages/eas-cli/src/commands/update/configure.ts index f5bf5a4c66..8f075e41a0 100644 --- a/packages/eas-cli/src/commands/update/configure.ts +++ b/packages/eas-cli/src/commands/update/configure.ts @@ -1,10 +1,11 @@ import { Flags } from '@oclif/core'; +import chalk from 'chalk'; import EasCommand from '../../commandUtils/EasCommand'; import { EASNonInteractiveFlag } from '../../commandUtils/flags'; import Log from '../../log'; import { RequestedPlatform } from '../../platform'; -import { ensureEASUpdatesIsConfiguredAsync } from '../../update/configure'; +import { ensureEASUpdateIsConfiguredAsync } from '../../update/configure'; export default class UpdateConfigure extends EasCommand { static override description = 'configure the project to support EAS Update'; @@ -38,7 +39,7 @@ export default class UpdateConfigure extends EasCommand { '๐Ÿ’ก The following process will configure your project to run EAS Update. These changes only apply to your local project files and you can safely revert them at any time.' ); - await ensureEASUpdatesIsConfiguredAsync(graphqlClient, { + await ensureEASUpdateIsConfiguredAsync(graphqlClient, { exp, projectId, projectDir, @@ -46,6 +47,23 @@ export default class UpdateConfigure extends EasCommand { }); Log.addNewLineIfNone(); - Log.log(`๐ŸŽ‰ Your app is configured to run EAS Update!`); + Log.log(`๐ŸŽ‰ Your app is configured with EAS Update!`); + Log.newLine(); + Log.log(`${chalk.bold('Next steps')}:`); + Log.newLine(); + Log.log('Update a production build:'); + Log.log(`1. Create a new build. Example: ${chalk.bold('eas build --profile production')}.`); + Log.log('2. Make changes in your project.'); + Log.log(`3. Publish an update. Example: ${chalk.bold('eas update --channel production')}.`); + Log.log('4. Force close and reopen the app at least twice to view the update.'); + + Log.newLine(); + Log.log('Preview an update:'); + Log.log( + `1. Publish an update to a branch. Example: ${chalk.bold('eas update --branch new-feature')}.` + ); + Log.log( + '2. In Expo Go or a development build, navigate to Projects > [project name] > Branch > Open.' + ); } } diff --git a/packages/eas-cli/src/commands/update/index.ts b/packages/eas-cli/src/commands/update/index.ts index c363a5219d..be48ed680a 100644 --- a/packages/eas-cli/src/commands/update/index.ts +++ b/packages/eas-cli/src/commands/update/index.ts @@ -37,7 +37,7 @@ import { } from '../../project/publish'; import { resolveWorkflowAsync } from '../../project/workflow'; import { promptAsync } from '../../prompts'; -import { ensureEASUpdatesIsConfiguredAsync } from '../../update/configure'; +import { ensureEASUpdateIsConfiguredAsync } from '../../update/configure'; import { formatUpdateMessage, truncateString as truncateUpdateMessage } from '../../update/utils'; import { checkManifestBodyAgainstUpdateInfoGroup, @@ -192,7 +192,7 @@ export default class UpdatePublish extends EasCommand { await maybeWarnAboutEasOutagesAsync(graphqlClient, [StatuspageServiceName.EasUpdate]); - await ensureEASUpdatesIsConfiguredAsync(graphqlClient, { + await ensureEASUpdateIsConfiguredAsync(graphqlClient, { exp: expPossiblyWithoutEasUpdateConfigured, platform: getRequestedPlatform(platformFlag), projectDir, diff --git a/packages/eas-cli/src/update/configure.ts b/packages/eas-cli/src/update/configure.ts index d4381639b3..d1c78845ca 100644 --- a/packages/eas-cli/src/update/configure.ts +++ b/packages/eas-cli/src/update/configure.ts @@ -1,7 +1,9 @@ import { modifyConfigAsync } from '@expo/config'; import { ExpoConfig } from '@expo/config-types'; import { Platform, Workflow } from '@expo/eas-build-job'; +import { EasJsonAccessor } from '@expo/eas-json'; import chalk from 'chalk'; +import fs from 'fs-extra'; import { getEASUpdateURL } from '../api'; import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient'; @@ -225,7 +227,7 @@ function warnEASUpdatesManualConfig({ /** * Make sure that the current `app.json` configuration for EAS Updates is set natively. */ -async function ensureEASUpdatesIsConfiguredNativelyAsync( +async function ensureEASUpdateIsConfiguredNativelyAsync( graphqlClient: ExpoGraphqlClient, { exp, @@ -252,6 +254,67 @@ async function ensureEASUpdatesIsConfiguredNativelyAsync( } } +/** + * Make sure EAS Build profiles are configured to work with EAS Update by adding channels to build profiles. + */ + +async function ensureEASUpdateIsConfiguredInEasJsonAsync(projectDir: string): Promise { + const easJsonPath = EasJsonAccessor.formatEasJsonPath(projectDir); + + if (!(await fs.pathExists(easJsonPath))) { + Log.warn( + `EAS Build is not configured. If you'd like to use EAS Build with EAS Update, run ${chalk.bold( + 'eas build:configure' + )}, then re-run ${chalk.bold('eas update:configure')} to configure ${chalk.bold( + 'eas.json' + )} with EAS Update.` + ); + return; + } + + try { + const easJsonAccessor = new EasJsonAccessor(projectDir); + await easJsonAccessor.readRawJsonAsync(); + + easJsonAccessor.patch(easJsonRawObject => { + const easBuildProfilesWithChannels = Object.keys(easJsonRawObject.build).reduce( + (acc, profileNameKey) => { + const buildProfile = easJsonRawObject.build[profileNameKey]; + const isNotAlreadyConfigured = !buildProfile.channel && !buildProfile.releaseChannel; + + if (isNotAlreadyConfigured) { + return { + ...acc, + [profileNameKey]: { + ...buildProfile, + channel: profileNameKey, + }, + }; + } + + return { + ...acc, + [profileNameKey]: { + ...easJsonRawObject.build[profileNameKey], + }, + }; + }, + {} + ); + + return { + ...easJsonRawObject, + build: easBuildProfilesWithChannels, + }; + }); + + await easJsonAccessor.writeAsync(); + Log.withTick(`Configured ${chalk.bold('eas.json')}.`); + } catch (error) { + Log.error(`We were not able to configure ${chalk.bold('eas.json')}. Error: ${error}.`); + } +} + /** * Make sure EAS Update is fully configured in the current project. * This goes over a checklist and performs the following checks or changes: @@ -261,7 +324,7 @@ async function ensureEASUpdatesIsConfiguredNativelyAsync( * - Sets `updates.url` if not set * - Ensure latest changes are reflected in the native config, if any */ -export async function ensureEASUpdatesIsConfiguredAsync( +export async function ensureEASUpdateIsConfiguredAsync( graphqlClient: ExpoGraphqlClient, { exp: expWithoutUpdates, @@ -300,8 +363,10 @@ export async function ensureEASUpdatesIsConfiguredAsync( workflows, }); + await ensureEASUpdateIsConfiguredInEasJsonAsync(projectDir); + if (projectChanged || !hasExpoUpdates) { - await ensureEASUpdatesIsConfiguredNativelyAsync(graphqlClient, { + await ensureEASUpdateIsConfiguredNativelyAsync(graphqlClient, { exp: expWithUpdates, projectDir, projectId,