forked from invertase/react-native-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpodfile.ts
More file actions
72 lines (62 loc) · 1.95 KB
/
Copy pathpodfile.ts
File metadata and controls
72 lines (62 loc) · 1.95 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { ConfigPlugin, withPodfile } from '@expo/config-plugins';
import {
mergeContents,
removeGeneratedContents,
} from '@expo/config-plugins/build/utils/generateCode';
import { PluginConfigType } from '../pluginConfig';
const TAG = '@react-native-firebase/analytics-withoutAdIdSupport';
const ANCHOR = /prepare_react_native_project!/;
const FLAG = '$RNFirebaseAnalyticsWithoutAdIdSupport = true';
const TAG_ODM = '@react-native-firebase/analytics-googleAppMeasurementOnDeviceConversion';
const FLAG_ODM = '$RNFirebaseAnalyticsGoogleAppMeasurementOnDeviceConversion = true';
function setAnalyticsPodfileFlag(
src: string,
tag: string,
flag: string,
enabled: boolean = false,
): string {
if (!enabled) {
return removeGeneratedContents(src, tag) ?? src;
}
return mergeContents({
src,
newSrc: flag,
tag,
anchor: ANCHOR,
offset: 1,
comment: '#',
}).contents;
}
export function setAnalyticsPodfileWithoutAdIdSupport(
src: string,
enabled: boolean = false,
): string {
return setAnalyticsPodfileFlag(src, TAG, FLAG, enabled);
}
export function setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(
src: string,
enabled: boolean = false,
): string {
return setAnalyticsPodfileFlag(src, TAG_ODM, FLAG_ODM, enabled);
}
export const withIosGoogleAppMeasurementOnDeviceConversion: ConfigPlugin<PluginConfigType> = (
config,
props,
) => {
return withPodfile(config, config => {
config.modResults.contents = setAnalyticsPodfileGoogleAppMeasurementOnDeviceConversion(
config.modResults.contents,
props?.ios?.googleAppMeasurementOnDeviceConversion === true,
);
return config;
});
};
export const withIosWithoutAdIdSupport: ConfigPlugin<PluginConfigType> = (config, props) => {
return withPodfile(config, config => {
config.modResults.contents = setAnalyticsPodfileWithoutAdIdSupport(
config.modResults.contents,
props?.ios?.withoutAdIdSupport === true,
);
return config;
});
};