From bc52ac71c6ffbce058e18654c8d3d165076a00b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristofer=20G=C3=B6ransson?= Date: Mon, 2 Jul 2018 15:44:34 +0200 Subject: [PATCH] Reverting a previous commit to fix iOS reload issue. See: https://github.com/nordnet/cordova-hot-code-push/issues/331 ---- Revert "Refactoring PR https://github.com/nordnet/cordova-hot-code-push/pull/296" This reverts commit c6d1e6f5ec1b08b70f7e9f693a131c1d7f1ae938. --- scripts/lib/iosWKWebViewEngineSupport.js | 82 +++++++++++++----------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/scripts/lib/iosWKWebViewEngineSupport.js b/scripts/lib/iosWKWebViewEngineSupport.js index d326cc6a..5e4747a9 100644 --- a/scripts/lib/iosWKWebViewEngineSupport.js +++ b/scripts/lib/iosWKWebViewEngineSupport.js @@ -67,49 +67,55 @@ function isDirectoryExists(dir) { * @return {Object} projectFile - project file information */ function loadProjectFile() { - try { - return loadProjectFile_cordova_7_and_above(); - } catch(e) { - } - - try { - return loadProjectFile_cordova_5_and_6(); - } catch(e) { - } + var platform_ios; + var projectFile; try { - return loadProjectFile_cordova_pre_5(); + // try pre-5.0 cordova structure + platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios']; + projectFile = platform_ios.parseProjectFile(iosPlatformPath); } catch (e) { - } - - throw new Error('Failed to load iOS project file. Maybe your Cordova version is not supported?'); -} - -function loadProjectFile_cordova_pre_5() { - var platformIos = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios']; - - return platformIos.parseProjectFile(iosPlatformPath); -} - -function loadProjectFile_cordova_5_and_6() { - var platformIos = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios'); - - return platformIos.parseProjectFile(iosPlatformPath); -} - -function loadProjectFile_cordova_7_and_above() { - var pbxPath = path.join(iosPlatformPath, projectName + '.xcodeproj', 'project.pbxproj'); - var xcodeproj = context.requireCordovaModule('xcode').project(pbxPath); - xcodeproj.parseSync(); + // let's try cordova 5.0 structure + try { + platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios'); + projectFile = platform_ios.parseProjectFile(iosPlatformPath); + } catch (e) { + // cordova 7.0 due to https://issues.apache.org/jira/browse/CB-11242 / https://github.com/apache/cordova-lib/pull/526 + var project_files = context.requireCordovaModule('glob') + .sync(path.join(iosPlatformPath, '*.xcodeproj', 'project.pbxproj')); + + if (project_files.length === 0) { + throw new Error('does not appear to be an xcode project (no xcode project file)'); + } - var saveProj = function() { - fs.writeFileSync(pbxPath, xcodeproj.writeSync()); - }; + var pbxPath = project_files[0]; + + var xcodeproj = context.requireCordovaModule('xcode').project(pbxPath); + xcodeproj.parseSync(); + + projectFile = { + 'xcode': xcodeproj, + write: function () { + var fs = context.requireCordovaModule('fs'); + + var frameworks_file = path.join(iosPlatformPath, 'frameworks.json'); + var frameworks = {}; + try { + frameworks = context.requireCordovaModule(frameworks_file); + } 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', frameworks_file); + return; + } + fs.writeFileSync(frameworks_file, JSON.stringify(this.frameworks, null, 4)); + } + }; + } - return { - xcode: xcodeproj, - write: saveProj - }; + return projectFile; } /**