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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
var fs = require("fs");
var path = require("path");
var utilities = require("../lib/utilities");
var xcode = require("xcode");
var plist = require('plist');
/**
* This is used as the display text for the build phase block in XCode as well as the
* inline comments inside of the .pbxproj file for the build script phase block.
*/
var comment = "\"Crashlytics\"";
module.exports = {
/**
* Used to get the path to the XCode project's .pbxproj file.
*/
getXcodeProjectPath: function () {
var appName = utilities.getAppName();
return path.join("platforms", "ios", appName + ".xcodeproj", "project.pbxproj");
},
/**
* This helper is used to add a build phase to the XCode project which runs a shell
* script during the build process. The script executes Crashlytics run command line
* tool with the API and Secret keys. This tool is used to upload the debug symbols
* (dSYMs) so that Crashlytics can display stack trace information in it's web console.
*/
addShellScriptBuildPhase: function (context, xcodeProjectPath) {
// Read and parse the XCode project (.pxbproj) from disk.
// File format information: http://www.monobjc.net/xcode-project-file-format.html
var xcodeProject = xcode.project(xcodeProjectPath);
xcodeProject.parseSync();
// Build the body of the script to be executed during the build phase.
var script = '"' + '\\"${PODS_ROOT}/FirebaseCrashlytics/run\\"' + '"';
// Generate a unique ID for our new build phase.
var id = xcodeProject.generateUuid();
// Create the build phase.
xcodeProject.hash.project.objects.PBXShellScriptBuildPhase[id] = {
isa: "PBXShellScriptBuildPhase",
buildActionMask: 2147483647,
files: [],
inputPaths: ['"' + '$(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)' + '"'],
name: comment,
outputPaths: [],
runOnlyForDeploymentPostprocessing: 0,
shellPath: "/bin/sh",
shellScript: script,
showEnvVarsInLog: 0
};
// Add a comment to the block (viewable in the source of the pbxproj file).
xcodeProject.hash.project.objects.PBXShellScriptBuildPhase[id + "_comment"] = comment;
// Add this new shell script build phase block to the targets.
for (var nativeTargetId in xcodeProject.hash.project.objects.PBXNativeTarget) {
// Skip over the comment blocks.
if (nativeTargetId.indexOf("_comment") !== -1) {
continue;
}
var nativeTarget = xcodeProject.hash.project.objects.PBXNativeTarget[nativeTargetId];
nativeTarget.buildPhases.push({
value: id,
comment: comment
});
}
// Finally, write the .pbxproj back out to disk.
fs.writeFileSync(path.resolve(xcodeProjectPath), xcodeProject.writeSync());
},
/**
* This helper is used to remove the build phase from the XCode project that was added
* by the addShellScriptBuildPhase() helper method.
*/
removeShellScriptBuildPhase: function (context, xcodeProjectPath) {
// Read and parse the XCode project (.pxbproj) from disk.
// File format information: http://www.monobjc.net/xcode-project-file-format.html
var xcodeProject = xcode.project(xcodeProjectPath);
xcodeProject.parseSync();
// First, we want to delete the build phase block itself.
var buildPhases = xcodeProject.hash.project.objects.PBXShellScriptBuildPhase;
var commentTest = comment.replace(/"/g, '');
for (var buildPhaseId in buildPhases) {
var buildPhase = xcodeProject.hash.project.objects.PBXShellScriptBuildPhase[buildPhaseId];
var shouldDelete = false;
if (buildPhaseId.indexOf("_comment") === -1) {
// Dealing with a build phase block.
// If the name of this block matches ours, then we want to delete it.
shouldDelete = buildPhase.name && buildPhase.name.indexOf(commentTest) !== -1;
} else {
// Dealing with a comment block.
// If this is a comment block that matches ours, then we want to delete it.
shouldDelete = buildPhase === commentTest;
}
if (shouldDelete) {
delete buildPhases[buildPhaseId];
}
}
// Second, we want to delete the native target reference to the block.
var nativeTargets = xcodeProject.hash.project.objects.PBXNativeTarget;
for (var nativeTargetId in nativeTargets) {
// Skip over the comment blocks.
if (nativeTargetId.indexOf("_comment") !== -1) {
continue;
}
var nativeTarget = nativeTargets[nativeTargetId];
// We remove the reference to the block by filtering out the the ones that match.
nativeTarget.buildPhases = nativeTarget.buildPhases.filter(function (buildPhase) {
return buildPhase.comment !== commentTest;
});
}
// Finally, write the .pbxproj back out to disk.
fs.writeFileSync(path.resolve(xcodeProjectPath), xcodeProject.writeSync());
},
ensureRunpathSearchPath: function(context, xcodeProjectPath){
function addRunpathSearchBuildProperty(proj, build) {
let LD_RUNPATH_SEARCH_PATHS = proj.getBuildProperty("LD_RUNPATH_SEARCH_PATHS", build);
if (!Array.isArray(LD_RUNPATH_SEARCH_PATHS)) {
LD_RUNPATH_SEARCH_PATHS = [LD_RUNPATH_SEARCH_PATHS];
}
LD_RUNPATH_SEARCH_PATHS.forEach(LD_RUNPATH_SEARCH_PATH => {
if (!LD_RUNPATH_SEARCH_PATH) {
proj.addBuildProperty("LD_RUNPATH_SEARCH_PATHS", "\"$(inherited) @executable_path/Frameworks\"", build);
}
if (LD_RUNPATH_SEARCH_PATH.indexOf("@executable_path/Frameworks") == -1) {
var newValue = LD_RUNPATH_SEARCH_PATH.substr(0, LD_RUNPATH_SEARCH_PATH.length - 1);
newValue += ' @executable_path/Frameworks\"';
proj.updateBuildProperty("LD_RUNPATH_SEARCH_PATHS", newValue, build);
}
if (LD_RUNPATH_SEARCH_PATH.indexOf("$(inherited)") == -1) {
var newValue = LD_RUNPATH_SEARCH_PATH.substr(0, LD_RUNPATH_SEARCH_PATH.length - 1);
newValue += ' $(inherited)\"';
proj.updateBuildProperty("LD_RUNPATH_SEARCH_PATHS", newValue, build);
}
});
}
// Read and parse the XCode project (.pxbproj) from disk.
// File format information: http://www.monobjc.net/xcode-project-file-format.html
var xcodeProject = xcode.project(xcodeProjectPath);
xcodeProject.parseSync();
// Add search paths build property
addRunpathSearchBuildProperty(xcodeProject, "Debug");
addRunpathSearchBuildProperty(xcodeProject, "Release");
// Finally, write the .pbxproj back out to disk.
fs.writeFileSync(path.resolve(xcodeProjectPath), xcodeProject.writeSync());
},
stripDebugSymbols: function(){
var podFilePath = 'platforms/ios/Podfile',
podFile = fs.readFileSync(path.resolve(podFilePath)).toString();
if(!podFile.match('DEBUG_INFORMATION_FORMAT')){
podFile += "\npost_install do |installer|\n" +
" installer.pods_project.targets.each do |target|\n" +
" target.build_configurations.each do |config|\n" +
" config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf'\n" +
" end\n" +
" end\n" +
"end";
fs.writeFileSync(path.resolve(podFilePath), podFile);
console.log('cordova-plugin-firebasex: Applied IOS_STRIP_DEBUG to Podfile');
}
},
applyPluginVarsToPlists: function(googlePlistPath, appPlistPath, pluginVariables){
var googlePlist = plist.parse(fs.readFileSync(path.resolve(googlePlistPath), 'utf8')),
appPlist = plist.parse(fs.readFileSync(path.resolve(appPlistPath), 'utf8')),
googlePlistModified = false,
appPlistModified = false;
if(typeof pluginVariables['FIREBASE_ANALYTICS_COLLECTION_ENABLED'] !== 'undefined'){
googlePlist["FIREBASE_ANALYTICS_COLLECTION_ENABLED"] = (pluginVariables['FIREBASE_ANALYTICS_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ;
googlePlistModified = true;
}
if(typeof pluginVariables['FIREBASE_PERFORMANCE_COLLECTION_ENABLED'] !== 'undefined'){
googlePlist["FIREBASE_PERFORMANCE_COLLECTION_ENABLED"] = (pluginVariables['FIREBASE_PERFORMANCE_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ;
googlePlistModified = true;
}
if(typeof pluginVariables['FIREBASE_CRASHLYTICS_COLLECTION_ENABLED'] !== 'undefined'){
googlePlist["FirebaseCrashlyticsCollectionEnabled"] = (pluginVariables['FIREBASE_CRASHLYTICS_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ;
googlePlistModified = true;
}
if(typeof pluginVariables['IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL'] !== 'undefined'){
appPlist["shouldEstablishDirectChannel"] = (pluginVariables['IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL'] === "true") ;
appPlistModified = true;
}
if(pluginVariables['SETUP_RECAPTCHA_VERIFICATION'] === 'true'){
var reversedClientId = googlePlist['REVERSED_CLIENT_ID'];
if(!appPlist['CFBundleURLTypes']) appPlist['CFBundleURLTypes'] = [];
var entry, i;
for(i=0; i<appPlist['CFBundleURLTypes'].length; i++){
if(typeof appPlist['CFBundleURLTypes'][i] === 'object' && appPlist['CFBundleURLTypes'][i]['CFBundleURLSchemes']){
entry = appPlist['CFBundleURLTypes'][i];
break;
}
}
if(!entry) entry = {};
if(!entry['CFBundleTypeRole']) entry['CFBundleTypeRole'] = 'Editor';
if(!entry['CFBundleURLSchemes']) entry['CFBundleURLSchemes'] = [];
if(entry['CFBundleURLSchemes'].indexOf(reversedClientId) === -1){
entry['CFBundleURLSchemes'].push(reversedClientId)
}
appPlist['CFBundleURLTypes'][i] = entry;
appPlistModified = true;
}
if(googlePlistModified) fs.writeFileSync(path.resolve(googlePlistPath), plist.build(googlePlist));
if(appPlistModified) fs.writeFileSync(path.resolve(appPlistPath), plist.build(appPlist));
}
};
|