Last active
February 4, 2016 15:49
-
-
Save phynet/2e3dcd5ef843d7e9b6a2 to your computer and use it in GitHub Desktop.
This is a JS-Node Hook Plugin for Cordova, that adds the "Run Script" option in XCODE for CRASHLYTICS. What it does, is to add the PBXBuildFile section in project.pbxproj file. Thanks to my lovely bf for pointing me out to use the global match (g modifier) in the regex part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
- Really important: install first npm package 'replace'. | |
*/ | |
module.exports = function(ctx) { | |
var apiKey = 'YourApiKey'; | |
var secretKey = 'YourSecretKey'; | |
var shellScript = '\".\/Fabric.framework\/run '+ apiKey + ' '+ secretKey+'\"'; | |
//If you are having troubles with Fabric's path, try to point to where the Fabric.framework is added in your project. | |
//For example, I added mine instead of root, in my project's cordova Plugin. This was an absolute path adjusted to my needs. | |
//You can always change it to a relative one | |
//var shellScript = '\"crashlyticsPlugin\/Plugins\/cordova-plugin-crashlytics\/Fabric.framework\/run '+ apiKey + ' '+ secretKey+'\"'; | |
var shellIn = 'shellScript = "";'; | |
var shellOut = 'shellScript = '+ shellScript + ';'; | |
/*============================================= | |
= Find Project Name .xcodeproj = | |
=============================================*/ | |
var path = require('path'); | |
var filePath = path.resolve(__dirname,'..','..','..'); | |
var namePathXcode = path.resolve(__dirname,'..','..','..'); | |
console.log(namePathXcode); | |
var count = namePathXcode.length; | |
var temp = ".xcodeproj"; | |
for (var i = count-1; i > 0; i--) { | |
if (namePathXcode[i] != '\/' ){ | |
temp = namePathXcode[i] + temp; | |
}else{ | |
i = 0; | |
} | |
} | |
var xcodePath = '/platforms/ios/'+temp+'/project.pbxproj'; | |
filePath = filePath + xcodePath; | |
console.log("File xcodeproj "+ filePath); | |
/*============================================= | |
= Replace text inside project.pbxproj = | |
=============================================*/ | |
var stringIn = "/* End PBXBuildFile section */"; | |
var stringOut = stringIn+ "\r\n\n" +"\/* Begin PBXShellScriptBuildPhase section *\/\r\n\t\t079C36101C60A60F0039930C \/* ShellScript *\/ = {\r\n\t\t\tisa = PBXShellScriptBuildPhase;\r\n\t\t\tbuildActionMask = 2147483647;\r\n\t\t\tfiles = (\r\n\t\t\t);\r\n\t\t\tinputPaths = (\r\n\t\t\t);\r\n\t\t\toutputPaths = (\r\n\t\t\t);\r\n\t\t\trunOnlyForDeploymentPostprocessing = 0;\r\n\t\t\tshellPath = \/bin\/sh;\r\n\t\t\t"+shellOut+"\r\n\t\t};\r\n\/* End PBXShellScriptBuildPhase section *\/\r\n\n\n"; | |
var replace = require("replace"); | |
console.log("starting to replace regex"); | |
console.log(stringIn); | |
console.log(stringOut); | |
replace({ | |
regex: /\/\* End PBXBuildFile section \*\//g, | |
replacement: stringOut, | |
paths: [filePath], | |
recursive: false, | |
silent: true, | |
}); | |
replace({ | |
regex: /\)\;\n\t\t\tbuildRules = \(/g, | |
replacement:'\t079C36101C60A60F0039930C \/* ShellScript *\/,\n\t\t\t\)\;\n\t\t\tbuildRules = (', | |
paths: [filePath], | |
recursive: false, | |
silent: true, | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment