Skip to content

Commit

Permalink
fix: cleaned up cordova 7.0.0 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanneff committed May 10, 2017
1 parent 862f14e commit 6f1a2a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ testbed/platforms
testbed/plugins
testbed/hooks
testbed/build.json
testbed/package.json
node_modules
.installed
.gradle/
Expand Down
39 changes: 21 additions & 18 deletions src/scripts/npm/processConfigXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,53 +108,56 @@
var projectRoot = getProjectRoot(context)
var projectPath = path.join(projectRoot, 'platforms', 'ios')

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

function getProjectModulePlugman (context) {
function getProjectModuleGlob (context) {
// get xcodeproj
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.')
}

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

// add hash
xcodeproj.parseSync()

var xCodeProjectFile = {
// return xcodeproj and write method
return {
'xcode': xcodeproj,
'write': function () {
// save xcodeproj
var fs = context.requireCordovaModule('fs')
fs.writeFileSync(pbxPath, xcodeproj.writeSync())

// pull framework dependencies
var frameworksFile = path.join(projectPath, 'frameworks.json')
var frameworks = {}

try {
frameworks = context.requireCordovaModule(frameworksFile)
} catch (e) {}

fs.writeFileSync(pbxPath, xcodeproj.writeSync())
// If there are no framework references, remove this file
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
return context.requireCordovaModule('shelljs').rm('-rf', frameworksFile)
}
fs.writeFileSync(frameworksFile, JSON.stringify(this.frameworks, null, 4))

// save frameworks
fs.writeFileSync(frameworksFile, JSON.stringify(frameworks, null, 4))
}
}

return xCodeProjectFile
}

// validate <branch-config> properties within config.xml
Expand Down
1 change: 1 addition & 0 deletions testbed/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ main() {
rm -rf ./plugins
rm -rf ./platforms
rm -rf ./build.json
rm -rf ./package.json

# build (platforms added before plugin because before_plugin_install does not work on file reference)
if [[ "$run_ios" == "true" ]]; then
Expand Down

0 comments on commit 6f1a2a5

Please sign in to comment.