Skip to content

Commit

Permalink
fix: added support for cordova 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed May 9, 2017
1 parent de7cc9d commit 862f14e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/scripts/ios/enableEntitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
// updates the xcode preferences to allow associated domains
function enableAssociatedDomains (preferences) {
var entitlementsFile = path.join(preferences.projectRoot, 'platforms', 'ios', preferences.projectName, 'Resources', preferences.projectName + '.entitlements')
var projectFile = preferences.iosProjectModule.parseProjectFile(path.join(preferences.projectRoot, 'platforms', 'ios'))

activateAssociativeDomains(projectFile.xcode, entitlementsFile)
addPbxReference(projectFile.xcode, entitlementsFile)
projectFile.write()
activateAssociativeDomains(preferences.iosProjectModule.xcode, entitlementsFile)
addPbxReference(preferences.iosProjectModule.xcode, entitlementsFile)
preferences.iosProjectModule.write()
}

// adds entitlement files to the xcode project
Expand Down
50 changes: 47 additions & 3 deletions src/scripts/npm/processConfigXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,58 @@

// read iOS project module from cordova context
function getProjectModule (context) {
// try pre-5.0 cordova structure
var projectRoot = getProjectRoot(context)
var projectPath = path.join(projectRoot, 'platforms', 'ios')

// try pre 5.0 cordova structure
try {
return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios
return context.requireCordovaModule('cordova-lib/src/plugman/platforms').ios.parseProjectFile(projectPath)
} catch (e) {
return context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios')
// try pre 7.0 cordova structure
try {
return context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios').parseProjectFile(projectPath)
} catch (e) {
return getProjectModulePlugman(context)
}
}
}

function getProjectModulePlugman (context) {
var projectRoot = getProjectRoot(context)
var projectPath = path.join(projectRoot, 'platforms', 'ios')
var projectFiles = context.requireCordovaModule('glob').sync(path.join(projectPath, '*.xcodeproj', 'project.pbxproj'))

if (projectFiles.length === 0) {
throw new Error('BRANCH SDK: Unable to locate the Xcode project file.')
}

var pbxPath = projectFiles[0]
var xcodeproj = context.requireCordovaModule('xcode').project(pbxPath)
xcodeproj.parseSync()

var xCodeProjectFile = {
'xcode': xcodeproj,
'write': function () {
var fs = context.requireCordovaModule('fs')
var frameworksFile = path.join(projectPath, 'frameworks.json')
var frameworks = {}
try {
frameworks = context.requireCordovaModule(frameworksFile)
} catch (e) {}

fs.writeFileSync(pbxPath, xcodeproj.writeSync())
if (Object.keys(frameworks).length === 0) {
// If there is no framework references remain in the project, just remove this file
context.requireCordovaModule('shelljs').rm('-rf', frameworksFile)
return
}
fs.writeFileSync(frameworksFile, JSON.stringify(this.frameworks, null, 4))
}
}

return xCodeProjectFile
}

// validate <branch-config> properties within config.xml
function validateBranchPreferences (preferences) {
if (preferences.projectRoot === null) {
Expand Down
1 change: 1 addition & 0 deletions testbed/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ main() {
npm uninstall mkpath node-version-compare plist xml2js
fi
rm -rf ../.installed
rm -rf ./node_modules
rm -rf ./plugins
rm -rf ./platforms
rm -rf ./build.json
Expand Down

0 comments on commit 862f14e

Please sign in to comment.