Skip to content

Commit

Permalink
[eas-cli] resolve default environment automatically based on build co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
szdziedzic committed Oct 22, 2024
1 parent 38805c6 commit 0a03d18
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/eas-cli/src/build/evaluateConfigWithEnvVarsAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async function resolveEnvVarsAsync({
projectId: string;
}): Promise<Env> {
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(
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 0a03d18

Please sign in to comment.