Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[expo-cli] add option to assign created push key to current project #3098

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/expo-cli/src/credentials/views/IosPushCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class CreateIosPush implements IView {
log('Successfully created Push Notification Key\n');
displayIosUserCredentials(pushKey);
log();

Copy link
Contributor

@wkozyra95 wkozyra95 Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action is called from other places e.g. as part of the setup before build where this behaviour would not be correct.

This was intended to simple CRUD action that results in the creation of a new push key, if the intention is that ensuring valid push key is assigned to the app then logic for that should be different and is already present in build command.

If it's unclear that this command won't assign dist cert to the app then maybe it's better to add some warnings. If you want to modify this action without affecting build command then create new action that is using CreateIosPush class.

async open(ctx: Context): Promise<> {
  await runCredentialsManager(ctx, new CreateIosPush(accountName));
  // some code you want to add
}

and replace it here https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/credentials/views/Select.ts#L93

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, thanks for catching that

Changed it and created a new class that extends CreateIosPush instead - dcae9ca

return null;
}

Expand Down Expand Up @@ -74,6 +75,40 @@ export class CreateIosPush implements IView {
}
}

export class CreateAndAssignIosPush extends CreateIosPush {
async open(ctx: Context): Promise<IView | null> {
const pushKey = await super.create(ctx);

log('Successfully created Push Notification Key\n');
displayIosUserCredentials(pushKey);
log();

if (ctx.hasProjectContext && pushKey) {
await this.assignToCurrentProject(ctx, pushKey.id);
log();
}

return null;
}

async assignToCurrentProject(ctx: Context, pushKeyId: number) {
const experienceName = `@${ctx.projectOwner}/${ctx.manifest.slug}`;
const bundleIdentifier = ctx.manifest?.ios?.bundleIdentifier;
if (!ctx.nonInteractive && bundleIdentifier) {
const confirm = await confirmAsync({
message: `Would you like to use this push key for the current project: ${experienceName} (${bundleIdentifier})?`,
});
if (!confirm) {
return;
}

const app = getAppLookupParams(experienceName, bundleIdentifier);
await ctx.ios.usePushKey(app, pushKeyId);
log(chalk.green(`Successfully assigned Push Key to ${experienceName} (${bundleIdentifier})`));
}
}
}

export class RemoveIosPush implements IView {
constructor(private accountName: string, private shouldRevoke: boolean = false) {}

Expand Down
2 changes: 1 addition & 1 deletion packages/expo-cli/src/credentials/views/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class SelectIosExperience implements IView {
handleAction(ctx: Context, accountName: string, action: string): IView | null {
switch (action) {
case 'create-ios-push':
return new iosPushView.CreateIosPush(accountName);
return new iosPushView.CreateAndAssignIosPush(accountName);
case 'update-ios-push':
return new iosPushView.UpdateIosPush(accountName);
case 'remove-ios-push':
Expand Down