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