Skip to content

Commit ebd648c

Browse files
committed
[eas-cli] Add eas update:list-embedded command
1 parent f72b0ae commit ebd648c

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { Platform } from '@expo/eas-build-job';
2+
import { Flags } from '@oclif/core';
3+
4+
import EasCommand from '../../commandUtils/EasCommand';
5+
import {
6+
EasNonInteractiveAndJsonFlags,
7+
resolveNonInteractiveAndJsonFlags,
8+
} from '../../commandUtils/flags';
9+
import { getLimitFlagWithCustomValues } from '../../commandUtils/pagination';
10+
import { AppPlatform } from '../../graphql/generated';
11+
import {
12+
EmbeddedUpdateFragment,
13+
EmbeddedUpdateQuery,
14+
} from '../../graphql/queries/EmbeddedUpdateQuery';
15+
import { toAppPlatform } from '../../graphql/types/AppPlatform';
16+
import Log from '../../log';
17+
import formatFields from '../../utils/formatFields';
18+
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
19+
20+
const DEFAULT_LIMIT = 25;
21+
const MAX_LIMIT = 50;
22+
23+
export default class UpdateListEmbedded extends EasCommand {
24+
static override description = 'list embedded updates registered with EAS Update for this project';
25+
26+
static override flags = {
27+
platform: Flags.option({
28+
char: 'p',
29+
description: 'Filter by platform',
30+
options: [Platform.IOS, Platform.ANDROID] as const,
31+
})(),
32+
'runtime-version': Flags.string({
33+
description: 'Filter by runtime version',
34+
}),
35+
channel: Flags.string({
36+
description: 'Filter by channel name',
37+
}),
38+
limit: getLimitFlagWithCustomValues({ defaultTo: DEFAULT_LIMIT, limit: MAX_LIMIT }),
39+
'after-cursor': Flags.string({
40+
description: 'Return items after this cursor (for pagination)',
41+
}),
42+
...EasNonInteractiveAndJsonFlags,
43+
};
44+
45+
static override contextDefinition = {
46+
...this.ContextOptions.ProjectId,
47+
...this.ContextOptions.LoggedIn,
48+
};
49+
50+
async runAsync(): Promise<void> {
51+
const { flags } = await this.parse(UpdateListEmbedded);
52+
const { json: jsonFlag, nonInteractive } = resolveNonInteractiveAndJsonFlags(flags);
53+
54+
const {
55+
projectId,
56+
loggedIn: { graphqlClient },
57+
} = await this.getContextAsync(UpdateListEmbedded, { nonInteractive });
58+
59+
if (jsonFlag) {
60+
enableJsonOutput();
61+
}
62+
63+
const platform: AppPlatform | undefined = flags.platform
64+
? toAppPlatform(flags.platform as Platform)
65+
: undefined;
66+
const filter =
67+
(platform ?? flags['runtime-version'] ?? flags.channel)
68+
? {
69+
platform,
70+
runtimeVersion: flags['runtime-version'],
71+
channel: flags.channel,
72+
}
73+
: undefined;
74+
75+
const limit = flags.limit ?? DEFAULT_LIMIT;
76+
const connection = await EmbeddedUpdateQuery.viewPaginatedAsync(graphqlClient, {
77+
appId: projectId,
78+
filter,
79+
first: limit,
80+
after: flags['after-cursor'],
81+
});
82+
83+
const embeddedUpdates = connection.edges.map(e => e.node);
84+
85+
if (jsonFlag) {
86+
printJsonOnlyOutput({
87+
embeddedUpdates,
88+
pageInfo: connection.pageInfo,
89+
});
90+
return;
91+
}
92+
93+
if (embeddedUpdates.length === 0) {
94+
Log.log('No embedded updates found.');
95+
return;
96+
}
97+
98+
for (const embeddedUpdate of embeddedUpdates) {
99+
Log.log(formatEmbeddedUpdateRow(embeddedUpdate));
100+
Log.addNewLineIfNone();
101+
}
102+
103+
if (connection.pageInfo.hasNextPage && connection.pageInfo.endCursor) {
104+
Log.log(
105+
`Showing ${embeddedUpdates.length} result${embeddedUpdates.length === 1 ? '' : 's'}. ` +
106+
`For the next page, run with --after-cursor ${connection.pageInfo.endCursor}`
107+
);
108+
}
109+
}
110+
}
111+
112+
function formatEmbeddedUpdateRow(embeddedUpdate: EmbeddedUpdateFragment): string {
113+
return formatFields([
114+
{ label: 'ID', value: embeddedUpdate.id },
115+
{ label: 'Platform', value: embeddedUpdate.platform.toLowerCase() },
116+
{ label: 'Runtime version', value: embeddedUpdate.runtimeVersion },
117+
{ label: 'Channel', value: embeddedUpdate.channel },
118+
{ label: 'Created at', value: new Date(embeddedUpdate.createdAt).toLocaleString() },
119+
]);
120+
}

0 commit comments

Comments
 (0)