|
13 | 13 | * - It updates the EMBEDDED_CONTENT_CONTAINS_SWIFT build setting to YES. |
14 | 14 | */ |
15 | 15 |
|
16 | | -var child_process = require('child_process'); |
17 | 16 | var fs = require('fs'); |
18 | 17 | var path = require('path'); |
19 | 18 | var xcode = require('xcode'); |
20 | 19 |
|
21 | 20 | module.exports = function(context) { |
22 | 21 | var platformMetadata = context.requireCordovaModule('cordova-lib/src/cordova/platform_metadata'); |
23 | 22 | var projectRoot = context.opts.projectRoot; |
| 23 | + var glob = context.requireCordovaModule('glob'); |
24 | 24 |
|
25 | 25 | platformMetadata.getPlatformVersions(projectRoot).then(function(platformVersions) { |
26 | | - var _ = context.requireCordovaModule('underscore'); |
27 | 26 | var IOS_MIN_DEPLOYMENT_TARGET = '7.0'; |
28 | 27 | var platformPath = path.join(projectRoot, 'platforms', 'ios'); |
29 | 28 |
|
@@ -54,34 +53,33 @@ module.exports = function(context) { |
54 | 53 |
|
55 | 54 | xcodeProject.parseSync(); |
56 | 55 |
|
57 | | - bridgingHeaderPath = unquote(xcodeProject.getBuildProperty('SWIFT_OBJC_BRIDGING_HEADER')); |
| 56 | + bridgingHeaderPath = getBridgingHeaderPath(context, projectPath, iosPlatformVersion); |
58 | 57 |
|
59 | 58 | try{ |
60 | 59 | fs.statSync(bridgingHeaderPath); |
61 | 60 | } catch(err) { |
62 | 61 | // If the bridging header doesn't exist, we create it with the minimum |
63 | 62 | // Cordova/CDV.h import. |
64 | | - |
65 | | - bridgingHeaderPath = getBridgingHeaderPath(context, projectPath, iosPlatformVersion); |
66 | | - |
67 | 63 | bridgingHeaderContent = [ '//', |
68 | 64 | '// Use this file to import your target\'s public headers that you would like to expose to Swift.', |
69 | 65 | '//', |
70 | 66 | '#import <Cordova/CDV.h>' ]; |
71 | | - |
72 | 67 | fs.writeFileSync(bridgingHeaderPath, bridgingHeaderContent.join('\n'), { encoding: 'utf-8', flag: 'w' }); |
73 | 68 | 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); |
76 | 69 | } |
77 | 70 |
|
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 | + } |
80 | 76 |
|
| 77 | + // Look for any bridging header defined in the plugin |
| 78 | + glob('**/*Bridging-Header*.h', { cwd: pluginsPath }, function(error, files) { |
81 | 79 | var bridgingHeader = path.basename(bridgingHeaderPath); |
82 | | - var headers = _.compact(stdout.toString().split('\n').map(function (filePath) { |
| 80 | + var headers = files.map(function (filePath) { |
83 | 81 | return path.basename(filePath); |
84 | | - })); |
| 82 | + }); |
85 | 83 |
|
86 | 84 | // if other bridging headers are found, they are imported in the |
87 | 85 | // one already configured in the project. |
@@ -134,18 +132,11 @@ function getConfigParser(context, config) { |
134 | 132 | function getBridgingHeaderPath(context, projectPath, iosPlatformVersion) { |
135 | 133 | var semver = context.requireCordovaModule('semver'); |
136 | 134 | var bridgingHeaderPath; |
137 | | - |
138 | 135 | 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'); |
140 | 137 | } else { |
141 | | - bridgingHeaderPath = path.join(projectPath, 'Bridging-Header.h'); |
| 138 | + bridgingHeaderPath = path.posix.join(projectPath, 'Bridging-Header.h'); |
142 | 139 | } |
143 | 140 |
|
144 | 141 | return bridgingHeaderPath; |
145 | 142 | } |
146 | | - |
147 | | -function unquote(str) { |
148 | | - if (str) { |
149 | | - return str.replace(/^"(.*)"$/, '$1'); |
150 | | - } |
151 | | -} |
0 commit comments