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

Commit

Permalink
[expo-cli] add option to assign created push key to current project (#…
Browse files Browse the repository at this point in the history
…3098)

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

* new CreateAndAssignIosPush action
  • Loading branch information
cruzach authored Jan 21, 2021
1 parent 825f5e4 commit 9485c82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
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();

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

0 comments on commit 9485c82

Please sign in to comment.