From e21e892a25df137b8060b8baa24251e24d727b94 Mon Sep 17 00:00:00 2001 From: Matt Hayashida Date: Tue, 14 May 2024 15:30:21 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Add=20support=20for=20EAS=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://docs.expo.dev/build-reference/app-extensions/ --- plugin/src/helpers.ts | 13 ++++++++ plugin/src/withIosAppcuesRichPush.ts | 45 +++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 plugin/src/helpers.ts diff --git a/plugin/src/helpers.ts b/plugin/src/helpers.ts new file mode 100644 index 0000000..ff11441 --- /dev/null +++ b/plugin/src/helpers.ts @@ -0,0 +1,13 @@ +export function safeSet(obj: any, key: string, value: any) { + const segments = key.split('.'); + const last = segments.pop(); + segments.forEach((segment) => { + if (!obj[segment]) { + obj[segment] = {}; + } + obj = obj[segment]; + }); + obj[last!] = value; + + return obj; +} diff --git a/plugin/src/withIosAppcuesRichPush.ts b/plugin/src/withIosAppcuesRichPush.ts index f456519..c5d76d2 100644 --- a/plugin/src/withIosAppcuesRichPush.ts +++ b/plugin/src/withIosAppcuesRichPush.ts @@ -5,6 +5,7 @@ import { } from 'expo/config-plugins'; import fs from 'fs'; +import { safeSet } from './helpers'; import { APPCUES_NSE_TARGET, BUNDLE_SHORT_VERSION_TEMPLATE_REGEX, @@ -139,14 +140,55 @@ const withAppcuesXcodeProject: ConfigPlugin = (config, props) => { target.uuid ); + const quotedTargetName = `"${APPCUES_NSE_TARGET.NAME}"`; + // Fix "Value for SWIFT_VERSION cannot be empty." const swiftVersion = xcodeProject.getBuildProperty('SWIFT_VERSION'); - xcodeProject.addBuildProperty('SWIFT_VERSION', swiftVersion); + xcodeProject.updateBuildProperty( + 'SWIFT_VERSION', + swiftVersion, + null, // want both Debug and Release, so don't specify either + quotedTargetName + ); + + // Set Automatic code signing. + xcodeProject.updateBuildProperty( + 'CODE_SIGN_STYLE', + 'Automatic', + null, // want both Debug and Release, so don't specify either + quotedTargetName + ); return config; }); }; +const withEasTargets: ConfigPlugin = (config, props) => { + if (!config.ios?.bundleIdentifier) { + throw new Error(`Missing 'ios.bundleIdentifier' in app config.`); + } + + safeSet(config, 'extra.eas.build.experimental.ios.appExtensions', []); + + const index = + config.extra!.eas.build.experimental.ios.appExtensions.findIndex( + (ext: any) => ext.targetName === APPCUES_NSE_TARGET.NAME + ); + + const extConfig = { + targetName: APPCUES_NSE_TARGET.NAME, + bundleIdentifier: `${config?.ios?.bundleIdentifier}.${APPCUES_NSE_TARGET.NAME}`, + }; + + if (index > -1) { + config.extra!.eas.build.experimental.ios.appExtensions[index] = extConfig; + } else { + config.extra!.eas.build.experimental.ios.appExtensions.push(extConfig); + } + + return config; +}; + export const withIosAppcuesRichPush: ConfigPlugin = ( config, props @@ -154,5 +196,6 @@ export const withIosAppcuesRichPush: ConfigPlugin = ( config = withAppcuesXcodeProject(config, props); config = withAppcuesFiles(config, props); config = withAppcuesPodfile(config, props); + config = withEasTargets(config, props); return config; };