1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.createBuildGradlePropsConfigPlugin = createBuildGradlePropsConfigPlugin; 7exports.updateAndroidBuildPropertiesFromConfig = updateAndroidBuildPropertiesFromConfig; 8exports.updateAndroidBuildProperty = updateAndroidBuildProperty; 9exports.withJsEngineGradleProps = void 0; 10 11function _androidPlugins() { 12 const data = require("../plugins/android-plugins"); 13 14 _androidPlugins = function () { 15 return data; 16 }; 17 18 return data; 19} 20 21/** 22 * Creates a `withGradleProperties` config-plugin based on given config to property mapping rules. 23 * 24 * The factory supports two modes from generic type inference 25 * ```ts 26 * // config-plugin without `props`, it will implicitly use the expo config as source config. 27 * createBuildGradlePropsConfigPlugin<ExpoConfig>(): ConfigPlugin<void>; 28 * 29 * // config-plugin with a parameter `props: CustomType`, it will use the `props` as source config. 30 * createBuildGradlePropsConfigPlugin<CustomType>(): ConfigPlugin<CustomType>; 31 * ``` 32 * 33 * @param configToPropertyRules config to property mapping rules 34 * @param name the config plugin name 35 */ 36function createBuildGradlePropsConfigPlugin(configToPropertyRules, name) { 37 const withUnknown = (config, sourceConfig) => (0, _androidPlugins().withGradleProperties)(config, config => { 38 config.modResults = updateAndroidBuildPropertiesFromConfig(sourceConfig !== null && sourceConfig !== void 0 ? sourceConfig : config, config.modResults, configToPropertyRules); 39 return config; 40 }); 41 42 if (name) { 43 Object.defineProperty(withUnknown, 'name', { 44 value: name 45 }); 46 } 47 48 return withUnknown; 49} 50/** 51 * A config-plugin to update `android/gradle.properties` from the `jsEngine` in expo config 52 */ 53 54 55const withJsEngineGradleProps = createBuildGradlePropsConfigPlugin([{ 56 propName: 'expo.jsEngine', 57 propValueGetter: config => { 58 var _ref, _config$android$jsEng, _config$android; 59 60 return (_ref = (_config$android$jsEng = (_config$android = config.android) === null || _config$android === void 0 ? void 0 : _config$android.jsEngine) !== null && _config$android$jsEng !== void 0 ? _config$android$jsEng : config.jsEngine) !== null && _ref !== void 0 ? _ref : 'jsc'; 61 } 62}], 'withJsEngineGradleProps'); 63exports.withJsEngineGradleProps = withJsEngineGradleProps; 64 65function updateAndroidBuildPropertiesFromConfig(config, gradleProperties, configToPropertyRules) { 66 for (const configToProperty of configToPropertyRules) { 67 const value = configToProperty.propValueGetter(config); 68 updateAndroidBuildProperty(gradleProperties, configToProperty.propName, value); 69 } 70 71 return gradleProperties; 72} 73 74function updateAndroidBuildProperty(gradleProperties, name, value, options) { 75 const oldPropIndex = gradleProperties.findIndex(prop => prop.type === 'property' && prop.key === name); 76 77 if (value) { 78 // found the matched value, add or merge new property 79 const newProp = { 80 type: 'property', 81 key: name, 82 value 83 }; 84 85 if (oldPropIndex >= 0) { 86 gradleProperties[oldPropIndex] = newProp; 87 } else { 88 gradleProperties.push(newProp); 89 } 90 } else if (options !== null && options !== void 0 && options.removePropWhenValueIsNull && oldPropIndex >= 0) { 91 gradleProperties.splice(oldPropIndex, 1); 92 } 93 94 return gradleProperties; 95} 96//# sourceMappingURL=BuildProperties.js.map