|
| 1 | +// @ts-check |
| 2 | +const { withMod } = require("@expo/config-plugins"); |
| 3 | + |
| 4 | +/** |
| 5 | + * @typedef {import("@expo/config-plugins").ExportedConfig} ExportedConfig |
| 6 | + * @typedef {import("@expo/config-plugins").ExportedConfigWithProps} ExportedConfigWithProps |
| 7 | + * @typedef {import("@expo/config-plugins").Mod} Mod |
| 8 | + * @typedef {import("@expo/config-plugins").ModConfig} ModConfig |
| 9 | + * @typedef {ExportedConfigWithProps & { macos?: { infoPlist?: Record<string, unknown> }}} ExportedConfigWithPropsMac |
| 10 | + */ |
| 11 | + |
| 12 | +const macosPlatform = /** @type {keyof ModConfig} */ ("macos"); |
| 13 | + |
| 14 | +/** |
| 15 | + * Provides the `ReactNativeHost` file for modification. |
| 16 | + * @param {ExportedConfig} config Exported config |
| 17 | + * @param {Mod} action Method to run on the mod when the config is compiled |
| 18 | + * @returns {ExportedConfig} Modified config |
| 19 | + */ |
| 20 | +function withReactNativeHost(config, action) { |
| 21 | + return withMod(config, { |
| 22 | + platform: macosPlatform, |
| 23 | + mod: "reactNativeHost", |
| 24 | + action, |
| 25 | + }); |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * Provides the `AppDelegate` file for modification. |
| 30 | + * @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L101} |
| 31 | + * @param {ExportedConfig} config Exported config |
| 32 | + * @param {Mod} action Method to run on the mod when the config is compiled |
| 33 | + * @returns {ExportedConfig} Modified config |
| 34 | + */ |
| 35 | +function withAppDelegate(config, action) { |
| 36 | + return withMod(config, { |
| 37 | + platform: macosPlatform, |
| 38 | + mod: "appDelegate", |
| 39 | + action, |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * Provides the `Info.plist` file for modification. |
| 45 | + * @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L116} |
| 46 | + * @param {ExportedConfig} config Exported config |
| 47 | + * @param {Mod} action Method to run on the mod when the config is compiled |
| 48 | + * @returns {ExportedConfig} Modified config |
| 49 | + */ |
| 50 | +function withInfoPlist(config, action) { |
| 51 | + return withMod(config, { |
| 52 | + platform: macosPlatform, |
| 53 | + mod: "infoPlist", |
| 54 | + async action(cfg) { |
| 55 | + /** @type {ExportedConfigWithPropsMac} */ |
| 56 | + const config = await action(cfg); |
| 57 | + if (!config.macos) { |
| 58 | + config.macos = {}; |
| 59 | + } |
| 60 | + config.macos.infoPlist = config.modResults; |
| 61 | + return config; |
| 62 | + }, |
| 63 | + }); |
| 64 | +} |
| 65 | + |
| 66 | +/** |
| 67 | + * Provides the main `.xcodeproj` for modification. |
| 68 | + * @see {@link https://github.com/expo/expo/blob/sdk-51/packages/%40expo/config-plugins/src/plugins/ios-plugins.ts#L173} |
| 69 | + * @param {ExportedConfig} config Exported config |
| 70 | + * @param {Mod} action Method to run on the mod when the config is compiled |
| 71 | + * @returns {ExportedConfig} Modified config |
| 72 | + */ |
| 73 | +function withXcodeProject(config, action) { |
| 74 | + return withMod(config, { |
| 75 | + platform: macosPlatform, |
| 76 | + mod: "xcodeproj", |
| 77 | + action, |
| 78 | + }); |
| 79 | +} |
| 80 | + |
| 81 | +exports.withAppDelegate = withAppDelegate; |
| 82 | +exports.withInfoPlist = withInfoPlist; |
| 83 | +exports.withXcodeProject = withXcodeProject; |
| 84 | +exports.withReactNativeHost = withReactNativeHost; |
0 commit comments