├── .npmrc ├── bad_resource.png ├── linker_error.png ├── scripts ├── bump-plugin-xml.js └── podify.js ├── .gitignore ├── plugin.xml ├── LICENSE ├── package.json ├── schemes ├── CordovaLib.xcscheme └── App.xcscheme └── README.md /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false -------------------------------------------------------------------------------- /bad_resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blakgeek/cordova-plugin-cocoapods-support/HEAD/bad_resource.png -------------------------------------------------------------------------------- /linker_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blakgeek/cordova-plugin-cocoapods-support/HEAD/linker_error.png -------------------------------------------------------------------------------- /scripts/bump-plugin-xml.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var libxml = require('libxmljs'); 3 | var version = process.env.npm_package_version; 4 | var content = fs.readFileSync('plugin.xml'); 5 | var xml = libxml.parseXmlString(content); 6 | xml.get('/p:plugin', { 7 | 'p': 'http://apache.org/cordova/ns/plugins/1.0' 8 | }).attr({ 9 | 'version': version 10 | }); 11 | 12 | fs.writeFileSync('plugin.xml', xml.toString()); 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Node template 3 | # Logs 4 | logs 5 | *.log 6 | npm-debug.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | 28 | # Dependency directory 29 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 30 | node_modules 31 | .idea/ 32 | *.iml 33 | 34 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Cordova CocoaPods Dependency Support 4 | Carlos "blakgeek" Lawton 5 | A Cordova/PhoneGap plugin to add support for CocoaPods dependencies. 6 | cordova, ios, cocoapods, pod, pods 7 | https://github.com/blakgeek/cordova-plugin-cocoapods-support.git 8 | https://github.com/blakgeek/cordova-plugin-cocoapods-support/issues 9 | MIT 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 blakgeek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-cocoapod-support", 3 | "version": "1.6.2", 4 | "description": "A Cordova/PhoneGap plugin to add support for Cocoapod dependencies.", 5 | "cordova": { 6 | "id": "cordova-plugin-cocoapod-support", 7 | "platforms": [ 8 | "ios", 9 | "android" 10 | ] 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/blakgeek/cordova-plugin-cocoapods-support.git" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/blakgeek/cordova-plugin-cocoapods-support/issues" 18 | }, 19 | "homepage": "https://github.com/blakgeek/cordova-plugin-cocoapods-support", 20 | "keywords": [ 21 | "ecosystem:cordova", 22 | "cordova-ios", 23 | "cordova:plugin", 24 | "cocoapods", 25 | "pod", 26 | "pods", 27 | "plugin" 28 | ], 29 | "license": "MIT", 30 | "dependencies": { 31 | "lodash": "^4.17.2", 32 | "q": "^1.5.1", 33 | "semver": "^5.3.0", 34 | "shelljs": "^0.7.5", 35 | "xml2js": "^0.4.16" 36 | }, 37 | "scripts": { 38 | "postversion": "node scripts/bump-plugin-xml.js; git add plugin.xml; git commit plugin.xml -m \"v${npm_package_version}\"" 39 | }, 40 | "devDependencies": { 41 | "libxmljs": "^0.18.4" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /schemes/CordovaLib.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /schemes/App.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cordova-plugin-cocoapod-support 2 | Are you tired of manually adding ios dependencies in Cordova apps? Me too. Android has Gradle support out of the box, but 3 | CocoaPods get no love. That is until now. 4 | 5 | With this plugin you can define plugin or project CocoaPods dependencies right in the xml. 6 | 7 | After adding this plugin be sure to open the .xcworkspace in XCode instead of the .xcodeproj. 8 | 9 | *Note*: Dependencies defined in the config.xml take precedence of dependencies defined in plugin's. 10 | 11 | *Note*: The highest value of minimum ios version will be used and use_frameworks! will be enabled if the flag is set anywhere. 12 | 13 | ## How does it work? 14 | It looks for <pod> entries the config.xml and plugin.xml, creates the Podfile, updates the necessary configs and 15 | then runs pod update for you. 16 | 17 | ## How do I install it? 18 | 19 | If you're like me and using [Cordova CLI](http://cordova.apache.org/): 20 | ``` 21 | cordova plugin add cordova-plugin-cocoapod-support --save 22 | ``` 23 | 24 | or 25 | 26 | ``` 27 | phonegap local plugin add cordova-plugin-cocoapod-support 28 | ``` 29 | 30 | ## How do I use it? 31 | 32 | Plugin developers, here's a sample plugin.xml. 33 | ```xml 34 | 35 | 36 | A Plugin With CocoaPods Dependencies 37 | 38 | A plugin demonstrating the use of CocoaPods dependencies. 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | ``` 69 | 70 | App developers, here's a sample config.xml. Entries in the config.xml will override the plugin.xml(s). 71 | This is useful if you need to resolve conflicts between plugins or if a plugin doesn't include it's iOS dependencies. 72 | ```xml 73 | 74 | 75 | CocoapodsDemo 76 | 77 | An app demonstrating the use of CocoaPods dependencies. 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | ``` 107 | 108 | ## Troubleshooting 109 | * If you get errors like the following. 110 | ``` 111 | error: Resource ".../Build/Products/Debug-iphonesimulator/Lock/Auth0.bundle" not found. Run 'pod install' to update the copy resources script 112 | ``` 113 | Add the fix-bundle-path attribute to the pod tag with the path after the device. In this case: 114 | ```xml 115 | 116 | ``` 117 | This is caused by a bug in the later versions of CocoaPods. 118 | 119 | or have a look at [the example plugin](https://github.com/blakgeek/cordova-plugin-cocoapods-support-example). 120 | 121 | ## Notes 122 | * The plugin now detects Cordova framework tags with type="podspec" so there shouldn't be anymore conflicts with the native functionality and the plugin. 123 | * Pod "id" was deprecated in version 1.3.0. You should use "name" instead. But don't worry "id" will continue to work. 124 | I made this change to better align with the podspec. 125 | * Enabling the pods_use_frameworks preference disables the bridged headers property added by 126 | [CB-10072](https://issues.apache.org/jira/browse/CB-10072). This might cause odd behavior in some projects. 127 | 128 | 129 | ##TODO: 130 | * Update with examples of all of the supported pod attributes (git, podspec, path, subspec, configuration(s) ) 131 | 132 | 133 | 134 | [bad_resource]: ./bad_resource.png "Bad Resource" 135 | [linker_error]: ./linker_error.png "Linker Error" 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /scripts/podify.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var _ = require('lodash'); 4 | var fs = require('fs'); 5 | var path = require("path"); 6 | var xml2js = require('xml2js'); 7 | var spawn = require('child_process').spawn; 8 | var parser = new xml2js.Parser(); 9 | var Q = require('q'); 10 | var semver = require('semver'); 11 | require('shelljs/global'); 12 | 13 | module.exports = function (context) { 14 | 15 | if (!context.opts.platforms || !context.opts.platforms.includes('ios')) { 16 | return; 17 | } 18 | 19 | var podfileContents = []; 20 | var rootPath = context.opts.projectRoot; 21 | var configXmlPath = path.join(rootPath, 'config.xml'); 22 | var configParser = getConfigParser(context, configXmlPath); 23 | var appName = configParser.name(); 24 | var oldMinVersion = configParser.getPreference('pods_ios_min_version', 'ios') || 25 | configParser.getPreference('pods_ios_min_version'); 26 | var iosMinVersion = configParser.getPreference('deployment-target', 'ios') || 27 | configParser.getPreference('deployment-target') || 28 | oldMinVersion || '7.0'; 29 | var useFrameworks = configParser.getPreference('pods_use_frameworks', 'ios') || configParser.getPreference('pods_use_frameworks') || 'false'; 30 | var podConfigPath = path.join(rootPath, 'platforms', 'ios', '.pods.json'); 31 | var pod, podName; 32 | var podified = fs.existsSync(podConfigPath); 33 | var currentPods = podified ? JSON.parse(fs.readFileSync(podConfigPath)) : {}; 34 | var workspaceDir = path.join(rootPath, 'platforms', 'ios', '' + appName + '.xcworkspace'); 35 | var sharedDataDir = path.join(workspaceDir, 'xcshareddata'); 36 | var pluginDir = context.opts.plugin.pluginInfo.dir; 37 | var schemesSrcDir = path.join(pluginDir, 'schemes'); 38 | var schemesTargetDir = path.join(sharedDataDir, 'xcschemes'); 39 | var bundlePathsToFix = []; 40 | var newPods = { 41 | pods: {}, 42 | sources: {} 43 | }; 44 | 45 | if (oldMinVersion) { 46 | console.warn('The preference "pods_ios_min_version" has been deprecated. Please use "deployment-target" instead.'); 47 | } 48 | 49 | log('Searching for new pods'); 50 | 51 | return Q.all(parsePluginXmls()) 52 | .then(parseConfigXml) 53 | .then(createFiles) 54 | .then(installPods) 55 | .then(fixBundlePaths) 56 | .then(updateBuild); 57 | 58 | function parseConfigXml() { 59 | 60 | parser.parseString(fs.readFileSync('config.xml'), function (err, data) { 61 | 62 | if (data.widget.platform) { 63 | log('Checking config.xml for pods.'); 64 | data.widget.platform.forEach(function (platform) { 65 | if (platform.$.name === 'ios') { 66 | (platform.pod || []).forEach(function (pod) { 67 | var name = pod.$.name || pod.$.id; 68 | newPods.pods[name] = pod.$; 69 | log(`config.xml requires pod: ${name}`); 70 | }); 71 | } 72 | }); 73 | } 74 | }); 75 | } 76 | 77 | function parsePluginXmls() { 78 | 79 | var promises = []; 80 | context.opts.cordova.plugins.forEach(id => { 81 | 82 | const deferred = Q.defer(); 83 | 84 | parser.parseString(fs.readFileSync('plugins/' + id + '/plugin.xml'), function (err, data) { 85 | 86 | if (err) { 87 | deferred.reject(err); 88 | } else { 89 | if (data.plugin.platform) { 90 | log(`Checking ${id} for pods.`); 91 | data.plugin.platform.forEach(function (platform) { 92 | 93 | if (platform.$.name === 'ios') { 94 | const podsConfig = (platform['pods-config'] || [])[0]; 95 | 96 | if (podsConfig) { 97 | iosMinVersion = maxVer(iosMinVersion, podsConfig.$ ? podsConfig.$['ios-min-version'] : iosMinVersion); 98 | useFrameworks = podsConfig.$ && podsConfig.$['use-frameworks'] === 'true' ? 'true' : useFrameworks; 99 | 100 | (podsConfig.source || []).forEach(function (podSource) { 101 | log(`${id} requires pod source: ${podSource.$.url}`); 102 | newPods.sources[podSource.$.url] = true; 103 | }); 104 | } 105 | 106 | // support native dependency specification 107 | // 108 | (platform.framework || []).forEach(framework => { 109 | 110 | if(framework.$.type === 'podspec') { 111 | 112 | let name = framework.$.src; 113 | newPods.pods[name] = Object.assign({type: 'native'}, framework.$); 114 | log(`${id} requires pod: ${name}`); 115 | } 116 | }); 117 | 118 | // tags takes precedence over cuz well... it's my plugin :) 119 | (platform.pod || []).forEach(function (pod) { 120 | var name = pod.$.name || pod.$.id; 121 | newPods.pods[name] = Object.assign({type: 'pod'}, pod.$); 122 | log(`${id} requires pod: ${name}`); 123 | }); 124 | } 125 | }); 126 | } 127 | 128 | deferred.resolve(); 129 | } 130 | }); 131 | 132 | promises.push(deferred.promise); 133 | }); 134 | return promises; 135 | } 136 | 137 | function createFiles() { 138 | 139 | newPods.iosMinVersion = iosMinVersion; 140 | newPods.useFrameworks = useFrameworks === 'true'; 141 | 142 | if (!podified || !_.isEqual(newPods, currentPods)) { 143 | 144 | podfileContents.push("platform :ios, '" + iosMinVersion + "'"); 145 | if (useFrameworks === 'true') { 146 | podfileContents.push("use_frameworks!"); 147 | } 148 | 149 | Object.keys(newPods.sources).forEach(function (podSource) { 150 | log("Adding pod source " + podSource); 151 | podfileContents.push("source '" + podSource + "'"); 152 | }); 153 | 154 | podfileContents.push("target '" + appName + "' do"); 155 | 156 | for (podName in newPods.pods) { 157 | 158 | let suffix; 159 | pod = newPods.pods[podName]; 160 | 161 | if (pod['fix-bundle-path']) { 162 | bundlePathsToFix.push(pod['fix-bundle-path']); 163 | } 164 | if (pod.version) { 165 | suffix = `, '${pod.version}'`; 166 | } else if (pod.git) { 167 | suffix = ", :git => '" + pod.git + "'"; 168 | if (pod.tag) { 169 | suffix += ", :tag => '" + pod.tag + "'"; 170 | } else if (pod.branch) { 171 | suffix += ", :branch => '" + pod.branch + "'"; 172 | } else if (pod.commit) { 173 | suffix += ", :commit => '" + pod.commit + "'"; 174 | } 175 | 176 | } else if (pod.path) { 177 | suffix = ", :path => '" + pod.path + "'"; 178 | } else if (pod.subspecs) { 179 | var specs = pod.subspecs.split(',').map(spec => `'${spec.trim()}'`); 180 | suffix = ", :subspecs => [" + specs.join() + "]"; 181 | } else if (pod.configuration) { 182 | suffix = ", :configuration => '" + pod.configuration + "'"; 183 | } else if (pod.configurations) { 184 | var configs = pod.configurations.split(',').map(config => `'${config.trim()}`); 185 | suffix = ", :subspecs => [" + configs.join() + "]"; 186 | } else if (pod.podspec) { 187 | suffix = ", :podspec => '" + pod.podspec + "'"; 188 | } else if (pod.spec) { 189 | suffix = pod.spec.startsWith(':') ? `, ${pod.spec}` : `, '${pod.spec}'`; 190 | } else { 191 | suffix = ''; 192 | } 193 | 194 | podfileContents.push(`\tpod '${podName}'${suffix}`); 195 | } 196 | podfileContents.push('end'); 197 | fs.writeFileSync('platforms/ios/Podfile', podfileContents.join('\n')); 198 | 199 | var debugXcContents = fs.readFileSync('platforms/ios/cordova/build-debug.xcconfig', 'utf8'); 200 | var includeRegex = new RegExp('#include "Pods/Target Support Files/Pods-' + appName + '/Pods-' + appName + '\\.\\w+\\.xcconfig"'); 201 | if (!includeRegex.test(debugXcContents)) { 202 | fs.writeFileSync('platforms/ios/cordova/build-debug.xcconfig', debugXcContents + '\n' + '#include "Pods/Target Support Files/Pods-' + appName + '/Pods-' + appName + '.debug.xcconfig"'); 203 | } 204 | var releaseXcContents = fs.readFileSync('platforms/ios/cordova/build-release.xcconfig', 'utf8'); 205 | if (!includeRegex.test(releaseXcContents)) { 206 | fs.writeFileSync('platforms/ios/cordova/build-release.xcconfig', releaseXcContents + '\n' + '#include "Pods/Target Support Files/Pods-' + appName + '/Pods-' + appName + '.release.xcconfig"'); 207 | } 208 | 209 | var buildConfigContext = fs.readFileSync('platforms/ios/cordova/build.xcconfig', 'utf8'); 210 | var bridgedHeaderRegex; 211 | if (useFrameworks) { 212 | bridgedHeaderRegex = /SWIFT_OBJC_BRIDGING_HEADER/g; 213 | fs.writeFileSync('platforms/ios/cordova/build.xcconfig', buildConfigContext.replace(bridgedHeaderRegex, '//SWIFT_OBJC_BRIDGING_HEADER')); 214 | } else { 215 | bridgedHeaderRegex = /\/\/SWIFT_OBJC_BRIDGING_HEADER/g; 216 | fs.writeFileSync('platforms/ios/cordova/build.xcconfig', buildConfigContext.replace(bridgedHeaderRegex, 'SWIFT_OBJC_BRIDGING_HEADER')); 217 | 218 | } 219 | 220 | fs.writeFileSync(podConfigPath, JSON.stringify(newPods, null, '\t')); 221 | } else { 222 | log('No new pods detects'); 223 | } 224 | } 225 | 226 | function installPods() { 227 | 228 | var deferred = Q.defer(); 229 | 230 | if (which('pod')) { 231 | 232 | if (!podified || !_.isEqual(newPods, currentPods)) { 233 | log("Installing pods"); 234 | log("Sit back and relax this could take a while."); 235 | var podInstall = spawn('pod', ['install'], { 236 | cwd: 'platforms/ios' 237 | }); 238 | podInstall.stdout.on('data', function (data) { 239 | log(data.toString('utf8')); 240 | }); 241 | podInstall.stderr.on('data', function (data) { 242 | console.error(data.toString('utf8')); 243 | }); 244 | podInstall.on('close', function (exitCode) { 245 | deferred.resolve(exitCode === 0); 246 | }); 247 | } else { 248 | deferred.resolve(false); 249 | } 250 | 251 | } else { 252 | log("\nAh man!. It doesn't look like you have CocoaPods installed.\n\nYou have two choices.\n\n1. Install Cocoapods:\n$ sudo gem install cocoapods\n2. Manually install the dependencies."); 253 | deferred.resolve(false); 254 | } 255 | 256 | return deferred.promise; 257 | } 258 | 259 | function fixBundlePaths(shouldRun) { 260 | 261 | if (bundlePathsToFix.length) { 262 | var podsResourcesSh = 'platforms/ios/Pods/Target Support Files/Pods-' + appName + '/Pods-' + appName + '-resources.sh'; 263 | var content = fs.readFileSync(podsResourcesSh, 'utf8'); 264 | 265 | bundlePathsToFix.forEach(function (path) { 266 | var fixedPath = appName + '.app/' + path.split('/').slice(1).join('/'); 267 | var regex = new RegExp('(install_resource.*)' + path, 'gi'); 268 | content = content.replace(regex, "$1" + fixedPath); 269 | 270 | }); 271 | fs.writeFileSync(podsResourcesSh, content); 272 | } 273 | 274 | 275 | return shouldRun; 276 | } 277 | 278 | function updateBuild(shouldRun) { 279 | 280 | if (shouldRun) { 281 | log('Updating ios build to use workspace.'); 282 | var buildContent = fs.readFileSync('platforms/ios/cordova/lib/build.js', 'utf8'); 283 | var targetRegex = new RegExp("'-target',\\s*projectName\\s*,", 'g'); 284 | var targetFix = "'-scheme', projectName,"; 285 | var projectRegex = new RegExp("'-project'\\s*,\\s*projectName\\s*\\+\\s*'\\.xcodeproj'\\s*,", 'g'); 286 | var projectFix = "'-workspace', projectName + '.xcworkspace',"; 287 | var xcodeprojRegex = /\.xcodeproj/g; 288 | var xcodeprojFix = '.xcworkspace'; 289 | var fixedBuildContent = buildContent 290 | .replace(targetRegex, targetFix) 291 | .replace(projectRegex, projectFix) 292 | .replace(xcodeprojRegex, xcodeprojFix); 293 | 294 | fs.writeFileSync('platforms/ios/cordova/lib/build.js', fixedBuildContent); 295 | 296 | if (!podified) { 297 | log('Adding schemes'); 298 | if (!test('-e', sharedDataDir)) { 299 | mkdir(sharedDataDir); 300 | } 301 | 302 | if (!test('-e', schemesTargetDir)) { 303 | mkdir(schemesTargetDir); 304 | } 305 | 306 | copyTpl(schemesSrcDir + '/CordovaLib.xcscheme', schemesTargetDir + '/CordovaLib.xcscheme', { 307 | appName: appName 308 | }); 309 | copyTpl(schemesSrcDir + '/App.xcscheme', schemesTargetDir + '/' + appName + '.xcscheme', { 310 | appName: appName, 311 | appId: '1D6058900D05DD3D006BFB54' 312 | }); 313 | } 314 | } 315 | } 316 | 317 | function fixSwiftLegacy(shouldRun) { 318 | var directories = getDirectories(path.join(__dirname + '/../../../platforms/ios/Pods/Target Support Files')), 319 | podXcContents, 320 | SWIFT_VERSION_REGX = /SWIFT_VERSION=(?:\d*\.)\d/g; 321 | if (useLegacy) { 322 | for (var i = 0; i < directories.length; i++) { 323 | if (directories[i].indexOf(appName) === -1) { 324 | podXcContents = fs.readFileSync('platforms/ios/Pods/Target Support Files/' + directories[i] + '/' + directories[i] + '.xcconfig', 'utf8'); 325 | if (podXcContents.indexOf('SWIFT_VERSION') === -1) { 326 | fs.writeFileSync('platforms/ios/Pods/Target Support Files/' + directories[i] + '/' + directories[i] + '.xcconfig', podXcContents + '\n' + 'SWIFT_VERSION=' + useLegacy) 327 | } else { 328 | fs.writeFileSync('platforms/ios/Pods/Target Support Files/' + directories[i] + '/' + directories[i] + '.xcconfig', podXcContents.replace(SWIFT_VERSION_REGX, 'SWIFT_VERSION=' + useLegacy)) 329 | } 330 | } 331 | } 332 | 333 | log('Using Swift Version ' + useLegacy); 334 | } 335 | 336 | return shouldRun; 337 | } 338 | 339 | function templify(str, data) { 340 | 341 | return str.replace(/{[^{}]+}/g, function (key) { 342 | var k = key.replace(/[{}]+/g, ""); 343 | return data.hasOwnProperty(k) ? data[k] : ""; 344 | }); 345 | } 346 | 347 | function copyTpl(src, dest, data) { 348 | fs.writeFileSync(dest, templify(fs.readFileSync(src, 'utf8'), data)); 349 | } 350 | 351 | function getConfigParser(context, config) { 352 | var ConfigParser; 353 | if (semver.lt(context.opts.cordova.version, '5.4.0')) { 354 | ConfigParser = context.requireCordovaModule('cordova-lib/src/ConfigParser/ConfigParser'); 355 | } else { 356 | ConfigParser = context.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser'); 357 | } 358 | 359 | return new ConfigParser(config); 360 | } 361 | 362 | function maxVer(v1, v2) { 363 | 364 | if (!v2) { 365 | return v1; 366 | } 367 | 368 | var v1Parts = v1.split('.'); 369 | var v2Parts = v2.split('.'); 370 | 371 | if (+v1Parts[0] > +v2Parts[0]) { 372 | return v1; 373 | } else if (+v1Parts[0] < +v2Parts[0]) { 374 | return v2; 375 | } else if (+v1Parts[1] > +v2Parts[1]) { 376 | return v1; 377 | } else { 378 | return v2; 379 | } 380 | } 381 | 382 | function log(message) { 383 | console.log(message); 384 | } 385 | }; 386 | 387 | --------------------------------------------------------------------------------