forked from THEOplayer/react-native-theoplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.plugin.js
57 lines (52 loc) · 1.67 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
56
57
/**
* 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 the localMaven repo to the project's repositories
return withProjectBuildGradle(config, (config) => {
const localMaven = 'maven { url("$rootDir/../node_modules/react-native-theoplayer/android/local") }';
config.modResults.contents = config.modResults.contents.replace(
/allprojects\s*\{\s*repositories\s*\{/,
`$&\n\t\t${localMaven}`
)
return config;
});
};
module.exports = (config, props) => {
// Apply Android modifications
return withAndroidTHEOplayer(config, props);
}