From 6f1a2a5b032f8d6a32f0417f56ff218b5ec793b2 Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Wed, 10 May 2017 10:04:33 -0700 Subject: [PATCH] fix: cleaned up cordova 7.0.0 fix --- .gitignore | 1 + src/scripts/npm/processConfigXml.js | 39 ++++++++++++++++------------- testbed/init.sh | 1 + 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index bacd909f..daafabfd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ testbed/platforms testbed/plugins testbed/hooks testbed/build.json +testbed/package.json node_modules .installed .gradle/ diff --git a/src/scripts/npm/processConfigXml.js b/src/scripts/npm/processConfigXml.js index 79d080e5..a77fc086 100644 --- a/src/scripts/npm/processConfigXml.js +++ b/src/scripts/npm/processConfigXml.js @@ -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 properties within config.xml diff --git a/testbed/init.sh b/testbed/init.sh index 340dfd73..fd75d3e5 100755 --- a/testbed/init.sh +++ b/testbed/init.sh @@ -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