Skip to content

Commit

Permalink
refactor(eas-cli): simplify the output of eas deploy --json (#2596)
Browse files Browse the repository at this point in the history
* refactor(eas-cli): simplify the `eas deploy --json` output

* docs: fix changelog entry

* refactor(eas-cli): keep aliases as array in `--json` output

* docs: fix changelog entry
  • Loading branch information
byCedric authored Sep 24, 2024
1 parent 2e002ad commit c0c2755
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🧹 Chores

- Simplify the output of `eas deploy --json`. ([#2596](https://github.com/expo/eas-cli/pull/2596) by [@byCedric](https://github.com/byCedric))

## [12.5.0](https://github.com/expo/eas-cli/releases/tag/v12.5.0) - 2024-09-23

### 🎉 New features
Expand Down
9 changes: 3 additions & 6 deletions packages/eas-cli/src/commands/worker/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import * as path from 'node:path';

import EasCommand from '../../commandUtils/EasCommand';
import { EASEnvironmentFlag, EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import {
EnvironmentVariableEnvironment,
WorkerDeploymentAliasFragment,
} from '../../graphql/generated';
import { EnvironmentVariableEnvironment } from '../../graphql/generated';
import Log from '../../log';
import { ora } from '../../ora';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
Expand Down Expand Up @@ -311,7 +308,7 @@ export default class WorkerDeploy extends EasCommand {
deploymentIdentifier: deployResult.id,
url: getDeploymentUrlFromFullName(deployResult.fullName),
},
aliases: [deploymentAlias].filter(Boolean) as WorkerDeploymentAliasFragment[],
aliases: [deploymentAlias],
production: deploymentProdAlias,
})
);
Expand All @@ -328,7 +325,7 @@ export default class WorkerDeploy extends EasCommand {
deploymentIdentifier: deployResult.id,
url: getDeploymentUrlFromFullName(deployResult.fullName),
},
aliases: [deploymentAlias].filter(Boolean) as WorkerDeploymentAliasFragment[],
aliases: [deploymentAlias],
production: deploymentProdAlias,
})
);
Expand Down
54 changes: 28 additions & 26 deletions packages/eas-cli/src/worker/utils/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type WorkerDeploymentData = {
/** The actual deployment information */
deployment: Pick<WorkerDeploymentFragment, 'deploymentIdentifier' | 'url'>;
/** All modified aliases of the deployment, if any */
aliases?: WorkerDeploymentAliasFragment[];
aliases?: (WorkerDeploymentAliasFragment | null)[];
/** The production promoting alias of the deployment, if any */
production?: WorkerDeploymentAliasFragment | null;
};
Expand All @@ -34,7 +34,10 @@ export function formatWorkerDeploymentTable(data: WorkerDeploymentData): string
];

if (data.aliases?.length) {
fields.push({ label: 'Alias URL', value: data.aliases[0].url });
const alias = data.aliases.filter(Boolean)[0];
if (alias) {
fields.push({ label: 'Alias URL', value: alias.url });
}
}
if (data.production) {
fields.push({ label: 'Production URL', value: data.production.url });
Expand All @@ -49,34 +52,33 @@ export function formatWorkerDeploymentTable(data: WorkerDeploymentData): string
type WorkerDeploymentOutput = {
/** The absolute URL to the dashboard on `expo.dev` */
dashboardUrl: string;
/** The deployment information */
deployment: {
identifier: string;
url: string;
aliases?: { id: string; name: string; url: string }[];
production?: { id: string; url: string };
};
/** The deployment identifier */
identifier: string;
/** The deployment URL */
url: string;
/** Custom aliases, if assigned */
aliases?: { id: string; url: string; name: string }[];
/** The production alias, if assigned */
production?: { id: string; url: string };
};

export function formatWorkerDeploymentJson(data: WorkerDeploymentData): WorkerDeploymentOutput {
const aliases = !data.aliases
? []
: (data.aliases.filter(Boolean) as WorkerDeploymentAliasFragment[]);

return {
dashboardUrl: getDashboardUrl(data.projectId),
deployment: {
identifier: data.deployment.deploymentIdentifier,
url: data.deployment.url,
aliases: !data.aliases?.length
? undefined
: data.aliases.map(alias => ({
id: alias.id,
name: alias.aliasName,
url: alias.url,
})),
production: !data.production
? undefined
: {
id: data.production.id,
url: data.production.url,
},
},
identifier: data.deployment.deploymentIdentifier,
url: data.deployment.url,
aliases: !aliases.length
? undefined
: aliases.map(alias => ({ id: alias.id, url: alias.url, name: alias.aliasName })),
production: !data.production
? undefined
: {
id: data.production.id,
url: data.production.url,
},
};
}

0 comments on commit c0c2755

Please sign in to comment.