1import { RawExpoModuleConfig, SupportedPlatform } from './types'; 2 3/** 4 * A class that wraps the raw config (`expo-module.json` or `unimodule.json`). 5 */ 6export class ExpoModuleConfig { 7 constructor(readonly rawConfig: RawExpoModuleConfig) {} 8 9 /** 10 * Whether the module supports given platform. 11 */ 12 supportsPlatform(platform: SupportedPlatform): boolean { 13 return this.rawConfig.platforms?.includes(platform) ?? false; 14 } 15 16 /** 17 * Returns a list of names of Swift native modules classes to put to the generated modules provider file. 18 */ 19 iosModulesClassNames() { 20 return this.rawConfig.ios?.modulesClassNames ?? []; 21 } 22 23 /** 24 * Returns a list of names of Swift classes that receives AppDelegate life-cycle events. 25 */ 26 iosAppDelegateSubscribers(): string[] { 27 return this.rawConfig.ios?.appDelegateSubscribers ?? []; 28 } 29 30 /** 31 * Returns a list of names of Kotlin native modules classes to put to the generated package provider file. 32 */ 33 androidModulesClassNames() { 34 return this.rawConfig.android?.modulesClassNames ?? []; 35 } 36 37 /** 38 * Returns serializable raw config. 39 */ 40 toJSON(): RawExpoModuleConfig { 41 return this.rawConfig; 42 } 43} 44 45/** 46 * Reads the config at given path and returns the config wrapped by `ExpoModuleConfig` class. 47 */ 48export function requireAndResolveExpoModuleConfig(path: string): ExpoModuleConfig { 49 // TODO: Validate the raw config against a schema. 50 // TODO: Support for `*.js` files, not only static `*.json`. 51 return new ExpoModuleConfig(require(path) as RawExpoModuleConfig); 52} 53