├── .editorconfig ├── .eslintrc.json ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── package.json ├── plugin.xml └── src └── add-swift-support.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "standard", 3 | "rules": { 4 | "semi": [2, "always"] 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | *.orig 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | webpack.config.js 2 | .travis.yml 3 | .editorconfig 4 | .eslintrc 5 | .npmignore 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - "6" 5 | - "8" 6 | - "10" 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [2.0.2](https://github.com/akofman/cordova-plugin-add-swift-support/tree/2.0.2) (2019-04-05) 4 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/2.0.1...2.0.2) 5 | 6 | **Merged pull requests:** 7 | 8 | - Script needs to be quoted [\#59](https://github.com/akofman/cordova-plugin-add-swift-support/pull/59) ([shivan](https://github.com/shivan)) 9 | 10 | ## [2.0.1](https://github.com/akofman/cordova-plugin-add-swift-support/tree/2.0.1) (2019-04-01) 11 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/2.0.0...2.0.1) 12 | 13 | **Closed issues:** 14 | 15 | - add-swift-support.js of v2.0 is missing on npm [\#58](https://github.com/akofman/cordova-plugin-add-swift-support/issues/58) 16 | - Support cordova-cli 9.0.0 - requireCordovaModule deprecation [\#56](https://github.com/akofman/cordova-plugin-add-swift-support/issues/56) 17 | - Swift 4 support [\#55](https://github.com/akofman/cordova-plugin-add-swift-support/issues/55) 18 | - Swift 4 is failing with latest cordova [\#50](https://github.com/akofman/cordova-plugin-add-swift-support/issues/50) 19 | 20 | ## [2.0.0](https://github.com/akofman/cordova-plugin-add-swift-support/tree/2.0.0) (2019-04-01) 21 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.7.2...2.0.0) 22 | 23 | **Merged pull requests:** 24 | 25 | - refactor: update tooling, add support for Cordova v9 [\#57](https://github.com/akofman/cordova-plugin-add-swift-support/pull/57) ([timbru31](https://github.com/timbru31)) 26 | - Document where to specify Swift version preference [\#53](https://github.com/akofman/cordova-plugin-add-swift-support/pull/53) ([eladnava](https://github.com/eladnava)) 27 | 28 | ## [1.7.2](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.7.2) (2018-03-30) 29 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.7.1...1.7.2) 30 | 31 | **Closed issues:** 32 | 33 | - Implement catching promise rejections [\#51](https://github.com/akofman/cordova-plugin-add-swift-support/issues/51) 34 | - \*-Briding-Header.h not used [\#48](https://github.com/akofman/cordova-plugin-add-swift-support/issues/48) 35 | - SWIFT\_VERSION build setting not being applied @1.7.1 [\#47](https://github.com/akofman/cordova-plugin-add-swift-support/issues/47) 36 | - Unhandled promise rejection \(rejection id: 1\): Error: Cannot find module '../cordova/platform\_metadata' [\#44](https://github.com/akofman/cordova-plugin-add-swift-support/issues/44) 37 | - Can not restore this plugin when using cordova-cli@8.0.0 [\#43](https://github.com/akofman/cordova-plugin-add-swift-support/issues/43) 38 | - Hook won't trigger [\#40](https://github.com/akofman/cordova-plugin-add-swift-support/issues/40) 39 | - Error adding cordova-plugin-add-swift-support [\#39](https://github.com/akofman/cordova-plugin-add-swift-support/issues/39) 40 | - OSX support [\#19](https://github.com/akofman/cordova-plugin-add-swift-support/issues/19) 41 | 42 | **Merged pull requests:** 43 | 44 | - Fix for cordova projects located in paths with spaces [\#52](https://github.com/akofman/cordova-plugin-add-swift-support/pull/52) ([TheLiquidSky](https://github.com/TheLiquidSky)) 45 | 46 | ## [1.7.1](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.7.1) (2017-12-22) 47 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.7.0...1.7.1) 48 | 49 | **Closed issues:** 50 | 51 | - SWIFT\_VERSION build setting not being applied [\#42](https://github.com/akofman/cordova-plugin-add-swift-support/issues/42) 52 | - Node.JS 8.X Support [\#38](https://github.com/akofman/cordova-plugin-add-swift-support/issues/38) 53 | - Missing tag and changelog for 1.7.0 [\#33](https://github.com/akofman/cordova-plugin-add-swift-support/issues/33) 54 | 55 | **Merged pull requests:** 56 | 57 | - fix\(\): platform\_metadata is now project\_metadata [\#45](https://github.com/akofman/cordova-plugin-add-swift-support/pull/45) ([mhartington](https://github.com/mhartington)) 58 | - add OSX paltform support [\#37](https://github.com/akofman/cordova-plugin-add-swift-support/pull/37) ([tryadelion](https://github.com/tryadelion)) 59 | 60 | ## [1.7.0](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.7.0) (2017-07-07) 61 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.6.0...1.7.0) 62 | 63 | **Closed issues:** 64 | 65 | - Wrong text merged in Briding-Header.h [\#31](https://github.com/akofman/cordova-plugin-add-swift-support/issues/31) 66 | - Phonegap Build Support [\#28](https://github.com/akofman/cordova-plugin-add-swift-support/issues/28) 67 | - how to ? [\#26](https://github.com/akofman/cordova-plugin-add-swift-support/issues/26) 68 | - swift3 required me to explicitly expose plugin method [\#23](https://github.com/akofman/cordova-plugin-add-swift-support/issues/23) 69 | - Keep Xcode7 compatibility [\#20](https://github.com/akofman/cordova-plugin-add-swift-support/issues/20) 70 | 71 | **Merged pull requests:** 72 | 73 | - Set swift version in config.xml [\#30](https://github.com/akofman/cordova-plugin-add-swift-support/pull/30) ([NiklasMerz](https://github.com/NiklasMerz)) 74 | 75 | ## [1.6.0](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.6.0) (2017-01-10) 76 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.4.0...1.6.0) 77 | 78 | **Closed issues:** 79 | 80 | - Differences between plugins [\#24](https://github.com/akofman/cordova-plugin-add-swift-support/issues/24) 81 | - Error: undefined is not a function [\#22](https://github.com/akofman/cordova-plugin-add-swift-support/issues/22) 82 | - Debug builds should be compiled without optimizations [\#18](https://github.com/akofman/cordova-plugin-add-swift-support/issues/18) 83 | - Hook fails to run properly with cordova 6.3.1 [\#14](https://github.com/akofman/cordova-plugin-add-swift-support/issues/14) 84 | 85 | **Merged pull requests:** 86 | 87 | - Next [\#25](https://github.com/akofman/cordova-plugin-add-swift-support/pull/25) ([akofman](https://github.com/akofman)) 88 | - enabled debugging swift in Debug configuration [\#21](https://github.com/akofman/cordova-plugin-add-swift-support/pull/21) ([viskin](https://github.com/viskin)) 89 | 90 | ## [1.4.0](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.4.0) (2016-10-07) 91 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.3.2...1.4.0) 92 | 93 | **Closed issues:** 94 | 95 | - \[Xcode 8\] Update embed Swift standard libraries setting [\#17](https://github.com/akofman/cordova-plugin-add-swift-support/issues/17) 96 | - Set "Legacy Swift Language Version" [\#15](https://github.com/akofman/cordova-plugin-add-swift-support/issues/15) 97 | 98 | **Merged pull requests:** 99 | 100 | - Set legacy swift version [\#16](https://github.com/akofman/cordova-plugin-add-swift-support/pull/16) ([NiklasMerz](https://github.com/NiklasMerz)) 101 | 102 | ## [1.3.2](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.3.2) (2016-09-03) 103 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.2.0...1.3.2) 104 | 105 | **Closed issues:** 106 | 107 | - Changes are made only to the current configuration \(tipically Debug\) [\#12](https://github.com/akofman/cordova-plugin-add-swift-support/issues/12) 108 | - Windows support [\#5](https://github.com/akofman/cordova-plugin-add-swift-support/issues/5) 109 | - App Store: invalid swift support [\#4](https://github.com/akofman/cordova-plugin-add-swift-support/issues/4) 110 | 111 | **Merged pull requests:** 112 | 113 | - Correctly update the properties for all build configurations [\#13](https://github.com/akofman/cordova-plugin-add-swift-support/pull/13) ([bugnano](https://github.com/bugnano)) 114 | - Hooks [\#8](https://github.com/akofman/cordova-plugin-add-swift-support/pull/8) ([akofman](https://github.com/akofman)) 115 | 116 | ## [1.2.0](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.2.0) (2016-06-10) 117 | [Full Changelog](https://github.com/akofman/cordova-plugin-add-swift-support/compare/1.1.0...1.2.0) 118 | 119 | **Closed issues:** 120 | 121 | - Changing hook type [\#3](https://github.com/akofman/cordova-plugin-add-swift-support/issues/3) 122 | 123 | **Merged pull requests:** 124 | 125 | - Windows [\#7](https://github.com/akofman/cordova-plugin-add-swift-support/pull/7) ([akofman](https://github.com/akofman)) 126 | 127 | ## [1.1.0](https://github.com/akofman/cordova-plugin-add-swift-support/tree/1.1.0) (2016-06-09) 128 | **Closed issues:** 129 | 130 | - Check the version of cordova-ios instead of the version of the CLI [\#1](https://github.com/akofman/cordova-plugin-add-swift-support/issues/1) 131 | 132 | **Merged pull requests:** 133 | 134 | - Hook [\#6](https://github.com/akofman/cordova-plugin-add-swift-support/pull/6) ([akofman](https://github.com/akofman)) 135 | 136 | 137 | 138 | \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present Alexis Kofman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://badge.fury.io/js/cordova-plugin-add-swift-support.svg)](https://badge.fury.io/js/cordova-plugin-add-swift-support) [![Build Status](https://travis-ci.org/akofman/cordova-plugin-add-swift-support.svg?branch=master)](https://travis-ci.org/akofman/cordova-plugin-add-swift-support) [![npm](https://img.shields.io/npm/dm/cordova-plugin-add-swift-support.svg)]() 2 | 3 | # cordova-plugin-add-swift-support 4 | 5 | ![swift-128x128](https://cloud.githubusercontent.com/assets/579922/15999501/79196b48-3146-11e6-836e-061a7ef53571.png) 6 | 7 | This [Cordova plugin](https://www.npmjs.com/package/cordova-plugin-add-swift-support) adds the Swift support to your iOS project. 8 | 9 | ## Installation 10 | 11 | You can add this plugin directly to your project: 12 | 13 | `cordova plugin add cordova-plugin-add-swift-support --save` 14 | 15 | Or add it as a dependency into your own plugin: 16 | 17 | `` 18 | 19 | By default, the Swift 4 support is added but the legacy version (2.3) can still be configured as a preference, inside the project's `config.xml`, within the `` section: 20 | 21 | `` 22 | 23 | Or it is possible to specify the version as following, inside the project's `config.xml`, within the `` section: 24 | 25 | `` 26 | 27 | If needed, add a prefixed Bridging-Header file in your plugin in order to import frameworks (MyPlugin-Bridging-Header.h for instance). 28 | As an example you can have a look at this [plugin](https://github.com/akofman/cordova-plugin-permissionScope). 29 | 30 | If the `cordova-plugin-add-swift-support` plugin is already installed to your project, then you can add your own Swift plugin as usual, its prefixed Bridging-Header will be automatically found and merged. 31 | 32 | ## Contributing 33 | 34 | The src folder contains ECMAScript 2015 source files, the minimum Node.js version is `6` (Boron). 35 | 36 | ## License 37 | 38 | MIT 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cordova-plugin-add-swift-support", 3 | "version": "2.0.2", 4 | "description": "Add Swift support to your iOS plugins", 5 | "homepage": "https://github.com/akofman/cordova-plugin-add-swift-support", 6 | "author": { 7 | "name": "Alexis Kofman", 8 | "email": "alexis.kofman@gmail.com", 9 | "url": "http://twitter.com/alexiskofman" 10 | }, 11 | "cordova": { 12 | "id": "cordova-plugin-add-swift-support", 13 | "platforms": [ 14 | "ios" 15 | ] 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/akofman/cordova-plugin-add-swift-support.git" 20 | }, 21 | "keywords": [ 22 | "cordova", 23 | "ios", 24 | "swift", 25 | "swift-support", 26 | "ecosystem:cordova", 27 | "cordova-ios", 28 | "cordova:plugin" 29 | ], 30 | "license": "Apache-2.0", 31 | "dependencies": { 32 | "glob": "^7.1.3", 33 | "semver": "^6.0.0", 34 | "xcode": "^2.0.0" 35 | }, 36 | "devDependencies": { 37 | "acorn": "^6.1.1", 38 | "eslint": "^5.15.3", 39 | "eslint-config-standard": "^12.0.0", 40 | "eslint-plugin-import": "^2.16.0", 41 | "eslint-plugin-node": "^8.0.1", 42 | "eslint-plugin-promise": "^4.0.1", 43 | "eslint-plugin-standard": "^4.0.0" 44 | }, 45 | "scripts": { 46 | "test": "eslint src" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | AddSwiftSupport 5 | Apache 2.0 6 | Cordova plugin to add swift support 7 | cordova,phonegap,swift,plugin 8 | https://github.com/akofman/cordova-plugin-add-swift-support.git 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/add-swift-support.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This hook adds all the needed config to implement a Cordova plugin with Swift. 3 | * 4 | * - It adds a Bridging header importing Cordova/CDV.h if it's not already 5 | * the case. Else it concats all the bridging headers in one single file. 6 | * 7 | * /!\ Please be sure not naming your bridging header file 'Bridging-Header.h' 8 | * else it won't be supported. 9 | * 10 | * - It puts the ios deployment target to 7.0 in case your project would have a 11 | * lesser one. 12 | * 13 | * - It updates the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES build setting to YES. 14 | * 15 | * - It updates the SWIFT_VERSION to 4.0. 16 | */ 17 | 18 | const fs = require('fs'); 19 | const path = require('path'); 20 | const xcode = require('xcode'); 21 | const childProcess = require('child_process'); 22 | const semver = require('semver'); 23 | const glob = require('glob'); 24 | 25 | module.exports = context => { 26 | const projectRoot = context.opts.projectRoot; 27 | 28 | // This script has to be executed depending on the command line arguments, not 29 | // on the hook execution cycle. 30 | if ((context.hook === 'after_platform_add' && context.cmdLine.includes('platform add')) || 31 | (context.hook === 'after_prepare' && context.cmdLine.includes('prepare')) || 32 | (context.hook === 'after_plugin_add' && context.cmdLine.includes('plugin add'))) { 33 | getPlatformVersionsFromFileSystem(context, projectRoot).then(platformVersions => { 34 | const IOS_MIN_DEPLOYMENT_TARGET = '7.0'; 35 | const platformPath = path.join(projectRoot, 'platforms', 'ios'); 36 | const config = getConfigParser(context, path.join(projectRoot, 'config.xml')); 37 | 38 | let bridgingHeaderPath; 39 | let bridgingHeaderContent; 40 | let projectName; 41 | let projectPath; 42 | let pluginsPath; 43 | let iosPlatformVersion; 44 | let pbxprojPath; 45 | let xcodeProject; 46 | 47 | const COMMENT_KEY = /_comment$/; 48 | let buildConfigs; 49 | let buildConfig; 50 | let configName; 51 | 52 | platformVersions.forEach((platformVersion) => { 53 | if (platformVersion.platform === 'ios') { 54 | iosPlatformVersion = platformVersion.version; 55 | } 56 | }); 57 | 58 | if (!iosPlatformVersion) { 59 | return; 60 | } 61 | 62 | projectName = config.name(); 63 | projectPath = path.join(platformPath, projectName); 64 | pbxprojPath = path.join(platformPath, projectName + '.xcodeproj', 'project.pbxproj'); 65 | xcodeProject = xcode.project(pbxprojPath); 66 | pluginsPath = path.join(projectPath, 'Plugins'); 67 | 68 | xcodeProject.parseSync(); 69 | 70 | bridgingHeaderPath = getBridgingHeaderPath(projectPath, iosPlatformVersion); 71 | 72 | try { 73 | fs.statSync(bridgingHeaderPath); 74 | } catch (err) { 75 | // If the bridging header doesn't exist, we create it with the minimum 76 | // Cordova/CDV.h import. 77 | bridgingHeaderContent = ['//', 78 | '// Use this file to import your target\'s public headers that you would like to expose to Swift.', 79 | '//', 80 | '#import ']; 81 | fs.writeFileSync(bridgingHeaderPath, bridgingHeaderContent.join('\n'), { encoding: 'utf-8', flag: 'w' }); 82 | xcodeProject.addHeaderFile('Bridging-Header.h'); 83 | } 84 | 85 | buildConfigs = xcodeProject.pbxXCBuildConfigurationSection(); 86 | 87 | const bridgingHeaderProperty = '"$(PROJECT_DIR)/$(PROJECT_NAME)' + bridgingHeaderPath.split(projectPath)[1] + '"'; 88 | 89 | for (configName in buildConfigs) { 90 | if (!COMMENT_KEY.test(configName)) { 91 | buildConfig = buildConfigs[configName]; 92 | if (xcodeProject.getBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', buildConfig.name) !== bridgingHeaderProperty) { 93 | xcodeProject.updateBuildProperty('SWIFT_OBJC_BRIDGING_HEADER', bridgingHeaderProperty, buildConfig.name); 94 | console.log('Update IOS build setting SWIFT_OBJC_BRIDGING_HEADER to:', bridgingHeaderProperty, 'for build configuration', buildConfig.name); 95 | } 96 | } 97 | } 98 | 99 | // Look for any bridging header defined in the plugin 100 | glob('**/*Bridging-Header*.h', { cwd: pluginsPath }, (error, files) => { 101 | const bridgingHeader = path.basename(bridgingHeaderPath); 102 | const headers = files.map((filePath) => path.basename(filePath)); 103 | 104 | // if other bridging headers are found, they are imported in the 105 | // one already configured in the project. 106 | let content = fs.readFileSync(bridgingHeaderPath, 'utf-8'); 107 | 108 | if (error) throw new Error(error); 109 | 110 | headers.forEach((header) => { 111 | if (header !== bridgingHeader && !~content.indexOf(header)) { 112 | if (content.charAt(content.length - 1) !== '\n') { 113 | content += '\n'; 114 | } 115 | content += '#import "' + header + '"\n'; 116 | console.log('Importing', header, 'into', bridgingHeaderPath); 117 | } 118 | }); 119 | fs.writeFileSync(bridgingHeaderPath, content, 'utf-8'); 120 | 121 | for (configName in buildConfigs) { 122 | if (!COMMENT_KEY.test(configName)) { 123 | buildConfig = buildConfigs[configName]; 124 | if (parseFloat(xcodeProject.getBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', buildConfig.name)) < parseFloat(IOS_MIN_DEPLOYMENT_TARGET)) { 125 | xcodeProject.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', IOS_MIN_DEPLOYMENT_TARGET, buildConfig.name); 126 | console.log('Update IOS project deployment target to:', IOS_MIN_DEPLOYMENT_TARGET, 'for build configuration', buildConfig.name); 127 | } 128 | 129 | if (xcodeProject.getBuildProperty('ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES', buildConfig.name) !== 'YES') { 130 | xcodeProject.updateBuildProperty('ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES', 'YES', buildConfig.name); 131 | console.log('Update IOS build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to: YES', 'for build configuration', buildConfig.name); 132 | } 133 | 134 | if (xcodeProject.getBuildProperty('LD_RUNPATH_SEARCH_PATHS', buildConfig.name) !== '"@executable_path/Frameworks"') { 135 | xcodeProject.updateBuildProperty('LD_RUNPATH_SEARCH_PATHS', '"@executable_path/Frameworks"', buildConfig.name); 136 | console.log('Update IOS build setting LD_RUNPATH_SEARCH_PATHS to: @executable_path/Frameworks', 'for build configuration', buildConfig.name); 137 | } 138 | 139 | if (typeof xcodeProject.getBuildProperty('SWIFT_VERSION', buildConfig.name) === 'undefined') { 140 | if (config.getPreference('UseLegacySwiftLanguageVersion', 'ios')) { 141 | xcodeProject.updateBuildProperty('SWIFT_VERSION', '2.3', buildConfig.name); 142 | console.log('Use legacy Swift language version', buildConfig.name); 143 | } else if (config.getPreference('UseSwiftLanguageVersion', 'ios')) { 144 | const swiftVersion = config.getPreference('UseSwiftLanguageVersion', 'ios'); 145 | xcodeProject.updateBuildProperty('SWIFT_VERSION', swiftVersion, buildConfig.name); 146 | console.log('Use Swift language version', swiftVersion); 147 | } else { 148 | xcodeProject.updateBuildProperty('SWIFT_VERSION', '4.0', buildConfig.name); 149 | console.log('Update SWIFT version to 4.0', buildConfig.name); 150 | } 151 | } 152 | 153 | if (buildConfig.name === 'Debug') { 154 | if (xcodeProject.getBuildProperty('SWIFT_OPTIMIZATION_LEVEL', buildConfig.name) !== '"-Onone"') { 155 | xcodeProject.updateBuildProperty('SWIFT_OPTIMIZATION_LEVEL', '"-Onone"', buildConfig.name); 156 | console.log('Update IOS build setting SWIFT_OPTIMIZATION_LEVEL to: -Onone', 'for build configuration', buildConfig.name); 157 | } 158 | } 159 | } 160 | } 161 | 162 | fs.writeFileSync(pbxprojPath, xcodeProject.writeSync()); 163 | }); 164 | }); 165 | } 166 | }; 167 | 168 | const getConfigParser = (context, configPath) => { 169 | let ConfigParser; 170 | 171 | if (semver.lt(context.opts.cordova.version, '5.4.0')) { 172 | ConfigParser = context.requireCordovaModule('cordova-lib/src/ConfigParser/ConfigParser'); 173 | } else { 174 | ConfigParser = context.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser'); 175 | } 176 | 177 | return new ConfigParser(configPath); 178 | }; 179 | 180 | const getBridgingHeaderPath = (projectPath, iosPlatformVersion) => { 181 | let bridgingHeaderPath; 182 | if (semver.lt(iosPlatformVersion, '4.0.0')) { 183 | bridgingHeaderPath = path.posix.join(projectPath, 'Plugins', 'Bridging-Header.h'); 184 | } else { 185 | bridgingHeaderPath = path.posix.join(projectPath, 'Bridging-Header.h'); 186 | } 187 | 188 | return bridgingHeaderPath; 189 | }; 190 | 191 | const getPlatformVersionsFromFileSystem = (context, projectRoot) => { 192 | const cordovaUtil = context.requireCordovaModule('cordova-lib/src/cordova/util'); 193 | const platformsOnFs = cordovaUtil.listPlatforms(projectRoot); 194 | const platformVersions = platformsOnFs.map(platform => { 195 | const script = path.join(projectRoot, 'platforms', platform, 'cordova', 'version'); 196 | return new Promise((resolve, reject) => { 197 | childProcess.exec('"' + script + '"', {}, (error, stdout, _) => { 198 | if (error) { 199 | reject(error); 200 | return; 201 | } 202 | resolve(stdout.trim()); 203 | }); 204 | }).then(result => { 205 | const version = result.replace(/\r?\n|\r/g, ''); 206 | return { platform, version }; 207 | }, (error) => { 208 | console.log(error); 209 | process.exit(1); 210 | }); 211 | }); 212 | 213 | return Promise.all(platformVersions); 214 | }; 215 | --------------------------------------------------------------------------------