@@ -17,17 +17,17 @@ var fs = require('fs');
17
17
var path = require ( 'path' ) ;
18
18
var xcode = require ( 'xcode' ) ;
19
19
20
- module . exports = function ( context ) {
20
+ module . exports = function ( context ) {
21
21
var platformMetadata = context . requireCordovaModule ( 'cordova-lib/src/cordova/platform_metadata' ) ;
22
22
var projectRoot = context . opts . projectRoot ;
23
23
var glob = context . requireCordovaModule ( 'glob' ) ;
24
24
25
25
// This script has to be executed depending on the command line arguments, not
26
26
// on the hook execution cycle.
27
- if ( ( context . hook === 'after_platform_add' && context . cmdLine . includes ( 'platform add' ) )
28
- || ( context . hook === 'after_prepare' && context . cmdLine . includes ( 'prepare' ) )
29
- || ( context . hook === 'after_plugin_add' && context . cmdLine . includes ( 'plugin add' ) ) ) {
30
- platformMetadata . getPlatformVersions ( projectRoot ) . then ( function ( platformVersions ) {
27
+ if ( ( context . hook === 'after_platform_add' && context . cmdLine . includes ( 'platform add' ) ) ||
28
+ ( context . hook === 'after_prepare' && context . cmdLine . includes ( 'prepare' ) ) ||
29
+ ( context . hook === 'after_plugin_add' && context . cmdLine . includes ( 'plugin add' ) ) ) {
30
+ platformMetadata . getPlatformVersions ( projectRoot ) . then ( function ( platformVersions ) {
31
31
var IOS_MIN_DEPLOYMENT_TARGET = '7.0' ;
32
32
var platformPath = path . join ( projectRoot , 'platforms' , 'ios' ) ;
33
33
@@ -45,13 +45,13 @@ module.exports = function(context) {
45
45
var buildConfig ;
46
46
var configName ;
47
47
48
- platformVersions . forEach ( function ( platformVersion ) {
49
- if ( platformVersion . platform === 'ios' ) {
48
+ platformVersions . forEach ( function ( platformVersion ) {
49
+ if ( platformVersion . platform === 'ios' ) {
50
50
iosPlatformVersion = platformVersion . version ;
51
51
}
52
52
} ) ;
53
53
54
- if ( ! iosPlatformVersion ) {
54
+ if ( ! iosPlatformVersion ) {
55
55
return ;
56
56
}
57
57
@@ -65,9 +65,9 @@ module.exports = function(context) {
65
65
66
66
bridgingHeaderPath = getBridgingHeaderPath ( context , projectPath , iosPlatformVersion ) ;
67
67
68
- try {
68
+ try {
69
69
fs . statSync ( bridgingHeaderPath ) ;
70
- } catch ( err ) {
70
+ } catch ( err ) {
71
71
// If the bridging header doesn't exist, we create it with the minimum
72
72
// Cordova/CDV.h import.
73
73
bridgingHeaderContent = [ '//' ,
@@ -85,15 +85,15 @@ module.exports = function(context) {
85
85
for ( configName in buildConfigs ) {
86
86
if ( ! COMMENT_KEY . test ( configName ) ) {
87
87
buildConfig = buildConfigs [ configName ] ;
88
- if ( xcodeProject . getBuildProperty ( 'SWIFT_OBJC_BRIDGING_HEADER' , buildConfig . name ) !== bridgingHeaderProperty ) {
88
+ if ( xcodeProject . getBuildProperty ( 'SWIFT_OBJC_BRIDGING_HEADER' , buildConfig . name ) !== bridgingHeaderProperty ) {
89
89
xcodeProject . updateBuildProperty ( 'SWIFT_OBJC_BRIDGING_HEADER' , bridgingHeaderProperty , buildConfig . name ) ;
90
90
console . log ( 'Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to:' , bridgingHeaderProperty , 'for build configuration' , buildConfig . name ) ;
91
91
}
92
92
}
93
93
}
94
94
95
95
// Look for any bridging header defined in the plugin
96
- glob ( '**/*Bridging-Header*.h' , { cwd : pluginsPath } , function ( error , files ) {
96
+ glob ( '**/*Bridging-Header*.h' , { cwd : pluginsPath } , function ( error , files ) {
97
97
var bridgingHeader = path . basename ( bridgingHeaderPath ) ;
98
98
var headers = files . map ( function ( filePath ) {
99
99
return path . basename ( filePath ) ;
@@ -103,8 +103,10 @@ module.exports = function(context) {
103
103
// one already configured in the project.
104
104
var content = fs . readFileSync ( bridgingHeaderPath , 'utf-8' ) ;
105
105
106
- headers . forEach ( function ( header ) {
107
- if ( header !== bridgingHeader && ! ~ content . indexOf ( header ) ) {
106
+ if ( error ) throw new Error ( error ) ;
107
+
108
+ headers . forEach ( function ( header ) {
109
+ if ( header !== bridgingHeader && ! ~ content . indexOf ( header ) ) {
108
110
if ( content . charAt ( content . length - 1 ) !== '\n' ) {
109
111
content += '\n' ;
110
112
}
@@ -117,7 +119,7 @@ module.exports = function(context) {
117
119
for ( configName in buildConfigs ) {
118
120
if ( ! COMMENT_KEY . test ( configName ) ) {
119
121
buildConfig = buildConfigs [ configName ] ;
120
- if ( parseFloat ( xcodeProject . getBuildProperty ( 'IPHONEOS_DEPLOYMENT_TARGET' , buildConfig . name ) ) < parseFloat ( IOS_MIN_DEPLOYMENT_TARGET ) ) {
122
+ if ( parseFloat ( xcodeProject . getBuildProperty ( 'IPHONEOS_DEPLOYMENT_TARGET' , buildConfig . name ) ) < parseFloat ( IOS_MIN_DEPLOYMENT_TARGET ) ) {
121
123
xcodeProject . updateBuildProperty ( 'IPHONEOS_DEPLOYMENT_TARGET' , IOS_MIN_DEPLOYMENT_TARGET , buildConfig . name ) ;
122
124
console . log ( 'Update IOS project deployment target to:' , IOS_MIN_DEPLOYMENT_TARGET , 'for build configuration' , buildConfig . name ) ;
123
125
}
@@ -127,16 +129,15 @@ module.exports = function(context) {
127
129
console . log ( 'Update IOS build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to: YES' , 'for build configuration' , buildConfig . name ) ;
128
130
}
129
131
130
- if ( xcodeProject . getBuildProperty ( 'LD_RUNPATH_SEARCH_PATHS' , buildConfig . name ) !== '"@executable_path/Frameworks"' ) {
131
- xcodeProject . updateBuildProperty ( 'LD_RUNPATH_SEARCH_PATHS' , '"@executable_path/Frameworks"' , buildConfig . name ) ;
132
+ if ( xcodeProject . getBuildProperty ( 'LD_RUNPATH_SEARCH_PATHS' , buildConfig . name ) !== '"@executable_path/Frameworks"' ) {
133
+ xcodeProject . updateBuildProperty ( 'LD_RUNPATH_SEARCH_PATHS' , '"@executable_path/Frameworks"' , buildConfig . name ) ;
132
134
console . log ( 'Update IOS build setting LD_RUNPATH_SEARCH_PATHS to: @executable_path/Frameworks' , 'for build configuration' , buildConfig . name ) ;
133
135
}
134
136
135
- if ( typeof xcodeProject . getBuildProperty ( 'SWIFT_VERSION' , buildConfig . name ) === 'undefined' ) {
136
- xcodeProject . updateBuildProperty ( 'SWIFT_VERSION' , '3.0' , buildConfig . name ) ;
137
+ if ( typeof xcodeProject . getBuildProperty ( 'SWIFT_VERSION' , buildConfig . name ) === 'undefined' ) {
138
+ xcodeProject . updateBuildProperty ( 'SWIFT_VERSION' , '3.0' , buildConfig . name ) ;
137
139
console . log ( 'Update SWIFT version to' , 3.0 , buildConfig . name ) ;
138
140
}
139
-
140
141
}
141
142
}
142
143
@@ -146,11 +147,11 @@ module.exports = function(context) {
146
147
}
147
148
} ;
148
149
149
- function getConfigParser ( context , config ) {
150
+ function getConfigParser ( context , config ) {
150
151
var semver = context . requireCordovaModule ( 'semver' ) ;
151
152
var ConfigParser ;
152
153
153
- if ( semver . lt ( context . opts . cordova . version , '5.4.0' ) ) {
154
+ if ( semver . lt ( context . opts . cordova . version , '5.4.0' ) ) {
154
155
ConfigParser = context . requireCordovaModule ( 'cordova-lib/src/ConfigParser/ConfigParser' ) ;
155
156
} else {
156
157
ConfigParser = context . requireCordovaModule ( 'cordova-common/src/ConfigParser/ConfigParser' ) ;
@@ -159,10 +160,10 @@ function getConfigParser(context, config) {
159
160
return new ConfigParser ( config ) ;
160
161
}
161
162
162
- function getBridgingHeaderPath ( context , projectPath , iosPlatformVersion ) {
163
+ function getBridgingHeaderPath ( context , projectPath , iosPlatformVersion ) {
163
164
var semver = context . requireCordovaModule ( 'semver' ) ;
164
165
var bridgingHeaderPath ;
165
- if ( semver . lt ( iosPlatformVersion , '4.0.0' ) ) {
166
+ if ( semver . lt ( iosPlatformVersion , '4.0.0' ) ) {
166
167
bridgingHeaderPath = path . posix . join ( projectPath , 'Plugins' , 'Bridging-Header.h' ) ;
167
168
} else {
168
169
bridgingHeaderPath = path . posix . join ( projectPath , 'Bridging-Header.h' ) ;
0 commit comments