diff options
Diffstat (limited to 'StoneIsland/platforms/ios/cordova/Api.js')
| -rw-r--r--[-rwxr-xr-x] | StoneIsland/platforms/ios/cordova/Api.js | 551 |
1 files changed, 391 insertions, 160 deletions
diff --git a/StoneIsland/platforms/ios/cordova/Api.js b/StoneIsland/platforms/ios/cordova/Api.js index dd50d11f..a7b62b68 100755..100644 --- a/StoneIsland/platforms/ios/cordova/Api.js +++ b/StoneIsland/platforms/ios/cordova/Api.js @@ -19,17 +19,27 @@ /* jslint node: true */ -var fs = require('fs'); -var path = require('path'); -var unorm = require('unorm'); -var projectFile = require('./lib/projectFile'); -var check_reqs = require('./lib/check_reqs'); -var CordovaError = require('cordova-common').CordovaError; -var CordovaLogger = require('cordova-common').CordovaLogger; -var events = require('cordova-common').events; -var PluginManager = require('cordova-common').PluginManager; -var Q = require('q'); -var util = require('util'); +/** + * @todo update coho to update this line. + * @todo use `package.json` instead but first + * figure out how this fit in with the platform-centered workflow structure. + * This workflow would not have the `package.json` file. + */ +// Coho updates this line +const VERSION = '6.1.1'; + +const fs = require('fs-extra'); +const path = require('path'); +const unorm = require('unorm'); +const projectFile = require('./lib/projectFile'); +const check_reqs = require('./lib/check_reqs'); +const CordovaError = require('cordova-common').CordovaError; +const CordovaLogger = require('cordova-common').CordovaLogger; +const events = require('cordova-common').events; +const PluginManager = require('cordova-common').PluginManager; +const util = require('util'); +const xcode = require('xcode'); +const ConfigParser = require('cordova-common').ConfigParser; function setupEvents (externalEventEmitter) { if (externalEventEmitter) { @@ -42,6 +52,10 @@ function setupEvents (externalEventEmitter) { } } +function getVariableSpec (spec, options) { + return spec.includes('$') ? options.cli_variables[spec.replace('$', '')] : spec; +} + /** * Creates a new PlatformApi instance. * @@ -60,19 +74,28 @@ function Api (platform, platformRootDir, events) { setupEvents(events); - var xcodeProjDir; - var xcodeCordovaProj; + let xcodeProjDir; + let xcodeCordovaProj; try { - xcodeProjDir = fs.readdirSync(this.root).filter(function (e) { return e.match(/\.xcodeproj$/i); })[0]; + const xcodeProjDir_array = fs.readdirSync(this.root).filter(e => e.match(/\.xcodeproj$/i)); + if (xcodeProjDir_array.length > 1) { + for (let x = 0; x < xcodeProjDir_array.length; x++) { + if (xcodeProjDir_array[x].substring(0, 2) === '._') { + xcodeProjDir_array.splice(x, 1); + } + } + } + xcodeProjDir = xcodeProjDir_array[0]; + if (!xcodeProjDir) { - throw new CordovaError('The provided path "' + this.root + '" is not a Cordova iOS project.'); + throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`); } - var cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj')); + const cordovaProjName = xcodeProjDir.substring(xcodeProjDir.lastIndexOf(path.sep) + 1, xcodeProjDir.indexOf('.xcodeproj')); xcodeCordovaProj = path.join(this.root, cordovaProjName); } catch (e) { - throw new CordovaError('The provided path "' + this.root + '" is not a Cordova iOS project.'); + throw new CordovaError(`The provided path "${this.root}" is not a Cordova iOS project.`); } this.locations = { @@ -83,11 +106,7 @@ function Api (platform, platformRootDir, events) { defaultConfigXml: path.join(this.root, 'cordova/defaults.xml'), pbxproj: path.join(this.root, xcodeProjDir, 'project.pbxproj'), xcodeProjDir: path.join(this.root, xcodeProjDir), - xcodeCordovaProj: xcodeCordovaProj, - // NOTE: this is required by browserify logic. - // As per platformApi spec we return relative to template root paths here - cordovaJs: 'bin/CordovaLib/cordova.js', - cordovaJsSrc: 'bin/cordova-js-src' + xcodeCordovaProj }; } @@ -95,7 +114,7 @@ function Api (platform, platformRootDir, events) { * Creates platform in a specified directory. * * @param {String} destination Destination directory, where install platform to - * @param {ConfigParser} [config] ConfgiParser instance, used to retrieve + * @param {ConfigParser} [config] ConfigParser instance, used to retrieve * project creation options, such as package id and project name. * @param {Object} [options] An options object. The most common options are: * @param {String} [options.customTemplate] A path to custom template, that @@ -109,26 +128,26 @@ function Api (platform, platformRootDir, events) { * @return {Promise<PlatformApi>} Promise either fulfilled with PlatformApi * instance or rejected with CordovaError. */ -Api.createPlatform = function (destination, config, options, events) { +Api.createPlatform = (destination, config, options, events) => { setupEvents(events); // CB-6992 it is necessary to normalize characters // because node and shell scripts handles unicode symbols differently // We need to normalize the name to NFD form since iOS uses NFD unicode form - var name = unorm.nfd(config.name()); - var result; + const name = unorm.nfd(config.name()); + let result; try { result = require('../../../lib/create') - .createProject(destination, config.packageName(), name, options) - .then(function () { + .createProject(destination, config.getAttribute('ios-CFBundleIdentifier') || config.packageName(), name, options, config) + .then(() => { // after platform is created we return Api instance based on new Api.js location // This is required to correctly resolve paths in the future api calls - var PlatformApi = require(path.resolve(destination, 'cordova/Api')); + const PlatformApi = require(path.resolve(destination, 'cordova/Api')); return new PlatformApi('ios', destination, events); }); } catch (e) { events.emit('error', 'createPlatform is not callable from the iOS project API.'); - throw (e); + throw e; } return result; }; @@ -149,20 +168,20 @@ Api.createPlatform = function (destination, config, options, events) { * @return {Promise<PlatformApi>} Promise either fulfilled with PlatformApi * instance or rejected with CordovaError. */ -Api.updatePlatform = function (destination, options, events) { +Api.updatePlatform = (destination, options, events) => { setupEvents(events); - var result; + let result; try { result = require('../../../lib/create') .updateProject(destination, options) - .then(function () { - var PlatformApi = require(path.resolve(destination, 'cordova/Api')); + .then(() => { + const PlatformApi = require(path.resolve(destination, 'cordova/Api')); return new PlatformApi('ios', destination, events); }); } catch (e) { events.emit('error', 'updatePlatform is not callable from the iOS project API, you will need to do this manually.'); - throw (e); + throw e; } return result; }; @@ -174,12 +193,12 @@ Api.updatePlatform = function (destination, options, events) { * platform's file structure and other properties of platform. */ Api.prototype.getPlatformInfo = function () { - var result = {}; + const result = {}; result.locations = this.locations; result.root = this.root; result.name = this.platform; - result.version = require('./version'); - result.projectConfig = this._config; + result.version = Api.version(); + result.projectConfig = new ConfigParser(this.locations.configXml); return result; }; @@ -199,6 +218,8 @@ Api.prototype.getPlatformInfo = function () { * CordovaError instance. */ Api.prototype.prepare = function (cordovaProject) { + cordovaProject.projectConfig = new ConfigParser(cordovaProject.locations.rootConfigXml || cordovaProject.projectConfig.path); + return require('./lib/prepare').prepare.call(this, cordovaProject); }; @@ -220,8 +241,7 @@ Api.prototype.prepare = function (cordovaProject) { * CordovaError instance. */ Api.prototype.addPlugin = function (plugin, installOptions) { - var xcodeproj = projectFile.parse(this.locations); - var self = this; + const xcodeproj = projectFile.parse(this.locations); installOptions = installOptions || {}; installOptions.variables = installOptions.variables || {}; @@ -230,70 +250,36 @@ Api.prototype.addPlugin = function (plugin, installOptions) { installOptions.variables.PACKAGE_NAME = xcodeproj.getPackageName(); } - return PluginManager.get(self.platform, self.locations, xcodeproj) + return PluginManager.get(this.platform, this.locations, xcodeproj) .addPlugin(plugin, installOptions) - .then(function () { - var frameworkTags = plugin.getFrameworks(self.platform); - var frameworkPods = frameworkTags.filter(function (obj) { - return (obj.type === 'podspec'); - }); - - return Q.resolve(frameworkPods); - }) - .then(function (frameworkPods) { - if (!(frameworkPods.length)) { - return Q.resolve(); - } - - var project_dir = self.locations.root; - var project_name = self.locations.xcodeCordovaProj.split('/').pop(); - - var Podfile = require('./lib/Podfile').Podfile; - var PodsJson = require('./lib/PodsJson').PodsJson; - - events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type="podspec"'); - - var podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); - var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name); - - frameworkPods.forEach(function (obj) { - var podJson = { - name: obj.src, - type: obj.type, - spec: obj.spec - }; - - var val = podsjsonFile.get(podJson.name); - if (val) { // found - if (podJson.spec !== val.spec) { // exists, different spec, print warning - events.emit('warn', plugin.id + ' depends on ' + podJson.name + '@' + podJson.spec + ', which conflicts with another plugin. ' + podJson.name + '@' + val.spec + ' is already installed and was not overwritten.'); - } - // increment count, but don't add in Podfile because it already exists - podsjsonFile.increment(podJson.name); - } else { // not found, write new - podJson.count = 1; - podsjsonFile.setJson(podJson.name, podJson); - // add to Podfile - podfileFile.addSpec(podJson.name, podJson.spec); + .then(() => { + if (plugin != null) { + const headerTags = plugin.getHeaderFiles(this.platform); + const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader'); + if (bridgingHeaders.length > 0) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split('/').pop(); + const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader; + const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h')); + events.emit('verbose', 'Adding Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"'); + bridgingHeaders.forEach(obj => { + const bridgingHeaderPath = path.basename(obj.src); + bridgingHeaderFile.addHeader(plugin.id, bridgingHeaderPath); + }); + bridgingHeaderFile.write(); } - }); - - // now that all the pods have been processed, write to pods.json - podsjsonFile.write(); - - // only write and pod install if the Podfile changed - if (podfileFile.isDirty()) { - podfileFile.write(); - events.emit('verbose', 'Running `pod install` (to install plugins)'); - - return podfileFile.install(check_reqs.check_cocoapods); - } else { - events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); } }) - // CB-11022 return non-falsy value to indicate - // that there is no need to run prepare after - .thenResolve(true); + .then(() => { + if (plugin != null) { + const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : []; + const frameworkTags = plugin.getFrameworks(this.platform); + const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); + return this.addPodSpecs(plugin, podSpecs, frameworkPods, installOptions); + } + }) + // CB-11022 Return truthy value to prevent running prepare after + .then(() => true); }; /** @@ -310,69 +296,321 @@ Api.prototype.addPlugin = function (plugin, installOptions) { * CordovaError instance. */ Api.prototype.removePlugin = function (plugin, uninstallOptions) { - var xcodeproj = projectFile.parse(this.locations); - var self = this; + const xcodeproj = projectFile.parse(this.locations); - return PluginManager.get(self.platform, self.locations, xcodeproj) + return PluginManager.get(this.platform, this.locations, xcodeproj) .removePlugin(plugin, uninstallOptions) - .then(function () { - var frameworkTags = plugin.getFrameworks(self.platform); - var frameworkPods = frameworkTags.filter(function (obj) { - return (obj.type === 'podspec'); + .then(() => { + if (plugin != null) { + const headerTags = plugin.getHeaderFiles(this.platform); + const bridgingHeaders = headerTags.filter(obj => obj.type === 'BridgingHeader'); + if (bridgingHeaders.length > 0) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split('/').pop(); + const BridgingHeader = require('./lib/BridgingHeader').BridgingHeader; + const bridgingHeaderFile = new BridgingHeader(path.join(project_dir, project_name, 'Bridging-Header.h')); + events.emit('verbose', 'Removing Bridging-Headers since the plugin contained <header-file> with type="BridgingHeader"'); + bridgingHeaders.forEach(obj => { + const bridgingHeaderPath = path.basename(obj.src); + bridgingHeaderFile.removeHeader(plugin.id, bridgingHeaderPath); + }); + bridgingHeaderFile.write(); + } + } + }) + .then(() => { + if (plugin != null) { + const podSpecs = plugin.getPodSpecs ? plugin.getPodSpecs(this.platform) : []; + const frameworkTags = plugin.getFrameworks(this.platform); + const frameworkPods = frameworkTags.filter(obj => obj.type === 'podspec'); + return this.removePodSpecs(plugin, podSpecs, frameworkPods, uninstallOptions); + } + }) + // CB-11022 Return truthy value to prevent running prepare after + .then(() => true); +}; + +/** + * adding CocoaPods libraries + * + * @param {PluginInfo} plugin A PluginInfo instance that represents plugin + * that will be installed. + * @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform) + * @param {Object} frameworkPods: framework tags object with type === 'podspec' + * @return {Promise} Return a promise + */ + +Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods, installOptions) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split('/').pop(); + const minDeploymentTarget = this.getPlatformInfo().projectConfig.getPreference('deployment-target', 'ios'); + + const Podfile = require('./lib/Podfile').Podfile; + const PodsJson = require('./lib/PodsJson').PodsJson; + const podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); + const podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name, minDeploymentTarget); + + if (podSpecs.length) { + events.emit('verbose', 'Adding pods since the plugin contained <podspecs>'); + podSpecs.forEach(obj => { + // declarations + Object.keys(obj.declarations).forEach(key => { + if (obj.declarations[key] === 'true') { + const declaration = Podfile.proofDeclaration(key); + const podJson = { + declaration + }; + const val = podsjsonFile.getDeclaration(declaration); + if (val) { + podsjsonFile.incrementDeclaration(declaration); + } else { + podJson.count = 1; + podsjsonFile.setJsonDeclaration(declaration, podJson); + podfileFile.addDeclaration(podJson.declaration); + } + } }); + // sources + Object.keys(obj.sources).forEach(key => { + const podJson = { + source: obj.sources[key].source + }; + const val = podsjsonFile.getSource(key); + if (val) { + podsjsonFile.incrementSource(key); + } else { + podJson.count = 1; + podsjsonFile.setJsonSource(key, podJson); + podfileFile.addSource(podJson.source); + } + }); + // libraries + Object.keys(obj.libraries).forEach(key => { + const podJson = Object.assign({}, obj.libraries[key]); + if (podJson.spec) { + podJson.spec = getVariableSpec(podJson.spec, installOptions); + } + const val = podsjsonFile.getLibrary(key); + if (val) { + events.emit('warn', `${plugin.id} depends on ${podJson.name}, which may conflict with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); + podsjsonFile.incrementLibrary(key); + } else { + podJson.count = 1; + podsjsonFile.setJsonLibrary(key, podJson); + podfileFile.addSpec(podJson.name, podJson); + } + }); + }); + } - return Q.resolve(frameworkPods); - }) - .then(function (frameworkPods) { - if (!(frameworkPods.length)) { - return Q.resolve(); + if (frameworkPods.length) { + events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.'); + events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type="podspec"'); + frameworkPods.forEach(obj => { + const spec = getVariableSpec(obj.spec, installOptions); + const podJson = { + name: obj.src, + type: obj.type, + spec + }; + + const val = podsjsonFile.getLibrary(podJson.name); + if (val) { // found + if (podJson.spec !== val.spec) { // exists, different spec, print warning + events.emit('warn', `${plugin.id} depends on ${podJson.name}@${podJson.spec}, which conflicts with another plugin. ${podJson.name}@${val.spec} is already installed and was not overwritten.`); + } + // increment count, but don't add in Podfile because it already exists + podsjsonFile.incrementLibrary(podJson.name); + } else { // not found, write new + podJson.count = 1; + podsjsonFile.setJsonLibrary(podJson.name, podJson); + // add to Podfile + podfileFile.addSpec(podJson.name, podJson.spec); } + }); + } + + if (podSpecs.length > 0 || frameworkPods.length > 0) { + // now that all the pods have been processed, write to pods.json + podsjsonFile.write(); - var project_dir = self.locations.root; - var project_name = self.locations.xcodeCordovaProj.split('/').pop(); + // only write and pod install if the Podfile changed + if (podfileFile.isDirty()) { + podfileFile.write(); + events.emit('verbose', 'Running `pod install` (to install plugins)'); + projectFile.purgeProjectFileCache(this.locations.root); - var Podfile = require('./lib/Podfile').Podfile; - var PodsJson = require('./lib/PodsJson').PodsJson; + return podfileFile.install(check_reqs.check_cocoapods) + .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); + } else { + events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + } + } + return Promise.resolve(); +}; + +/** + * removing CocoaPods libraries + * + * @param {PluginInfo} plugin A PluginInfo instance that represents plugin + * that will be installed. + * @param {Object} podSpecs: the return value of plugin.getPodSpecs(this.platform) + * @param {Object} frameworkPods: framework tags object with type === 'podspec' + * @return {Promise} Return a promise + */ - events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */ +Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods, uninstallOptions) { + const project_dir = this.locations.root; + const project_name = this.locations.xcodeCordovaProj.split('/').pop(); - var podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); - var podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name); + const Podfile = require('./lib/Podfile').Podfile; + const PodsJson = require('./lib/PodsJson').PodsJson; + const podsjsonFile = new PodsJson(path.join(project_dir, PodsJson.FILENAME)); + const podfileFile = new Podfile(path.join(project_dir, Podfile.FILENAME), project_name); - frameworkPods.forEach(function (obj) { - var podJson = { - name: obj.src, - type: obj.type, - spec: obj.spec + if (podSpecs.length) { + events.emit('verbose', 'Adding pods since the plugin contained <podspecs>'); + podSpecs.forEach(obj => { + // declarations + Object.keys(obj.declarations).forEach(key => { + if (obj.declarations[key] === 'true') { + const declaration = Podfile.proofDeclaration(key); + const podJson = { + declaration + }; + const val = podsjsonFile.getDeclaration(declaration); + if (val) { + podsjsonFile.decrementDeclaration(declaration); + } else { + const message = util.format('plugin \"%s\" declaration \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.declaration); /* eslint no-useless-escape : 0 */ + events.emit('verbose', message); + } + if (!val || val.count === 0) { + podfileFile.removeDeclaration(podJson.declaration); + } + } + }); + // sources + Object.keys(obj.sources).forEach(key => { + const podJson = { + source: obj.sources[key].source }; - - var val = podsjsonFile.get(podJson.name); - if (val) { // found, decrement count - podsjsonFile.decrement(podJson.name); - } else { // not found (perhaps a sync error) - var message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */ + const val = podsjsonFile.getSource(key); + if (val) { + podsjsonFile.decrementSource(key); + } else { + const message = util.format('plugin \"%s\" source \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.source); /* eslint no-useless-escape : 0 */ events.emit('verbose', message); } - - // always remove from the Podfile - podfileFile.removeSpec(podJson.name); + if (!val || val.count === 0) { + podfileFile.removeSource(podJson.source); + } + }); + // libraries + Object.keys(obj.libraries).forEach(key => { + const podJson = Object.assign({}, obj.libraries[key]); + if (podJson.spec) { + podJson.spec = getVariableSpec(podJson.spec, uninstallOptions); + } + const val = podsjsonFile.getLibrary(key); + if (val) { + podsjsonFile.decrementLibrary(key); + } else { + const message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */ + events.emit('verbose', message); + } + if (!val || val.count === 0) { + podfileFile.removeSpec(podJson.name); + } }); + }); + } + + if (frameworkPods.length) { + events.emit('warn', '"framework" tag with type "podspec" is deprecated and will be removed. Please use the "podspec" tag.'); + events.emit('verbose', 'Adding pods since the plugin contained <framework>(s) with type=\"podspec\"'); /* eslint no-useless-escape : 0 */ + frameworkPods.forEach(obj => { + const spec = getVariableSpec(obj.spec, uninstallOptions); + const podJson = { + name: obj.src, + type: obj.type, + spec + }; + + const val = podsjsonFile.getLibrary(podJson.name); + if (val) { // found, decrement count + podsjsonFile.decrementLibrary(podJson.name); + } else { // not found (perhaps a sync error) + const message = util.format('plugin \"%s\" podspec \"%s\" does not seem to be in pods.json, nothing to remove. Will attempt to remove from Podfile.', plugin.id, podJson.name); /* eslint no-useless-escape : 0 */ + events.emit('verbose', message); + } + + // always remove from the Podfile + podfileFile.removeSpec(podJson.name); + }); + } - // now that all the pods have been processed, write to pods.json - podsjsonFile.write(); + if (podSpecs.length > 0 || frameworkPods.length > 0) { + // now that all the pods have been processed, write to pods.json + podsjsonFile.write(); - if (podfileFile.isDirty()) { - podfileFile.write(); - events.emit('verbose', 'Running `pod install` (to uninstall pods)'); + if (podfileFile.isDirty()) { + podfileFile.write(); + events.emit('verbose', 'Running `pod install` (to uninstall pods)'); - return podfileFile.install(check_reqs.check_cocoapods); - } else { - events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + return podfileFile.install(check_reqs.check_cocoapods) + .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); + } else { + events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); + } + } + return Promise.resolve(); +}; + +/** + * set Swift Version for all CocoaPods libraries + * + * @param {PodsJson} podsjsonFile A PodsJson instance that represents pods.json + */ + +Api.prototype.setSwiftVersionForCocoaPodsLibraries = function (podsjsonFile) { + let __dirty = false; + return check_reqs.check_cocoapods().then(toolOptions => { + if (toolOptions.ignore) { + events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries'); + } else { + const podPbxPath = path.join(this.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj'); + const podXcodeproj = xcode.project(podPbxPath); + podXcodeproj.parseSync(); + const podTargets = podXcodeproj.pbxNativeTargetSection(); + const podConfigurationList = podXcodeproj.pbxXCConfigurationList(); + const podConfigs = podXcodeproj.pbxXCBuildConfigurationSection(); + + const libraries = podsjsonFile.getLibraries(); + Object.keys(libraries).forEach(key => { + const podJson = libraries[key]; + const name = podJson.name; + const swiftVersion = podJson['swift-version']; + if (swiftVersion) { + __dirty = true; + Object.keys(podTargets) + .filter(targetKey => podTargets[targetKey].productName === name) + .map(targetKey => podTargets[targetKey].buildConfigurationList) + .map(buildConfigurationListId => podConfigurationList[buildConfigurationListId]) + .map(buildConfigurationList => buildConfigurationList.buildConfigurations) + .reduce((acc, buildConfigurations) => acc.concat(buildConfigurations), []) + .map(buildConfiguration => buildConfiguration.value) + .forEach(buildId => { + __dirty = true; + podConfigs[buildId].buildSettings.SWIFT_VERSION = swiftVersion; + }); + } + }); + if (__dirty) { + fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8'); } - }) - // CB-11022 return non-falsy value to indicate - // that there is no need to run prepare after - .thenResolve(true); + } + }); }; /** @@ -408,11 +646,8 @@ Api.prototype.removePlugin = function (plugin, uninstallOptions) { * CordovaError instance. */ Api.prototype.build = function (buildOptions) { - var self = this; return check_reqs.run() - .then(function () { - return require('./lib/build').run.call(self, buildOptions); - }); + .then(() => require('./lib/build').run.call(this, buildOptions)); }; /** @@ -428,11 +663,8 @@ Api.prototype.build = function (buildOptions) { * successfully, or rejected with CordovaError. */ Api.prototype.run = function (runOptions) { - var self = this; return check_reqs.run() - .then(function () { - return require('./lib/run').run.call(self, runOptions); - }); + .then(() => require('./lib/run').run.call(this, runOptions)); }; /** @@ -442,14 +674,9 @@ Api.prototype.run = function (runOptions) { * CordovaError. */ Api.prototype.clean = function (cleanOptions) { - var self = this; return check_reqs.run() - .then(function () { - return require('./lib/clean').run.call(self, cleanOptions); - }) - .then(function () { - return require('./lib/prepare').clean.call(self, cleanOptions); - }); + .then(() => require('./lib/clean').run.call(this, cleanOptions)) + .then(() => require('./lib/prepare').clean.call(this, cleanOptions)); }; /** @@ -464,4 +691,8 @@ Api.prototype.requirements = function () { return check_reqs.check_all(); }; +Api.version = function () { + return VERSION; +}; + module.exports = Api; |
