1*04e66b12SGabriel Donadel Dall'Agnolimport Ajv, { JSONSchemaType } from 'ajv'; 2*04e66b12SGabriel Donadel Dall'Agnol 3*04e66b12SGabriel Donadel Dall'Agnol/** 4*04e66b12SGabriel Donadel Dall'Agnol * Type representing base dev launcher configuration. 5*04e66b12SGabriel Donadel Dall'Agnol */ 6*04e66b12SGabriel Donadel Dall'Agnolexport type PluginConfigType = PluginConfigOptionsByPlatform & PluginConfigOptions; 7*04e66b12SGabriel Donadel Dall'Agnol 8*04e66b12SGabriel Donadel Dall'Agnol/** 9*04e66b12SGabriel Donadel Dall'Agnol * Type representing available configuration for each platform. 10*04e66b12SGabriel Donadel Dall'Agnol */ 11*04e66b12SGabriel Donadel Dall'Agnolexport type PluginConfigOptionsByPlatform = { 12*04e66b12SGabriel Donadel Dall'Agnol /** 13*04e66b12SGabriel Donadel Dall'Agnol * Type representing available configuration for Android dev launcher. 14*04e66b12SGabriel Donadel Dall'Agnol * @platform android 15*04e66b12SGabriel Donadel Dall'Agnol */ 16*04e66b12SGabriel Donadel Dall'Agnol android?: PluginConfigOptions; 17*04e66b12SGabriel Donadel Dall'Agnol /** 18*04e66b12SGabriel Donadel Dall'Agnol * Type representing available configuration for iOS dev launcher. 19*04e66b12SGabriel Donadel Dall'Agnol * @platform ios 20*04e66b12SGabriel Donadel Dall'Agnol */ 21*04e66b12SGabriel Donadel Dall'Agnol ios?: PluginConfigOptions; 22*04e66b12SGabriel Donadel Dall'Agnol}; 23*04e66b12SGabriel Donadel Dall'Agnol 24*04e66b12SGabriel Donadel Dall'Agnol/** 25*04e66b12SGabriel Donadel Dall'Agnol * Type representing available configuration for dev launcher. 26*04e66b12SGabriel Donadel Dall'Agnol */ 27*04e66b12SGabriel Donadel Dall'Agnolexport type PluginConfigOptions = { 28*04e66b12SGabriel Donadel Dall'Agnol /** 29*04e66b12SGabriel Donadel Dall'Agnol * Attempts to launch directly into a previously opened project. If unable to connect, 30*04e66b12SGabriel Donadel Dall'Agnol * fall back to the launcher screen. 31*04e66b12SGabriel Donadel Dall'Agnol */ 32*04e66b12SGabriel Donadel Dall'Agnol tryToLaunchLastOpenedBundle?: boolean; 33*04e66b12SGabriel Donadel Dall'Agnol}; 34*04e66b12SGabriel Donadel Dall'Agnol 35*04e66b12SGabriel Donadel Dall'Agnolconst schema: JSONSchemaType<PluginConfigType> = { 36*04e66b12SGabriel Donadel Dall'Agnol type: 'object', 37*04e66b12SGabriel Donadel Dall'Agnol properties: { 38*04e66b12SGabriel Donadel Dall'Agnol tryToLaunchLastOpenedBundle: { type: 'boolean', nullable: true }, 39*04e66b12SGabriel Donadel Dall'Agnol android: { 40*04e66b12SGabriel Donadel Dall'Agnol type: 'object', 41*04e66b12SGabriel Donadel Dall'Agnol properties: { 42*04e66b12SGabriel Donadel Dall'Agnol tryToLaunchLastOpenedBundle: { type: 'boolean', nullable: true }, 43*04e66b12SGabriel Donadel Dall'Agnol }, 44*04e66b12SGabriel Donadel Dall'Agnol nullable: true, 45*04e66b12SGabriel Donadel Dall'Agnol }, 46*04e66b12SGabriel Donadel Dall'Agnol ios: { 47*04e66b12SGabriel Donadel Dall'Agnol type: 'object', 48*04e66b12SGabriel Donadel Dall'Agnol properties: { 49*04e66b12SGabriel Donadel Dall'Agnol tryToLaunchLastOpenedBundle: { type: 'boolean', nullable: true }, 50*04e66b12SGabriel Donadel Dall'Agnol }, 51*04e66b12SGabriel Donadel Dall'Agnol nullable: true, 52*04e66b12SGabriel Donadel Dall'Agnol }, 53*04e66b12SGabriel Donadel Dall'Agnol }, 54*04e66b12SGabriel Donadel Dall'Agnol}; 55*04e66b12SGabriel Donadel Dall'Agnol 56*04e66b12SGabriel Donadel Dall'Agnol/** 57*04e66b12SGabriel Donadel Dall'Agnol * @ignore 58*04e66b12SGabriel Donadel Dall'Agnol */ 59*04e66b12SGabriel Donadel Dall'Agnolexport function validateConfig<T>(config: T): PluginConfigType { 60*04e66b12SGabriel Donadel Dall'Agnol const validate = new Ajv({ allowUnionTypes: true }).compile(schema); 61*04e66b12SGabriel Donadel Dall'Agnol if (!validate(config)) { 62*04e66b12SGabriel Donadel Dall'Agnol throw new Error('Invalid expo-dev-launcher config: ' + JSON.stringify(validate.errors)); 63*04e66b12SGabriel Donadel Dall'Agnol } 64*04e66b12SGabriel Donadel Dall'Agnol 65*04e66b12SGabriel Donadel Dall'Agnol return config; 66*04e66b12SGabriel Donadel Dall'Agnol} 67