Skip to content

Commit

Permalink
[eas-cli] improve with-eas-environment-variables-set flag handling …
Browse files Browse the repository at this point in the history
…in `eas update` command (#2667)

<!-- If this PR requires a changelog entry, add it by commenting the PR with the command `/changelog-entry [breaking-change|new-feature|bug-fix|chore] [message]`. -->
<!-- You can skip the changelog check by labeling the PR with "no changelog". -->

# Why

Make the `with-eas-environment-variables-set` flag reusable and improve type safety and description.

# How

Extract `with-eas-environment-variables-set` to separate file. Improve validation and type safety.

# Test Plan

Run command locally.
  • Loading branch information
szdziedzic authored Nov 5, 2024
1 parent 7c9970d commit 71ca181
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function loadServerSideEnvironmentVariablesAsync({
);
} else {
Log.log(
`No environment variables found for the "${environment.toLowerCase()}" environment on EAS servers.`
`No readable environment variables found for the "${environment.toLowerCase()}" environment on EAS servers.`
);
}

Expand Down
12 changes: 12 additions & 0 deletions packages/eas-cli/src/commandUtils/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ export const EasJsonOnlyFlag = {
description: 'Enable JSON output, non-JSON messages will be printed to stderr.',
}),
};

export const WithEasEnvironmentVariablesSetFlag = {
'with-eas-environment-variables-set': Flags.enum<EnvironmentVariableEnvironment | null>({
description:
'Environment to use the server-side defined EAS environment variables for during command execution.',
options: mapToLowercase(Object.values(EnvironmentVariableEnvironment)),
parse: upperCaseAsync,
required: false,
hidden: true,
default: null,
}),
};
59 changes: 14 additions & 45 deletions packages/eas-cli/src/commands/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { transformFingerprintSource } from '../../build/graphql';
import { ensureRepoIsCleanAsync } from '../../build/utils/repository';
import { getUpdateGroupUrl } from '../../build/utils/url';
import EasCommand from '../../commandUtils/EasCommand';
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import {
EasNonInteractiveAndJsonFlags,
WithEasEnvironmentVariablesSetFlag,
} from '../../commandUtils/flags';
import { getPaginatedQueryOptions } from '../../commandUtils/pagination';
import fetch from '../../fetch';
import {
Expand All @@ -31,7 +34,6 @@ import {
buildBundlesAsync,
buildUnsortedUpdateInfoGroupAsync,
collectAssetsAsync,
defaultPublishPlatforms,
filterCollectedAssetsByRequestedPlatforms,
generateEasMetadataAsync,
getBranchNameForCommandAsync,
Expand Down Expand Up @@ -64,7 +66,7 @@ type RawUpdateFlags = {
branch?: string;
channel?: string;
message?: string;
platform: string;
platform: RequestedPlatform;
'input-dir': string;
'skip-bundler': boolean;
'clear-cache': boolean;
Expand All @@ -73,7 +75,7 @@ type RawUpdateFlags = {
'rollout-percentage'?: number;
'non-interactive': boolean;
json: boolean;
'with-eas-environment-variables-set'?: string;
'with-eas-environment-variables-set': EnvironmentVariableEnvironment | null;
};

type UpdateFlags = {
Expand All @@ -90,7 +92,7 @@ type UpdateFlags = {
rolloutPercentage?: number;
json: boolean;
nonInteractive: boolean;
withEasEnvironmentVariablesSet?: EnvironmentVariableEnvironment;
withEasEnvironmentVariablesSet: EnvironmentVariableEnvironment | null;
};

export default class UpdatePublish extends EasCommand {
Expand Down Expand Up @@ -133,14 +135,10 @@ export default class UpdatePublish extends EasCommand {
min: 0,
max: 100,
}),
platform: Flags.enum({
platform: Flags.enum<RequestedPlatform>({
char: 'p',
options: [
// TODO: Add web when it's fully supported
...defaultPublishPlatforms,
'all',
],
default: 'all',
options: Object.values(RequestedPlatform), // TODO: Add web when it's fully supported
default: RequestedPlatform.All,
required: false,
}),
auto: Flags.boolean({
Expand All @@ -152,18 +150,7 @@ export default class UpdatePublish extends EasCommand {
description: `File containing the PEM-encoded private key corresponding to the certificate in expo-updates' configuration. Defaults to a file named "private-key.pem" in the certificate's directory. Only relevant if you are using code signing: https://docs.expo.dev/eas-update/code-signing/`,
required: false,
}),
'with-eas-environment-variables-set': Flags.enum({
description: 'Environment to use for EAS environment variables',
options: [
EnvironmentVariableEnvironment.Development,
EnvironmentVariableEnvironment.Preview,
EnvironmentVariableEnvironment.Production,
].map(env => env.toLowerCase()),
// eslint-disable-next-line async-protect/async-suffix
parse: async input => input.toUpperCase(),
required: false,
hidden: true,
}),
...WithEasEnvironmentVariablesSetFlag,
...EasNonInteractiveAndJsonFlags,
};

Expand Down Expand Up @@ -202,7 +189,7 @@ export default class UpdatePublish extends EasCommand {
getServerSideEnvironmentVariablesAsync,
} = await this.getContextAsync(UpdatePublish, {
nonInteractive,
withServerSideEnvironment: withEasEnvironmentVariablesSet ?? null,
withServerSideEnvironment: withEasEnvironmentVariablesSet,
});

if (jsonFlag) {
Expand Down Expand Up @@ -661,22 +648,6 @@ export default class UpdatePublish extends EasCommand {
);
}

if (
flags['with-eas-environment-variables-set'] &&
!Object.values(EnvironmentVariableEnvironment).includes(
flags['with-eas-environment-variables-set'] as EnvironmentVariableEnvironment
)
) {
Errors.error(
`--with-eas-environment-variables-set must be one of ${Object.values(
EnvironmentVariableEnvironment
)
.map(env => `"${env.toLocaleLowerCase()}"`)
.join(', ')}`,
{ exit: 1 }
);
}

return {
auto,
branchName,
Expand All @@ -685,15 +656,13 @@ export default class UpdatePublish extends EasCommand {
inputDir: flags['input-dir'],
skipBundler,
clearCache: flags['clear-cache'] ? true : !!flags['with-eas-environment-variables-set'],
platform: flags.platform as RequestedPlatform,
platform: flags.platform,
privateKeyPath: flags['private-key-path'],
rolloutPercentage: flags['rollout-percentage'],
nonInteractive,
emitMetadata,
json: flags.json ?? false,
withEasEnvironmentVariablesSet: flags[
'with-eas-environment-variables-set'
] as EnvironmentVariableEnvironment,
withEasEnvironmentVariablesSet: flags['with-eas-environment-variables-set'],
};
}
}

0 comments on commit 71ca181

Please sign in to comment.