addFabricBuildToolsGradle = function () {
var buildGradle = utilities.readBuildGradle();
buildGradle += [
"",
"// Fabric Cordova Plugin - Start Fabric Build Tools ",
"buildscript {",
" repositories {",
" maven { url 'https://maven.fabric.io/public' }",
" }",
" dependencies {",
" classpath 'io.fabric.tools:gradle:1.+'",
" }",
"}",
"",
"apply plugin: 'io.fabric'",
"// Fabric Cordova Plugin - End Fabric Build Tools",
].join("\n");
utilities.writeBuildGradle(buildGradle);
}...
var platforms = context.opts.cordova.platforms;
// Modify the Gradle build file to add a task that will upload the debug symbols
// at build time.
if (platforms.indexOf("android") !== -1) {
androidHelper.removeFabricBuildToolsFromGradle();
androidHelper.addFabricBuildToolsGradle();
}
// Add a build phase which runs a shell script that executes the Crashlytics
// run command line tool which uploads the debug symbols at build time.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
iosHelper.removeShellScriptBuildPhase(context, xcodeProjectPath);
...removeFabricBuildToolsFromGradle = function () {
var buildGradle = utilities.readBuildGradle();
buildGradle = buildGradle.replace(/\n\/\/ Fabric Cordova Plugin - Start Fabric Build Tools[\s\S]*\/\/ Fabric Cordova Plugin -
End Fabric Build Tools/, "");
utilities.writeBuildGradle(buildGradle);
}...
module.exports = function(context) {
var platforms = context.opts.cordova.platforms;
// Modify the Gradle build file to add a task that will upload the debug symbols
// at build time.
if (platforms.indexOf("android") !== -1) {
androidHelper.removeFabricBuildToolsFromGradle();
androidHelper.addFabricBuildToolsGradle();
}
// Add a build phase which runs a shell script that executes the Crashlytics
// run command line tool which uploads the debug symbols at build time.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
...addShellScriptBuildPhase = function (context, xcodeProjectPath) {
var pluginConfig = utilities.getPluginConfig("ios");
var xcode = context.requireCordovaModule("xcode");
// 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 = '"' + '${SRCROOT}' + "/\\\"" + utilities.getAppName(context) + "\\\"/Plugins/cordova-fabric-plugin/Fabric.framework
/run " + pluginConfig.apiKey + " " + pluginConfig.apiSecret + '"';
// 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: [],
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(xcodeProjectPath, xcodeProject.writeSync());
}...
}
// Add a build phase which runs a shell script that executes the Crashlytics
// run command line tool which uploads the debug symbols at build time.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
iosHelper.removeShellScriptBuildPhase(context, xcodeProjectPath);
iosHelper.addShellScriptBuildPhase(context, xcodeProjectPath);
}
};
...removeShellScriptBuildPhase = function (context, xcodeProjectPath) {
var xcode = context.requireCordovaModule("xcode");
// 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;
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(comment) !== -1;
}
else {
// Dealing with a comment block.
// If this is a comment block that matches ours, then we want to delete it.
shouldDelete = buildPhaseId === comment;
}
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 !== comment;
});
}
// Finally, write the .pbxproj back out to disk.
fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync());
}...
androidHelper.addFabricBuildToolsGradle();
}
// Add a build phase which runs a shell script that executes the Crashlytics
// run command line tool which uploads the debug symbols at build time.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
iosHelper.removeShellScriptBuildPhase(context, xcodeProjectPath);
iosHelper.addShellScriptBuildPhase(context, xcodeProjectPath);
}
};
...getAppName = function (context) {
var ConfigParser = context.requireCordovaModule("cordova-lib").configparser;
var config = new ConfigParser("config.xml");
return config.name();
}...
// 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 = '"' + '${SRCROOT}' + "/\\\"" + utilities.getAppName(context) + "\\\"/Plugins/cordova-fabric-plugin/Fabric.framework/run " + pluginConfig.apiKey + " " + pluginConfig.apiSecret + '"';
// 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,
...getPluginConfig = function (platform) {
var platformConfigPath = path.join("..", "..", "..", platform + ".json");
var platformConfig = require(platformConfigPath);
var pluginId = this.getPluginId();
var apiKey = platformConfig.installed_plugins[pluginId].FABRIC_API_KEY;
var apiSecret = platformConfig.installed_plugins[pluginId].FABRIC_API_SECRET;
var config = {
apiKey: apiKey,
apiSecret: apiSecret
};
return config;
}...
* 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) {
var pluginConfig = utilities.getPluginConfig("ios");
var xcode = context.requireCordovaModule("xcode");
// 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();
...getPluginId = function () {
return "cordova-fabric-plugin";
}...
*/
getPluginConfig: function(platform) {
var platformConfigPath = path.join("..", "..", "..", platform + ".json");
var platformConfig = require(platformConfigPath);
var pluginId = this.getPluginId();
var apiKey = platformConfig.installed_plugins[pluginId].FABRIC_API_KEY;
var apiSecret = platformConfig.installed_plugins[pluginId].FABRIC_API_SECRET;
var config = {
apiKey: apiKey,
apiSecret: apiSecret
...getXcodeProjectPath = function (context) {
var appName = this.getAppName(context);
return path.join("platforms", "ios", appName + ".xcodeproj", "project.pbxproj");
}...
androidHelper.removeFabricBuildToolsFromGradle();
androidHelper.addFabricBuildToolsGradle();
}
// Add a build phase which runs a shell script that executes the Crashlytics
// run command line tool which uploads the debug symbols at build time.
if (platforms.indexOf("ios") !== -1) {
var xcodeProjectPath = utilities.getXcodeProjectPath(context);
iosHelper.removeShellScriptBuildPhase(context, xcodeProjectPath);
iosHelper.addShellScriptBuildPhase(context, xcodeProjectPath);
}
};
...readBuildGradle = function () {
return fs.readFileSync(getBuildGradlePath(), "utf-8");
}...
var path = require("path");
var utilities = require("./utilities");
module.exports = {
addFabricBuildToolsGradle: function() {
var buildGradle = utilities.readBuildGradle();
buildGradle += [
"",
"// Fabric Cordova Plugin - Start Fabric Build Tools ",
"buildscript {",
" repositories {",
" maven { url 'https://maven.fabric.io/public' }",
...writeBuildGradle = function (buildGradle) {
fs.writeFileSync(getBuildGradlePath(), buildGradle);
}...
" }",
"}",
"",
"apply plugin: 'io.fabric'",
"// Fabric Cordova Plugin - End Fabric Build Tools",
].join("\n");
utilities.writeBuildGradle(buildGradle);
},
removeFabricBuildToolsFromGradle: function() {
var buildGradle = utilities.readBuildGradle();
buildGradle = buildGradle.replace(/\n\/\/ Fabric Cordova Plugin - Start Fabric Build Tools[\s\S]*\/\/ Fabric Cordova Plugin - End
Fabric Build Tools/, "");
...