Skip to content

Instantly share code, notes, and snippets.

@beznosd
Created September 16, 2017 23:56
Show Gist options
  • Save beznosd/a3c0752961e372cc523a6c78407092c0 to your computer and use it in GitHub Desktop.
Save beznosd/a3c0752961e372cc523a6c78407092c0 to your computer and use it in GitHub Desktop.
function loadProjectFile() {
var platform_ios;
var projectFile;
try {
// try pre-5.0 cordova structure
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios'];
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
} catch (e) {
try {
// let's try cordova 5.0 structure
platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
} catch (e) {
// Then cordova 7.0
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 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 projectFile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment