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 serializable raw config. 25 */ 26 toJSON(): RawExpoModuleConfig { 27 return this.rawConfig; 28 } 29} 30 31/** 32 * Reads the config at given path and returns the config wrapped by `ExpoModuleConfig` class. 33 */ 34export function requireAndResolveExpoModuleConfig(path: string): ExpoModuleConfig { 35 // TODO: Validate the raw config against a schema. 36 // TODO: Support for `*.js` files, not only static `*.json`. 37 return new ExpoModuleConfig(require(path) as RawExpoModuleConfig); 38} 39