UNPKG

bitmovin-player-react-native

Version:

Official React Native bindings for Bitmovin's mobile Player SDKs.

76 lines (75 loc) 3.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const config_plugins_1 = require("expo/config-plugins"); const defaultProps = { spacing: ' ', dependencies: [], }; const withAppGradleDependencies = (config, props) => { const combinedProps = { ...defaultProps, ...(props || {}) }; config = (0, config_plugins_1.withAppBuildGradle)(config, (config) => { if (config.modResults.language !== 'groovy') { config_plugins_1.WarningAggregator.addWarningAndroid('withAppGradleDependencies', `Cannot automatically configure app/build.gradle if it's not groovy`); return config; } const deduplicatedDependencies = Array.from(new Set(combinedProps.dependencies)); const filteredDependencies = deduplicatedDependencies.filter((dep) => { return config.modResults.contents.indexOf(dep) === -1; }); if (filteredDependencies.length === 0) { return config; } const androidBlockStart = config.modResults.contents.search(/^android \{$/m); if (androidBlockStart === -1) { config_plugins_1.WarningAggregator.addWarningAndroid('withAppGradleDependencies', `Cannot configure app/build.gradle as no android block start was found`); return config; } const fromAndroid = config.modResults.contents.substring(androidBlockStart); const androidBlockEnd = fromAndroid.search(/^\}$/m); if (androidBlockEnd === -1) { config_plugins_1.WarningAggregator.addWarningAndroid('withAppGradleDependencies', `Cannot configure app/build.gradle as no android block end was found`); return config; } const androidPosition = androidBlockStart + androidBlockEnd; const compileOptions = []; compileOptions.push(`${combinedProps.spacing}compileOptions {`); compileOptions.push('\n'); compileOptions.push(`${combinedProps.spacing}setCoreLibraryDesugaringEnabled(true)`); compileOptions.push('\n'); compileOptions.push(`${combinedProps.spacing}}`); compileOptions.push('\n'); config.modResults.contents = [ config.modResults.contents.slice(0, androidPosition), ...compileOptions, config.modResults.contents.slice(androidPosition), ].join(''); const dependenciesBlockStart = config.modResults.contents.search(/^dependencies \{$/m); if (dependenciesBlockStart === -1) { config_plugins_1.WarningAggregator.addWarningAndroid('withAppGradleDependencies', `Cannot configure app/build.gradle as no dependency block start was found`); return config; } const fromDependencies = config.modResults.contents.substring(dependenciesBlockStart); const dependenciesBlockEnd = fromDependencies.search(/^\}$/m); if (dependenciesBlockEnd === -1) { config_plugins_1.WarningAggregator.addWarningAndroid('withAppGradleDependencies', `Cannot configure app/build.gradle as no dependency block end was found`); return config; } const position = dependenciesBlockStart + dependenciesBlockEnd; let insertedDependencies = []; insertedDependencies.push('\n'); insertedDependencies.push(`${combinedProps.spacing}coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'`); insertedDependencies.push('\n'); filteredDependencies.forEach((dependency) => { insertedDependencies.push(`${combinedProps.spacing}implementation '${dependency}'\n`); }); insertedDependencies.push('\n'); config.modResults.contents = [ config.modResults.contents.slice(0, position), ...insertedDependencies, config.modResults.contents.slice(position), ].join(''); return config; }); return config; }; exports.default = withAppGradleDependencies;