-
Notifications
You must be signed in to change notification settings - Fork 21
/
app.plugin.js
55 lines (50 loc) · 1.66 KB
/
app.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* Expo plugin for react-native-theoplayer.
*
* Example:
* "plugins": [
* ["react-native-theoplayer", {
* "extensions": ["ima", "dai", "cast"]
* }]
* ]
*/
const { withProjectBuildGradle, withGradleProperties } = require('@expo/config-plugins');
function mapAndroidExtensionKey(ext) {
switch (ext) {
case 'ima':
return 'THEOplayer_extensionGoogleIMA';
case 'dai':
return 'THEOplayer_extensionGoogleDAI';
case 'cast':
return 'THEOplayer_extensionCast';
default:
return undefined;
}
}
const applyAndroidExtensions = (config, extensions) => {
return withGradleProperties(config, (config) => {
extensions?.forEach((ext) => {
const key = mapAndroidExtensionKey(ext);
if (key) {
config.modResults.push({ type: 'property', key, value: true });
}
});
return config;
});
};
const withAndroidTHEOplayer = (config, props) => {
// Apply Android extensions
const { extensions } = props | {};
config = applyAndroidExtensions(config, extensions);
// Add THEOplayer and local Maven repos to the project's repositories
return withProjectBuildGradle(config, (config) => {
const localMaven = 'maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }';
const THEOplayerMaven = 'maven { url("https://maven.theoplayer.com/releases") }';
config.modResults.contents = config.modResults.contents.replace(/allprojects\s*\{\s*repositories\s*\{/, `$&\n\t\t${localMaven}\n\t\t${THEOplayerMaven}`);
return config;
});
};
module.exports = (config, props) => {
// Apply Android modifications
return withAndroidTHEOplayer(config, props);
};