Skip to content

Commit

Permalink
Merge pull request #7 from akofman/windows
Browse files Browse the repository at this point in the history
Windows
  • Loading branch information
akofman authored Jun 10, 2016
2 parents 3f07e94 + add9560 commit 1d17ed8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-add-swift-support",
"version": "1.1.0",
"version": "1.2.0",
"description": "Add Swift support to your iOS plugins",
"homepage": "https://github.com/akofman/cordova-plugin-add-swift-support",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-add-swift-support"
version="1.1.0" >
version="1.2.0" >

<name>AddSwiftSupport</name>
<license>Apache 2.0</license>
Expand Down
35 changes: 13 additions & 22 deletions src/add-swift-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
* - It updates the EMBEDDED_CONTENT_CONTAINS_SWIFT build setting to YES.
*/

var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var xcode = require('xcode');

module.exports = function(context) {
var platformMetadata = context.requireCordovaModule('cordova-lib/src/cordova/platform_metadata');
var projectRoot = context.opts.projectRoot;
var glob = context.requireCordovaModule('glob');

platformMetadata.getPlatformVersions(projectRoot).then(function(platformVersions) {
var _ = context.requireCordovaModule('underscore');
var IOS_MIN_DEPLOYMENT_TARGET = '7.0';
var platformPath = path.join(projectRoot, 'platforms', 'ios');

Expand Down Expand Up @@ -54,34 +53,33 @@ module.exports = function(context) {

xcodeProject.parseSync();

bridgingHeaderPath = unquote(xcodeProject.getBuildProperty('SWIFT_OBJC_BRIDGING_HEADER'));
bridgingHeaderPath = getBridgingHeaderPath(context, projectPath, iosPlatformVersion);

try{
fs.statSync(bridgingHeaderPath);
} catch(err) {
// If the bridging header doesn't exist, we create it with the minimum
// Cordova/CDV.h import.

bridgingHeaderPath = getBridgingHeaderPath(context, projectPath, iosPlatformVersion);

bridgingHeaderContent = [ '//',
'// Use this file to import your target\'s public headers that you would like to expose to Swift.',
'//',
'#import <Cordova/CDV.h>' ];

fs.writeFileSync(bridgingHeaderPath, bridgingHeaderContent.join('\n'), { encoding: 'utf-8', flag: 'w' });
xcodeProject.addHeaderFile('Bridging-Header.h');
xcodeProject.updateBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', '"' + bridgingHeaderPath + '"');
console.log('Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to:', bridgingHeaderPath);
}

// Look for any bridging header defined in the plugin
child_process.exec('find . -name "*Bridging-Header*.h"', { cwd: pluginsPath }, function (error, stdout) {
var bridgingHeaderProperty = '"$(PROJECT_DIR)/$(PROJECT_NAME)' + bridgingHeaderPath.split(projectPath)[1] + '"';
if(xcodeProject.getBuildProperty('SWIFT_OBJC_BRIDGING_HEADER') !== bridgingHeaderProperty) {
xcodeProject.updateBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', bridgingHeaderProperty);
console.log('Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to:', bridgingHeaderProperty);
}

// Look for any bridging header defined in the plugin
glob('**/*Bridging-Header*.h', { cwd: pluginsPath }, function(error, files) {
var bridgingHeader = path.basename(bridgingHeaderPath);
var headers = _.compact(stdout.toString().split('\n').map(function (filePath) {
var headers = files.map(function (filePath) {
return path.basename(filePath);
}));
});

// if other bridging headers are found, they are imported in the
// one already configured in the project.
Expand Down Expand Up @@ -134,18 +132,11 @@ function getConfigParser(context, config) {
function getBridgingHeaderPath(context, projectPath, iosPlatformVersion) {
var semver = context.requireCordovaModule('semver');
var bridgingHeaderPath;

if(semver.lt(iosPlatformVersion, '4.0.0')) {
bridgingHeaderPath = path.join(projectPath, 'Plugins', 'Bridging-Header.h');
bridgingHeaderPath = path.posix.join(projectPath, 'Plugins', 'Bridging-Header.h');
} else {
bridgingHeaderPath = path.join(projectPath, 'Bridging-Header.h');
bridgingHeaderPath = path.posix.join(projectPath, 'Bridging-Header.h');
}

return bridgingHeaderPath;
}

function unquote(str) {
if (str) {
return str.replace(/^"(.*)"$/, '$1');
}
}

0 comments on commit 1d17ed8

Please sign in to comment.