|
| 1 | +import { ExpoConfig } from 'expo/config'; |
| 2 | +import { |
| 3 | + ExportedConfigWithProps, |
| 4 | + Mod, |
| 5 | + ModPlatform, |
| 6 | + ModProps, |
| 7 | +} from 'expo/config-plugins'; |
| 8 | + |
| 9 | +// Extend ExpoConfig to include mods |
| 10 | +export interface ConfigWithMods extends ExpoConfig { |
| 11 | + mods?: { |
| 12 | + [key in ModPlatform]?: { |
| 13 | + [key in string]?: Mod<any>; |
| 14 | + }; |
| 15 | + }; |
| 16 | +} |
| 17 | + |
| 18 | +// Type for the result of withIterable |
| 19 | +export type WithIterableResult = ConfigWithMods & { |
| 20 | + mods: { |
| 21 | + ios: { |
| 22 | + infoPlist: Mod<Record<string, any>>; |
| 23 | + entitlements: Mod<Record<string, any>>; |
| 24 | + podfile: Mod<Record<string, any>>; |
| 25 | + dangerous: Mod<Record<string, any>>; |
| 26 | + xcodeproj: Mod<any>; |
| 27 | + }; |
| 28 | + android: { |
| 29 | + manifest: Mod<Record<string, any>>; |
| 30 | + projectBuildGradle: Mod<Record<string, any>>; |
| 31 | + appBuildGradle: Mod<Record<string, any>>; |
| 32 | + dangerous: Mod<Record<string, any>>; |
| 33 | + }; |
| 34 | + }; |
| 35 | +}; |
| 36 | + |
| 37 | +/** |
| 38 | + * Creates a function that generates mock config objects for a given platform. |
| 39 | + * @param platform - The platform to create the mock config for. |
| 40 | + * @returns A function that generates mock config objects for the given platform. |
| 41 | + */ |
| 42 | +const createConfigFunction = |
| 43 | + (platform: ModPlatform) => |
| 44 | + (modName: string): ExportedConfigWithProps<Record<string, any>> => ({ |
| 45 | + modResults: {}, |
| 46 | + modRequest: { |
| 47 | + projectRoot: process.cwd(), |
| 48 | + platformProjectRoot: process.cwd(), |
| 49 | + modName, |
| 50 | + platform, |
| 51 | + introspect: true, |
| 52 | + severity: 'info', |
| 53 | + } as ModProps<Record<string, any>>, |
| 54 | + modRawConfig: { name: 'TestApp', slug: 'test-app' }, |
| 55 | + name: 'TestApp', |
| 56 | + slug: 'test-app', |
| 57 | + }); |
| 58 | + |
| 59 | +/** |
| 60 | + * Creates a mock config object for the iOS platform. |
| 61 | + * @param modName - The name of the module to create the mock config for. |
| 62 | + * @returns A mock config object for the iOS platform. |
| 63 | + */ |
| 64 | +export const createMockIosConfig = createConfigFunction('ios'); |
| 65 | + |
| 66 | +/** |
| 67 | + * Creates a mock config object for the Android platform. |
| 68 | + * @param modName - The name of the module to create the mock config for. |
| 69 | + * @returns A mock config object for the Android platform. |
| 70 | + */ |
| 71 | +export const createMockConfig = ( |
| 72 | + modName: string |
| 73 | +): ExportedConfigWithProps<Record<string, any>> => ({ |
| 74 | + modResults: {}, |
| 75 | + modRequest: { |
| 76 | + projectRoot: process.cwd(), |
| 77 | + platformProjectRoot: process.cwd(), |
| 78 | + modName, |
| 79 | + platform: 'android', |
| 80 | + introspect: true, |
| 81 | + severity: 'info', |
| 82 | + } as ModProps<Record<string, any>>, |
| 83 | + modRawConfig: { name: 'TestApp', slug: 'test-app' }, |
| 84 | + name: 'TestApp', |
| 85 | + slug: 'test-app', |
| 86 | +}); |
| 87 | + |
| 88 | +/** |
| 89 | + * Creates a mock config object for the Info.plist file. |
| 90 | + * @param modResults - The results of the module to create the mock config for. |
| 91 | + * @returns A mock config object for the Info.plist file. |
| 92 | + */ |
| 93 | +export const createMockPlistConfig = ( |
| 94 | + modResults: Record<string, any> = {} |
| 95 | +): ExportedConfigWithProps<Record<string, any>> => ({ |
| 96 | + ...createMockIosConfig('infoPlist'), |
| 97 | + modResults, |
| 98 | +}); |
| 99 | + |
| 100 | +export const createMockManifestConfig = ( |
| 101 | + modResults: Record<string, any> = {} |
| 102 | +): ExportedConfigWithProps<Record<string, any>> => ({ |
| 103 | + ...createMockConfig('manifest'), |
| 104 | + modResults, |
| 105 | +}); |
| 106 | + |
| 107 | +/** |
| 108 | + * Creates a mock Android manifest object. |
| 109 | + * @returns A mock Android manifest object. |
| 110 | + */ |
| 111 | +export const createMockAndroidManifest = (): Record<string, any> => ({ |
| 112 | + manifest: { |
| 113 | + application: [ |
| 114 | + { $: { 'android:name': '.MainApplication' }, activity: [{ $: {} }] }, |
| 115 | + ], |
| 116 | + }, |
| 117 | +}); |
0 commit comments