Skip to content

Commit

Permalink
Improve entitlement generation
Browse files Browse the repository at this point in the history
  • Loading branch information
bndkt committed Aug 16, 2022
1 parent 9881f70 commit dd56d06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-app-clip",
"version": "0.0.23",
"version": "0.0.24",
"description": "Config plugin to add an App Clip to a React Native iOS app",
"homepage": "https://github.com/bndkt/react-native-app-clip#readme",
"main": "build/withIosAppClip.js",
Expand Down
37 changes: 21 additions & 16 deletions src/withAppClipAppConfig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import { ConfigPlugin, InfoPlist } from "@expo/config-plugins";
import { ExpoConfig } from "@expo/config-types";

import { getAppClipBundleIdentifier, getAppClipFolder } from "./withIosAppClip";

export const getAppClipEntitlements = (iosConfig: ExpoConfig["ios"]) => {
const appBundleIdentifier = iosConfig!.bundleIdentifier!;
const entitlements: InfoPlist = {
"com.apple.developer.parent-application-identifiers": [
`$(AppIdentifierPrefix)${appBundleIdentifier}`,
],
"com.apple.developer.on-demand-install-capable": true,
};

iosConfig?.usesAppleSignIn &&
(entitlements["com.apple.developer.applesignin"] = ["Default"]);

iosConfig?.associatedDomains &&
(entitlements["com.apple.developer.associated-domains"] =
iosConfig.associatedDomains);

return entitlements;
};

export const withAppClipAppConfig: ConfigPlugin = (config) => {
const appBundleIdentifier = config.ios!.bundleIdentifier!;
const appClipName = getAppClipFolder(config.name);
const appClipBundleIdentifier = getAppClipBundleIdentifier(
config.ios!.bundleIdentifier!
Expand All @@ -16,20 +35,6 @@ export const withAppClipAppConfig: ConfigPlugin = (config) => {
}
);

const newEntitlements: InfoPlist = {
"com.apple.developer.parent-application-identifiers": [
`${appBundleIdentifier}`,
],
"com.apple.developer.on-demand-install-capable": true,
};

config.ios!.usesAppleSignIn &&
(newEntitlements["com.apple.developer.applesignin"] = ["Default"]);

config.ios!.associatedDomains &&
(newEntitlements["com.apple.developer.associated-domains"] =
config.ios!.associatedDomains);

if (!appClipConfigIndex) {
config.extra = {
...config.extra,
Expand Down Expand Up @@ -63,7 +68,7 @@ export const withAppClipAppConfig: ConfigPlugin = (config) => {

appClipConfig.entitlements = {
...appClipConfig.entitlements,
...newEntitlements,
...getAppClipEntitlements(config.ios),
};
}

Expand Down
16 changes: 4 additions & 12 deletions src/withAppClipEntitlements.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import {
ConfigPlugin,
InfoPlist,
withDangerousMod,
} from "@expo/config-plugins";
import { ConfigPlugin, withDangerousMod } from "@expo/config-plugins";
import plist from "@expo/plist";
import * as fs from "fs";
import * as path from "path";
import { getAppClipEntitlements } from "./withAppClipAppConfig";

import { getAppClipFolder } from "./withIosAppClip";

export const withAppClipEntitlements: ConfigPlugin = (config) => {
return withDangerousMod(config, [
"ios",
async (config) => {
const bundleIdentifier = config.ios!.bundleIdentifier!;
const appClipFolderName = getAppClipFolder(
config.modRequest.projectName!
);
Expand All @@ -26,14 +22,10 @@ export const withAppClipEntitlements: ConfigPlugin = (config) => {
`${appClipFolderName}.entitlements`
);

const appClipPlist: InfoPlist = {
"com.apple.developer.parent-application-identifiers": [
`$(AppIdentifierPrefix)${bundleIdentifier}`,
],
};
const appClipEntitlements = getAppClipEntitlements(config.ios);

await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
await fs.promises.writeFile(filePath, plist.build(appClipPlist));
await fs.promises.writeFile(filePath, plist.build(appClipEntitlements));

return config;
},
Expand Down

0 comments on commit dd56d06

Please sign in to comment.