Skip to content

Commit 1d17ed8

Browse files
authored
Merge pull request #7 from akofman/windows
Windows
2 parents 3f07e94 + add9560 commit 1d17ed8

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-add-swift-support",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Add Swift support to your iOS plugins",
55
"homepage": "https://github.com/akofman/cordova-plugin-add-swift-support",
66
"author": {

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
33
id="cordova-plugin-add-swift-support"
4-
version="1.1.0" >
4+
version="1.2.0" >
55

66
<name>AddSwiftSupport</name>
77
<license>Apache 2.0</license>

src/add-swift-support.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
* - It updates the EMBEDDED_CONTENT_CONTAINS_SWIFT build setting to YES.
1414
*/
1515

16-
var child_process = require('child_process');
1716
var fs = require('fs');
1817
var path = require('path');
1918
var xcode = require('xcode');
2019

2120
module.exports = function(context) {
2221
var platformMetadata = context.requireCordovaModule('cordova-lib/src/cordova/platform_metadata');
2322
var projectRoot = context.opts.projectRoot;
23+
var glob = context.requireCordovaModule('glob');
2424

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

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

5554
xcodeProject.parseSync();
5655

57-
bridgingHeaderPath = unquote(xcodeProject.getBuildProperty('SWIFT_OBJC_BRIDGING_HEADER'));
56+
bridgingHeaderPath = getBridgingHeaderPath(context, projectPath, iosPlatformVersion);
5857

5958
try{
6059
fs.statSync(bridgingHeaderPath);
6160
} catch(err) {
6261
// If the bridging header doesn't exist, we create it with the minimum
6362
// Cordova/CDV.h import.
64-
65-
bridgingHeaderPath = getBridgingHeaderPath(context, projectPath, iosPlatformVersion);
66-
6763
bridgingHeaderContent = [ '//',
6864
'// Use this file to import your target\'s public headers that you would like to expose to Swift.',
6965
'//',
7066
'#import <Cordova/CDV.h>' ];
71-
7267
fs.writeFileSync(bridgingHeaderPath, bridgingHeaderContent.join('\n'), { encoding: 'utf-8', flag: 'w' });
7368
xcodeProject.addHeaderFile('Bridging-Header.h');
74-
xcodeProject.updateBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', '"' + bridgingHeaderPath + '"');
75-
console.log('Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to:', bridgingHeaderPath);
7669
}
7770

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

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

8684
// if other bridging headers are found, they are imported in the
8785
// one already configured in the project.
@@ -134,18 +132,11 @@ function getConfigParser(context, config) {
134132
function getBridgingHeaderPath(context, projectPath, iosPlatformVersion) {
135133
var semver = context.requireCordovaModule('semver');
136134
var bridgingHeaderPath;
137-
138135
if(semver.lt(iosPlatformVersion, '4.0.0')) {
139-
bridgingHeaderPath = path.join(projectPath, 'Plugins', 'Bridging-Header.h');
136+
bridgingHeaderPath = path.posix.join(projectPath, 'Plugins', 'Bridging-Header.h');
140137
} else {
141-
bridgingHeaderPath = path.join(projectPath, 'Bridging-Header.h');
138+
bridgingHeaderPath = path.posix.join(projectPath, 'Bridging-Header.h');
142139
}
143140

144141
return bridgingHeaderPath;
145142
}
146-
147-
function unquote(str) {
148-
if (str) {
149-
return str.replace(/^"(.*)"$/, '$1');
150-
}
151-
}

0 commit comments

Comments
 (0)