From 0a03d18da4135e26e564913b5a287e16178ad8d7 Mon Sep 17 00:00:00 2001 From: Szymon Dziedzic Date: Mon, 21 Oct 2024 15:58:40 +0200 Subject: [PATCH] [eas-cli] resolve default environment automatically based on build configuration --- .../build/evaluateConfigWithEnvVarsAsync.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts b/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts index 64d707125c..b493f2b842 100644 --- a/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts +++ b/packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts @@ -54,7 +54,9 @@ async function resolveEnvVarsAsync({ projectId: string; }): Promise { const environment = - buildProfile.environment?.toUpperCase() ?? process.env.EAS_CURRENT_ENVIRONMENT; + buildProfile.environment?.toUpperCase() ?? + process.env.EAS_CURRENT_ENVIRONMENT ?? + resolveSuggestedEnvironmentForBuildProfileConfiguration(buildProfile); if (!environment || !isEnvironment(environment)) { Log.log( @@ -145,3 +147,27 @@ async function resolveEnvVarsAsync({ return { ...buildProfile.env }; } } + +function resolveSuggestedEnvironmentForBuildProfileConfiguration( + buildProfile: BuildProfile +): EnvironmentVariableEnvironment { + const setEnvironmentMessage = + 'Set the environment using the "environment" field in the build profile configuration if you want to use a specific environment.'; + if (buildProfile.distribution === 'store') { + Log.log( + `We detected that you are building for the "store" distribution. Resolving the environment for environment variables used during the build to "production". ${setEnvironmentMessage}` + ); + return EnvironmentVariableEnvironment.Production; + } else { + if (buildProfile.developmentClient) { + Log.log( + `We detected that you are building the development client. Resolving the environment for environment variables used during the build to "development". ${setEnvironmentMessage}` + ); + return EnvironmentVariableEnvironment.Development; + } + Log.log( + `We detected that you are building for the "internal" distribution. Resolving the environment for environment variables used during the build to "preview". ${setEnvironmentMessage}` + ); + return EnvironmentVariableEnvironment.Preview; + } +}