mirror of
https://github.com/expo/eas-cli.git
synced 2026-11-23 16:00:26 -10:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2eed5ca5d5 | ||
|
|
d0efda7b75 | ||
|
|
fd33aceac9 | ||
|
|
b65b3422d5 | ||
|
|
fd2465b0ad | ||
|
|
fa77bd2e07 | ||
|
|
dc128d34e0 | ||
|
|
06265786a7 | ||
|
|
eb2927f24d | ||
|
|
ab76641dcb |
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'eas-cli': minor
|
||||
---
|
||||
|
||||
Add `eas project:icon:unset`, and make `eas project:icon:set` use the icon from the app config when no path is given.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'eas-cli': minor
|
||||
---
|
||||
|
||||
Show the display name, slug and icon in `eas project:info`, and describe how `eas project:icon:set` processes the image.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'eas-cli': minor
|
||||
---
|
||||
|
||||
Add `eas project:name:set` to set the project display name shown on the EAS dashboard.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'eas-cli': patch
|
||||
---
|
||||
|
||||
Fix the log URL of `eas workflow:view` for a project that has a display name.
|
||||
@@ -227,6 +227,12 @@
|
||||
"project": {
|
||||
"description": "manage project"
|
||||
},
|
||||
"project:icon": {
|
||||
"description": "manage the project icon displayed on the EAS dashboard"
|
||||
},
|
||||
"project:name": {
|
||||
"description": "manage the project display name shown on the EAS dashboard"
|
||||
},
|
||||
"release": {
|
||||
"description": "manage update releases"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { getMockOclifConfig } from '../../../__tests__/commands/utils';
|
||||
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppQuery } from '../../../graphql/queries/AppQuery';
|
||||
import Log from '../../../log';
|
||||
import ProjectInfo from '../info';
|
||||
|
||||
jest.mock('../../../graphql/queries/AppQuery');
|
||||
jest.mock('../../../log');
|
||||
|
||||
const projectId = 'test-project-id';
|
||||
|
||||
async function runAndGetOutputAsync(): Promise<string> {
|
||||
const command = new ProjectInfo([], getMockOclifConfig());
|
||||
// @ts-expect-error getContextAsync is protected
|
||||
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
|
||||
projectId,
|
||||
loggedIn: { graphqlClient: {} as ExpoGraphqlClient },
|
||||
});
|
||||
await command.runAsync();
|
||||
return jest.mocked(Log.log).mock.calls.flat().join('\n');
|
||||
}
|
||||
|
||||
describe(ProjectInfo, () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.mocked(AppQuery.byIdAsync).mockResolvedValue({
|
||||
id: projectId,
|
||||
name: 'My App',
|
||||
fullName: '@jester/my-app',
|
||||
slug: 'my-app',
|
||||
} as any);
|
||||
});
|
||||
|
||||
it('prints the display name, slug and icon URL', async () => {
|
||||
jest
|
||||
.mocked(AppQuery.byIdProfileImageUrlAsync)
|
||||
.mockResolvedValue('https://example.com/icon.png');
|
||||
|
||||
const output = await runAndGetOutputAsync();
|
||||
|
||||
expect(output).toMatch(/fullName.* @jester\/my-app/);
|
||||
expect(output).toMatch(/name.* My App/);
|
||||
expect(output).toMatch(/slug.* my-app/);
|
||||
expect(output).toMatch(/icon.* https:\/\/example\.com\/icon\.png/);
|
||||
expect(output).toMatch(/ID.* test-project-id/);
|
||||
});
|
||||
|
||||
it('prints "not set" when the project has no icon', async () => {
|
||||
jest.mocked(AppQuery.byIdProfileImageUrlAsync).mockResolvedValue(null);
|
||||
|
||||
expect(await runAndGetOutputAsync()).toMatch(/icon.* not set/);
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { vol } from 'memfs';
|
||||
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppUploadSessionType } from '../../../../graphql/generated';
|
||||
import { AppQuery } from '../../../../graphql/queries/AppQuery';
|
||||
import { getPrivateExpoConfigAsync } from '../../../../project/expoConfig';
|
||||
import { uploadAppScopedFileAtPathToGCSAsync } from '../../../../uploads';
|
||||
import { sleepAsync } from '../../../../utils/promise';
|
||||
import ProjectIconSet from '../set';
|
||||
@@ -11,6 +12,7 @@ import ProjectIconSet from '../set';
|
||||
jest.mock('fs');
|
||||
jest.mock('../../../../graphql/queries/AppQuery');
|
||||
jest.mock('../../../../log');
|
||||
jest.mock('../../../../project/expoConfig');
|
||||
jest.mock('../../../../ora', () => ({
|
||||
ora: jest.fn(() => {
|
||||
const spinner = {
|
||||
@@ -74,6 +76,7 @@ describe(ProjectIconSet, () => {
|
||||
// @ts-expect-error getContextAsync is protected
|
||||
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
|
||||
projectId,
|
||||
projectDir: '/app',
|
||||
loggedIn: { graphqlClient },
|
||||
});
|
||||
return command;
|
||||
@@ -109,12 +112,51 @@ describe(ProjectIconSet, () => {
|
||||
expect(mockUploadAsync).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('uploads the icon from the app config when no path is given', async () => {
|
||||
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
|
||||
jest.mocked(getPrivateExpoConfigAsync).mockResolvedValue({
|
||||
name: 'test',
|
||||
slug: 'test-project',
|
||||
icon: './assets/icon.png',
|
||||
} as any);
|
||||
mockByIdProfileImageUrlAsync
|
||||
.mockResolvedValueOnce('https://example.com/old.png')
|
||||
.mockResolvedValueOnce('https://example.com/new.png');
|
||||
|
||||
await createCommand([]).runAsync();
|
||||
|
||||
expect(mockUploadAsync).toHaveBeenCalledWith(graphqlClient, {
|
||||
type: AppUploadSessionType.ProfileImageUpload,
|
||||
appId: projectId,
|
||||
path: '/app/assets/icon.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when no path is given and the app config has no icon', async () => {
|
||||
jest
|
||||
.mocked(getPrivateExpoConfigAsync)
|
||||
.mockResolvedValue({ name: 'test', slug: 'test-project' } as any);
|
||||
|
||||
await expect(createCommand([]).runAsync()).rejects.toThrow(
|
||||
'No local icon found in the app config'
|
||||
);
|
||||
expect(mockUploadAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws when the file does not exist', async () => {
|
||||
const command = createCommand(['/app/missing.png']);
|
||||
await expect(command.runAsync()).rejects.toThrow('No file found at /app/missing.png');
|
||||
expect(mockUploadAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws for a directory', async () => {
|
||||
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
|
||||
const command = createCommand(['/app/assets']);
|
||||
|
||||
await expect(command.runAsync()).rejects.toThrow('/app/assets is not a file.');
|
||||
expect(mockUploadAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('throws for an unsupported image format', async () => {
|
||||
vol.fromJSON({ '/app/icon.gif': 'fake-gif-bytes' });
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { getMockOclifConfig } from '../../../../__tests__/commands/utils';
|
||||
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppMutation } from '../../../../graphql/mutations/AppMutation';
|
||||
import Log from '../../../../log';
|
||||
import ProjectIconUnset from '../unset';
|
||||
|
||||
jest.mock('../../../../graphql/mutations/AppMutation');
|
||||
jest.mock('../../../../log');
|
||||
|
||||
describe(ProjectIconUnset, () => {
|
||||
it('removes the icon of the current project', async () => {
|
||||
const graphqlClient = {} as ExpoGraphqlClient;
|
||||
jest
|
||||
.mocked(AppMutation.removeProfileImageAsync)
|
||||
.mockResolvedValue({ id: 'project-123', fullName: '@test-account/test-project' });
|
||||
|
||||
const command = new ProjectIconUnset([], getMockOclifConfig());
|
||||
// @ts-expect-error getContextAsync is protected
|
||||
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
|
||||
projectId: 'project-123',
|
||||
loggedIn: { graphqlClient },
|
||||
});
|
||||
await command.runAsync();
|
||||
|
||||
expect(AppMutation.removeProfileImageAsync).toHaveBeenCalledWith(graphqlClient, 'project-123');
|
||||
expect(jest.mocked(Log.withTick).mock.calls.flat().join()).toContain(
|
||||
'@test-account/test-project'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -9,18 +9,20 @@ import Log, { link } from '../../../log';
|
||||
import { ora } from '../../../ora';
|
||||
import {
|
||||
pollForProfileImageChangeAsync,
|
||||
resolveAppConfigIconAsync,
|
||||
uploadProjectIconAsync,
|
||||
validateIconAsync,
|
||||
} from '../../../project/projectIcon';
|
||||
|
||||
export default class ProjectIconSet extends EasCommand {
|
||||
static override description = 'set the project icon displayed on the EAS dashboard';
|
||||
static override description =
|
||||
'set the project icon displayed on the EAS dashboard (requires the Admin role)';
|
||||
|
||||
static override args = {
|
||||
path: Args.string({
|
||||
required: true,
|
||||
description:
|
||||
'Path to the icon image (PNG or JPEG, at most 10 MB). Non-square images are center-cropped to a square.',
|
||||
'Path to the icon image (PNG or JPEG, at most 10 MB). The image is resized to a 1024x1024 PNG, and a non-square image is center-cropped. Defaults to the icon in the app config.',
|
||||
ignoreStdin: true,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -30,21 +32,24 @@ export default class ProjectIconSet extends EasCommand {
|
||||
|
||||
static override contextDefinition = {
|
||||
...this.ContextOptions.ProjectId,
|
||||
...this.ContextOptions.ProjectDir,
|
||||
...this.ContextOptions.LoggedIn,
|
||||
};
|
||||
|
||||
async runAsync(): Promise<void> {
|
||||
const {
|
||||
args: { path: imagePath },
|
||||
args: { path: pathArgument },
|
||||
flags,
|
||||
} = await this.parse(ProjectIconSet);
|
||||
const {
|
||||
projectId,
|
||||
projectDir,
|
||||
loggedIn: { graphqlClient },
|
||||
} = await this.getContextAsync(ProjectIconSet, {
|
||||
nonInteractive: flags['non-interactive'],
|
||||
});
|
||||
|
||||
const imagePath = pathArgument ?? (await getAppConfigIconPathAsync(projectDir));
|
||||
await validateIconAsync(imagePath);
|
||||
|
||||
const app = await AppQuery.byIdAsync(graphqlClient, projectId);
|
||||
@@ -74,3 +79,14 @@ export default class ProjectIconSet extends EasCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getAppConfigIconPathAsync(projectDir: string): Promise<string> {
|
||||
const icon = await resolveAppConfigIconAsync(projectDir);
|
||||
if (!icon) {
|
||||
throw new Error(
|
||||
'No local icon found in the app config (icon, ios.icon, android.adaptiveIcon.foregroundImage or android.icon). Pass the path to an image instead.'
|
||||
);
|
||||
}
|
||||
Log.log(`Using "${icon.field}" from your app config: ${icon.path}`);
|
||||
return icon.path;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import chalk from 'chalk';
|
||||
|
||||
import EasCommand from '../../../commandUtils/EasCommand';
|
||||
import { EASNonInteractiveFlag } from '../../../commandUtils/flags';
|
||||
import { AppMutation } from '../../../graphql/mutations/AppMutation';
|
||||
import Log from '../../../log';
|
||||
|
||||
export default class ProjectIconUnset extends EasCommand {
|
||||
static override description =
|
||||
'remove the project icon displayed on the EAS dashboard (requires the Admin role)';
|
||||
|
||||
static override flags = {
|
||||
...EASNonInteractiveFlag,
|
||||
};
|
||||
|
||||
static override contextDefinition = {
|
||||
...this.ContextOptions.ProjectId,
|
||||
...this.ContextOptions.LoggedIn,
|
||||
};
|
||||
|
||||
async runAsync(): Promise<void> {
|
||||
const { flags } = await this.parse(ProjectIconUnset);
|
||||
const {
|
||||
projectId,
|
||||
loggedIn: { graphqlClient },
|
||||
} = await this.getContextAsync(ProjectIconUnset, {
|
||||
nonInteractive: flags['non-interactive'],
|
||||
});
|
||||
|
||||
const { fullName } = await AppMutation.removeProfileImageAsync(graphqlClient, projectId);
|
||||
Log.withTick(`${chalk.bold(fullName)} now has no icon`);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,8 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import EasCommand from '../../commandUtils/EasCommand';
|
||||
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { withErrorHandlingAsync } from '../../graphql/client';
|
||||
import { AppInfoQuery, AppInfoQueryVariables } from '../../graphql/generated';
|
||||
import { AppQuery } from '../../graphql/queries/AppQuery';
|
||||
import Log from '../../log';
|
||||
import formatFields from '../../utils/formatFields';
|
||||
|
||||
async function projectInfoByIdAsync(
|
||||
graphqlClient: ExpoGraphqlClient,
|
||||
appId: string
|
||||
): Promise<AppInfoQuery> {
|
||||
const data = await withErrorHandlingAsync(
|
||||
graphqlClient
|
||||
.query<AppInfoQuery, AppInfoQueryVariables>(
|
||||
gql`
|
||||
query AppInfo($appId: String!) {
|
||||
app {
|
||||
byId(appId: $appId) {
|
||||
id
|
||||
fullName
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ appId },
|
||||
{ additionalTypenames: ['App'] }
|
||||
)
|
||||
.toPromise()
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export default class ProjectInfo extends EasCommand {
|
||||
static override description = 'information about the current project';
|
||||
|
||||
@@ -49,15 +19,18 @@ export default class ProjectInfo extends EasCommand {
|
||||
nonInteractive: true,
|
||||
});
|
||||
|
||||
const { app } = await projectInfoByIdAsync(graphqlClient, projectId);
|
||||
if (!app) {
|
||||
throw new Error(`Could not find project with id: ${projectId}`);
|
||||
}
|
||||
const [app, iconUrl] = await Promise.all([
|
||||
AppQuery.byIdAsync(graphqlClient, projectId),
|
||||
AppQuery.byIdProfileImageUrlAsync(graphqlClient, projectId),
|
||||
]);
|
||||
|
||||
Log.addNewLineIfNone();
|
||||
Log.log(
|
||||
formatFields([
|
||||
{ label: 'fullName', value: app.byId.fullName },
|
||||
{ label: 'fullName', value: app.fullName },
|
||||
{ label: 'name', value: app.name },
|
||||
{ label: 'slug', value: app.slug },
|
||||
{ label: 'icon', value: iconUrl ?? 'not set' },
|
||||
{ label: 'ID', value: projectId },
|
||||
])
|
||||
);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { getMockOclifConfig } from '../../../../__tests__/commands/utils';
|
||||
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppMutation } from '../../../../graphql/mutations/AppMutation';
|
||||
import { getPrivateExpoConfigAsync } from '../../../../project/expoConfig';
|
||||
import ProjectNameSet from '../set';
|
||||
|
||||
jest.mock('../../../../graphql/mutations/AppMutation');
|
||||
jest.mock('../../../../log');
|
||||
jest.mock('../../../../project/expoConfig');
|
||||
|
||||
const graphqlClient = {} as ExpoGraphqlClient;
|
||||
const mockSetDisplayNameAsync = jest.mocked(AppMutation.setDisplayNameAsync);
|
||||
|
||||
async function runAsync(argv: string[]): Promise<void> {
|
||||
const command = new ProjectNameSet(argv, getMockOclifConfig());
|
||||
// @ts-expect-error getContextAsync is protected
|
||||
jest.spyOn(command, 'getContextAsync').mockResolvedValue({
|
||||
projectId: 'project-123',
|
||||
projectDir: '/app',
|
||||
loggedIn: { graphqlClient },
|
||||
});
|
||||
await command.runAsync();
|
||||
}
|
||||
|
||||
describe(ProjectNameSet, () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockSetDisplayNameAsync.mockResolvedValue({
|
||||
id: 'project-123',
|
||||
name: 'My App',
|
||||
fullName: '@test-account/my-app',
|
||||
});
|
||||
jest
|
||||
.mocked(getPrivateExpoConfigAsync)
|
||||
.mockResolvedValue({ name: 'Config Name', slug: 'my-app' } as any);
|
||||
});
|
||||
|
||||
it('sets the given display name, trimmed', async () => {
|
||||
await runAsync([' My App ']);
|
||||
|
||||
expect(mockSetDisplayNameAsync).toHaveBeenCalledWith(graphqlClient, {
|
||||
appId: 'project-123',
|
||||
displayName: 'My App',
|
||||
});
|
||||
});
|
||||
|
||||
it('uses the name from the app config when no name is given', async () => {
|
||||
await runAsync([]);
|
||||
|
||||
expect(mockSetDisplayNameAsync).toHaveBeenCalledWith(graphqlClient, {
|
||||
appId: 'project-123',
|
||||
displayName: 'Config Name',
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects a blank name', async () => {
|
||||
await expect(runAsync([' '])).rejects.toThrow('The display name cannot be blank.');
|
||||
expect(mockSetDisplayNameAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Args } from '@oclif/core';
|
||||
import chalk from 'chalk';
|
||||
|
||||
import EasCommand from '../../../commandUtils/EasCommand';
|
||||
import { EASNonInteractiveFlag } from '../../../commandUtils/flags';
|
||||
import { AppMutation } from '../../../graphql/mutations/AppMutation';
|
||||
import Log from '../../../log';
|
||||
import { getPrivateExpoConfigAsync } from '../../../project/expoConfig';
|
||||
|
||||
export default class ProjectNameSet extends EasCommand {
|
||||
static override description =
|
||||
'set the project display name shown on the EAS dashboard (does not change the slug)';
|
||||
|
||||
static override args = {
|
||||
name: Args.string({
|
||||
description: 'Display name, at most 255 characters. Defaults to the name in the app config.',
|
||||
ignoreStdin: true,
|
||||
}),
|
||||
};
|
||||
|
||||
static override flags = {
|
||||
...EASNonInteractiveFlag,
|
||||
};
|
||||
|
||||
static override contextDefinition = {
|
||||
...this.ContextOptions.ProjectId,
|
||||
...this.ContextOptions.ProjectDir,
|
||||
...this.ContextOptions.LoggedIn,
|
||||
};
|
||||
|
||||
async runAsync(): Promise<void> {
|
||||
const {
|
||||
args: { name: nameArgument },
|
||||
flags,
|
||||
} = await this.parse(ProjectNameSet);
|
||||
const {
|
||||
projectId,
|
||||
projectDir,
|
||||
loggedIn: { graphqlClient },
|
||||
} = await this.getContextAsync(ProjectNameSet, {
|
||||
nonInteractive: flags['non-interactive'],
|
||||
});
|
||||
|
||||
const displayName = (nameArgument ?? (await getPrivateExpoConfigAsync(projectDir)).name).trim();
|
||||
if (!displayName) {
|
||||
throw new Error('The display name cannot be blank.');
|
||||
}
|
||||
|
||||
const app = await AppMutation.setDisplayNameAsync(graphqlClient, {
|
||||
appId: projectId,
|
||||
displayName,
|
||||
});
|
||||
Log.withTick(`Set the display name of ${chalk.bold(app.fullName)} to ${chalk.bold(app.name)}`);
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ export default class WorkflowView extends EasCommand {
|
||||
|
||||
result.logURL = getWorkflowRunUrl(
|
||||
result.workflow.app.ownerAccount.name,
|
||||
result.workflow.app.name,
|
||||
result.workflow.app.slug,
|
||||
result.id
|
||||
);
|
||||
|
||||
|
||||
+15
-7
@@ -14976,13 +14976,6 @@ export type ResumeUpdateChannelMutationVariables = Exact<{
|
||||
|
||||
export type ResumeUpdateChannelMutation = { __typename?: 'RootMutation', updateChannel: { __typename?: 'UpdateChannelMutation', resumeUpdateChannel: { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string, isProtected: boolean } } };
|
||||
|
||||
export type AppInfoQueryVariables = Exact<{
|
||||
appId: Scalars['String']['input'];
|
||||
}>;
|
||||
|
||||
|
||||
export type AppInfoQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, fullName: string } } };
|
||||
|
||||
export type CreateAndroidAppBuildCredentialsMutationVariables = Exact<{
|
||||
androidAppBuildCredentialsInput: AndroidAppBuildCredentialsInput;
|
||||
androidAppCredentialsId: Scalars['ID']['input'];
|
||||
@@ -15524,6 +15517,21 @@ export type ScheduleAppDeletionMutationVariables = Exact<{
|
||||
|
||||
export type ScheduleAppDeletionMutation = { __typename?: 'RootMutation', app?: { __typename?: 'AppMutation', scheduleAppDeletion: { __typename?: 'BackgroundJobReceipt', id: string, state: BackgroundJobState, tries: number, willRetry: boolean, resultId?: string | null, resultType: BackgroundJobResultType, resultData?: any | null, errorCode?: string | null, errorMessage?: string | null, createdAt: any, updatedAt: any } } | null };
|
||||
|
||||
export type RemoveProfileImageMutationVariables = Exact<{
|
||||
appId: Scalars['ID']['input'];
|
||||
}>;
|
||||
|
||||
|
||||
export type RemoveProfileImageMutation = { __typename?: 'RootMutation', app?: { __typename?: 'AppMutation', removeProfileImage: { __typename?: 'App', id: string, fullName: string } } | null };
|
||||
|
||||
export type SetAppDisplayNameMutationVariables = Exact<{
|
||||
appId: Scalars['ID']['input'];
|
||||
appInfo: AppInfoInput;
|
||||
}>;
|
||||
|
||||
|
||||
export type SetAppDisplayNameMutation = { __typename?: 'RootMutation', app?: { __typename?: 'AppMutation', setAppInfo: { __typename?: 'App', id: string, name: string, fullName: string } } | null };
|
||||
|
||||
export type CreateAppVersionMutationVariables = Exact<{
|
||||
appVersionInput: AppVersionInput;
|
||||
}>;
|
||||
|
||||
@@ -7,8 +7,12 @@ import {
|
||||
BackgroundJobReceiptDataFragment,
|
||||
CreateAppMutation,
|
||||
CreateAppMutationVariables,
|
||||
RemoveProfileImageMutation,
|
||||
RemoveProfileImageMutationVariables,
|
||||
ScheduleAppDeletionMutation,
|
||||
ScheduleAppDeletionMutationVariables,
|
||||
SetAppDisplayNameMutation,
|
||||
SetAppDisplayNameMutationVariables,
|
||||
} from '../generated';
|
||||
import { BackgroundJobReceiptNode } from '../types/BackgroundJobReceipt';
|
||||
|
||||
@@ -68,4 +72,57 @@ export const AppMutation = {
|
||||
assert(receipt, 'Background job receipt must be defined');
|
||||
return receipt;
|
||||
},
|
||||
async removeProfileImageAsync(
|
||||
graphqlClient: ExpoGraphqlClient,
|
||||
appId: string
|
||||
): Promise<{ id: string; fullName: string }> {
|
||||
const data = await withErrorHandlingAsync(
|
||||
graphqlClient
|
||||
.mutation<RemoveProfileImageMutation, RemoveProfileImageMutationVariables>(
|
||||
gql`
|
||||
mutation RemoveProfileImageMutation($appId: ID!) {
|
||||
app {
|
||||
removeProfileImage(appId: $appId) {
|
||||
id
|
||||
fullName
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ appId },
|
||||
{ additionalTypenames: ['App'] }
|
||||
)
|
||||
.toPromise()
|
||||
);
|
||||
const app = data.app?.removeProfileImage;
|
||||
assert(app, 'App must be defined');
|
||||
return app;
|
||||
},
|
||||
async setDisplayNameAsync(
|
||||
graphqlClient: ExpoGraphqlClient,
|
||||
{ appId, displayName }: { appId: string; displayName: string }
|
||||
): Promise<{ id: string; name: string; fullName: string }> {
|
||||
const data = await withErrorHandlingAsync(
|
||||
graphqlClient
|
||||
.mutation<SetAppDisplayNameMutation, SetAppDisplayNameMutationVariables>(
|
||||
gql`
|
||||
mutation SetAppDisplayNameMutation($appId: ID!, $appInfo: AppInfoInput!) {
|
||||
app {
|
||||
setAppInfo(appId: $appId, appInfo: $appInfo) {
|
||||
id
|
||||
name
|
||||
fullName
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{ appId, appInfo: { displayName } },
|
||||
{ additionalTypenames: ['App'] }
|
||||
)
|
||||
.toPromise()
|
||||
);
|
||||
const app = data.app?.setAppInfo;
|
||||
assert(app, 'App must be defined');
|
||||
return app;
|
||||
},
|
||||
};
|
||||
@@ -4,6 +4,7 @@ import { getPrivateExpoConfigAsync } from '../expoConfig';
|
||||
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
|
||||
import { AppUploadSessionType } from '../../graphql/generated';
|
||||
import { AppQuery } from '../../graphql/queries/AppQuery';
|
||||
import Log from '../../log';
|
||||
import { uploadAppScopedFileAtPathToGCSAsync } from '../../uploads';
|
||||
import { maybeSetProjectIconFromAppConfigAsync, resolveAppConfigIconAsync } from '../projectIcon';
|
||||
|
||||
@@ -67,6 +68,48 @@ describe(resolveAppConfigIconAsync, () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('prefers a supported image over an earlier icon in an unsupported format', async () => {
|
||||
vol.fromJSON({
|
||||
'/app/assets/app.icon/icon.json': '{}',
|
||||
'/app/assets/foreground.png': 'fake-png-bytes',
|
||||
});
|
||||
mockAppConfig({
|
||||
ios: { icon: './assets/app.icon' },
|
||||
android: { adaptiveIcon: { foregroundImage: './assets/foreground.png' } },
|
||||
});
|
||||
|
||||
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
|
||||
field: 'android.adaptiveIcon.foregroundImage',
|
||||
path: '/app/assets/foreground.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('prefers an image within the size limit over an earlier icon that is too large', async () => {
|
||||
vol.fromJSON({
|
||||
'/app/assets/icon.png': 'x'.repeat(10 * 1024 * 1024 + 1),
|
||||
'/app/assets/ios-icon.png': 'fake-png-bytes',
|
||||
});
|
||||
mockAppConfig({ icon: './assets/icon.png', ios: { icon: './assets/ios-icon.png' } });
|
||||
|
||||
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
|
||||
field: 'ios.icon',
|
||||
path: '/app/assets/ios-icon.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('prefers an image file over an earlier icon that is a directory', async () => {
|
||||
vol.fromJSON({
|
||||
'/app/assets/icon.png/contents.json': '{}',
|
||||
'/app/assets/ios-icon.png': 'fake-png-bytes',
|
||||
});
|
||||
mockAppConfig({ icon: './assets/icon.png', ios: { icon: './assets/ios-icon.png' } });
|
||||
|
||||
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
|
||||
field: 'ios.icon',
|
||||
path: '/app/assets/ios-icon.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to the Android adaptive icon foreground', async () => {
|
||||
vol.fromJSON({ '/app/assets/foreground.png': 'fake-png-bytes' });
|
||||
mockAppConfig({
|
||||
@@ -79,6 +122,16 @@ describe(resolveAppConfigIconAsync, () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to the Android icon', async () => {
|
||||
vol.fromJSON({ '/app/assets/android-icon.png': 'fake-png-bytes' });
|
||||
mockAppConfig({ android: { icon: './assets/android-icon.png' } });
|
||||
|
||||
await expect(resolveAppConfigIconAsync(projectDir)).resolves.toEqual({
|
||||
field: 'android.icon',
|
||||
path: '/app/assets/android-icon.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores a remote icon URL', async () => {
|
||||
mockAppConfig({ icon: 'https://example.com/icon.png' });
|
||||
|
||||
@@ -126,6 +179,7 @@ describe(maybeSetProjectIconFromAppConfigAsync, () => {
|
||||
maybeSetProjectIconFromAppConfigAsync(graphqlClient, { projectId, projectDir })
|
||||
).resolves.toEqual({ status: 'skipped', reason: 'icon-already-set' });
|
||||
expect(mockUploadAsync).not.toHaveBeenCalled();
|
||||
expect(jest.mocked(Log.log).mock.calls.flat().join()).toContain('eas project:icon:set');
|
||||
});
|
||||
|
||||
it('skips without a server round-trip when the app config has no icon', async () => {
|
||||
@@ -158,6 +212,17 @@ describe(maybeSetProjectIconFromAppConfigAsync, () => {
|
||||
expect(mockUploadAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not propagate a failure to read the current icon', async () => {
|
||||
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
|
||||
mockAppConfig({ icon: './assets/icon.png' });
|
||||
mockByIdProfileImageUrlAsync.mockRejectedValue(new Error('timeout'));
|
||||
|
||||
await expect(
|
||||
maybeSetProjectIconFromAppConfigAsync(graphqlClient, { projectId, projectDir })
|
||||
).resolves.toEqual({ status: 'skipped', reason: 'upload-failed' });
|
||||
expect(mockUploadAsync).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not propagate an upload failure', async () => {
|
||||
vol.fromJSON({ '/app/assets/icon.png': 'fake-png-bytes' });
|
||||
mockAppConfig({ icon: './assets/icon.png' });
|
||||
|
||||
@@ -52,13 +52,13 @@ export async function maybeSetProjectIconFromAppConfigAsync(
|
||||
return { status: 'skipped', reason: 'invalid-icon' };
|
||||
}
|
||||
|
||||
const existingIconUrl = await AppQuery.byIdProfileImageUrlAsync(graphqlClient, projectId);
|
||||
if (existingIconUrl) {
|
||||
Log.debug('The project already has an icon, skipping the icon from the app config.');
|
||||
return { status: 'skipped', reason: 'icon-already-set' };
|
||||
}
|
||||
|
||||
try {
|
||||
if (await AppQuery.byIdProfileImageUrlAsync(graphqlClient, projectId)) {
|
||||
Log.log(
|
||||
`The project already has an icon. To replace it with "${icon.field}" from your app config, run ${chalk.bold('eas project:icon:set')}.`
|
||||
);
|
||||
return { status: 'skipped', reason: 'icon-already-set' };
|
||||
}
|
||||
await uploadProjectIconAsync(graphqlClient, { projectId, imagePath: icon.path });
|
||||
} catch (error: any) {
|
||||
Log.warn(`Failed to set the project icon from "${icon.field}": ${error.message}`);
|
||||
@@ -88,16 +88,24 @@ export async function resolveAppConfigIconAsync(projectDir: string): Promise<App
|
||||
['icon', exp.icon],
|
||||
['ios.icon', exp.ios?.icon],
|
||||
['android.adaptiveIcon.foregroundImage', exp.android?.adaptiveIcon?.foregroundImage],
|
||||
['android.icon', exp.android?.icon],
|
||||
];
|
||||
|
||||
let firstInvalidIcon: AppConfigIcon | null = null;
|
||||
for (const [field, value] of candidates) {
|
||||
const iconPath = resolveLocalIconPath(projectDir, value);
|
||||
if (iconPath && (await fs.pathExists(iconPath))) {
|
||||
return { field, path: iconPath };
|
||||
const icon = { field, path: iconPath };
|
||||
try {
|
||||
await validateIconAsync(iconPath);
|
||||
return icon;
|
||||
} catch {
|
||||
firstInvalidIcon ??= icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return firstInvalidIcon;
|
||||
}
|
||||
|
||||
function resolveLocalIconPath(projectDir: string, value: unknown): string | null {
|
||||
@@ -123,13 +131,17 @@ export async function validateIconAsync(imagePath: string): Promise<void> {
|
||||
if (!(await fs.pathExists(imagePath))) {
|
||||
throw new Error(`No file found at ${imagePath}`);
|
||||
}
|
||||
const stat = await fs.stat(imagePath);
|
||||
if (!stat.isFile()) {
|
||||
throw new Error(`${imagePath} is not a file.`);
|
||||
}
|
||||
const extension = path.extname(imagePath).toLowerCase();
|
||||
if (!ALLOWED_EXTENSIONS.includes(extension)) {
|
||||
throw new Error(
|
||||
`Unsupported image format "${extension}". The icon must be a PNG or JPEG file.`
|
||||
);
|
||||
}
|
||||
const { size } = await fs.stat(imagePath);
|
||||
const { size } = stat;
|
||||
if (size > MAX_IMAGE_SIZE_BYTES) {
|
||||
throw new Error(
|
||||
`The image is ${(size / 1024 / 1024).toFixed(1)} MB, but the maximum allowed size is 10 MB.`
|
||||
|
||||
Reference in new issue
Block a user