diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 29f6cc2e7..f81085f82 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -22,7 +22,6 @@ var Q = require('q'); var fs = require('fs'); var path = require('path'); var shell = require('shelljs'); -var xcode = require('xcode'); var unorm = require('unorm'); var plist = require('plist'); var URL = require('url'); @@ -282,15 +281,15 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ + var project; try { - proj.parseSync(); + project = projectFile.parse(locations); } catch (err) { return Q.reject(new CordovaError('Could not parse ' + locations.pbxproj + ': ' + err)); } - var origPkg = proj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER'); + var origPkg = project.xcode.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER'); // no build settings provided and we don't need to update build settings for launch storyboards, // then we don't need to parse and update .pbxproj file @@ -300,27 +299,27 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (origPkg !== pkg) { events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.'); - proj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg); + project.xcode.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg); } if (targetDevice) { events.emit('verbose', 'Set TARGETED_DEVICE_FAMILY to ' + targetDevice + '.'); - proj.updateBuildProperty('TARGETED_DEVICE_FAMILY', targetDevice); + project.xcode.updateBuildProperty('TARGETED_DEVICE_FAMILY', targetDevice); } if (deploymentTarget) { events.emit('verbose', 'Set IPHONEOS_DEPLOYMENT_TARGET to "' + deploymentTarget + '".'); - proj.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); + project.xcode.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); } if (swiftVersion) { events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".'); - proj.updateBuildProperty('SWIFT_VERSION', swiftVersion); + project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion); } - updateBuildSettingsForLaunchStoryboard(proj, platformConfig, infoPlist); + updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist); - fs.writeFileSync(locations.pbxproj, proj.writeSync(), 'utf-8'); + project.write(); return Q(); } @@ -962,7 +961,7 @@ function processAccessAndAllowNavigationEntries (config) { var allow_navigations = config.getAllowNavigations(); return allow_navigations - // we concat allow_navigations and accesses, after processing accesses + // we concat allow_navigations and accesses, after processing accesses .concat(accesses.map(function (obj) { // map accesses to a common key interface using 'href', not origin obj.href = obj.origin;