I use the npm plugin cordova-node-xcode
, which allows you to write the build phase to the generated Xcode project file. Add "xcode": "^3.0.1"
to your devDependencies in package.json.
Call a .js script AddBuildScript.js
from a Cordova "after_build" hook in your config.xml
:
<platform name="ios">
<hook src="AddBuildScript.js" type="after_build" />
Script AddBuildScript.js
:
var xcode = require('xcode'),
fs = require('fs'),
projectPath = 'platforms/ios/MyProj.xcodeproj/project.pbxproj',
proj = xcode.project(projectPath);
proj.parse(function (err) {
var scriptName = 'My Script';
var buildPhases = proj.getPBXObject('PBXShellScriptBuildPhase');
if (JSON.stringify(buildPhases).match(scriptName)) {
console.log('Xcode project not updated - ' + scriptName + ' already exists')
} else {
var options = {shellPath: '/bin/sh', shellScript: '$PODS_ROOT/ServiceSDK/Frameworks/ServiceCore.framework/prepare-framework'};
proj.addBuildPhase([], 'PBXShellScriptBuildPhase', scriptName, proj.getFirstTarget().uuid, options);
fs.writeFileSync(projectPath, proj.writeSync());
console.log('Xcode project updated - added ' + scriptName);
}
});