From dca1f7e58d04b1cff12707750920c0451192282a Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Wed, 5 Oct 2016 19:57:35 -0400 Subject: [PATCH] feat(ios): remove need for the swift-support hook, remove script The plugin now requires cordova-plugin-swift-support as a dependency. This package handles the job more effectively, and doesn't require cordova-plugin-qrscanner consumers to make any special configuration changes to install the plugin on iOS. --- plugin.xml | 4 +- scripts/swift-support.js | 143 ---------------------------- src/ios/QRScanner-Bridging-Header.h | 5 - tests/project/config.xml | 4 - tests/project/package.json | 2 +- 5 files changed, 3 insertions(+), 155 deletions(-) delete mode 100644 scripts/swift-support.js delete mode 100644 src/ios/QRScanner-Bridging-Header.h diff --git a/plugin.xml b/plugin.xml index 0d26cc12..507fee52 100755 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="2.3.4"> QRScanner @@ -35,7 +35,7 @@ - + The camera is used to scan QR codes. diff --git a/scripts/swift-support.js b/scripts/swift-support.js deleted file mode 100644 index 6577dbd1..00000000 --- a/scripts/swift-support.js +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env node - -'use strict'; - -// This hook is derived from iosrtc-swift-support.js in cordova-plugin-iosrtc -// -// Usage in cordova project config.xml: -// -// -// - -var - fs = require('fs'), - path = require('path'), - xcode = require('xcode'), - - BUILD_VERSION = '7.0', - SWIFT_VERSION_XCODE = '2.3', - BUILD_VERSION_XCODE = '"' + BUILD_VERSION + '"', - RUNPATH_SEARCH_PATHS = '@executable_path/Frameworks', - RUNPATH_SEARCH_PATHS_XCODE = '"' + RUNPATH_SEARCH_PATHS + '"', - ENABLE_BITCODE = 'NO', - ENABLE_BITCODE_XCODE = '"' + ENABLE_BITCODE + '"', - BRIDGING_HEADER_END = '/Plugins/cordova-plugin-qrscanner/QRScanner-Bridging-Header.h', - COMMENT_KEY = /_comment$/; - - -// Helpers - -// Returns the project name -function getProjectName(protoPath) { - var - cordovaConfigPath = path.join(protoPath, 'config.xml'), - content = fs.readFileSync(cordovaConfigPath, 'utf-8'); - - return /([\s\S]*)<\/name>/mi.exec(content)[1].trim(); -} - -// Drops the comments -function nonComments(obj) { - var - keys = Object.keys(obj), - newObj = {}, - i = 0; - - for (i; i < keys.length; i += 1) { - if (!COMMENT_KEY.test(keys[i])) { - newObj[keys[i]] = obj[keys[i]]; - } - } - - return newObj; -} - -function debug (msg) { - console.log('swift-support.js [INFO] ' + msg); -} - -function debugerror(msg) { - console.error('swift-support.js [ERROR] ' + msg); -} - -// Starting here - -module.exports = function (context) { - var - projectRoot = context.opts.projectRoot, - projectName = getProjectName(projectRoot), - xcconfigPath = path.join(projectRoot, '/platforms/ios/cordova/build.xcconfig'), - xcodeProjectName = projectName + '.xcodeproj', - xcodeProjectPath = path.join(projectRoot, 'platforms', 'ios', xcodeProjectName, 'project.pbxproj'), - swiftBridgingHead = projectName + BRIDGING_HEADER_END, - swiftBridgingHeadXcode = '"' + swiftBridgingHead + '"', - swiftOptions = [''], // <-- begin to file appending AFTER initial newline - xcodeProject; - - debug('Enabling Swift for cordova-plugin-qrscanner.'); - - // Checking if the project files are in the right place - if (!fs.existsSync(xcodeProjectPath)) { - debugerror('an error occurred searching the project file at: "' + xcodeProjectPath + '"'); - - return; - } - debug('".pbxproj" project file found: ' + xcodeProjectPath); - - if (!fs.existsSync(xcconfigPath)) { - debugerror('an error occurred searching the project file at: "' + xcconfigPath + '"'); - - return; - } - debug('".xcconfig" project file found: ' + xcconfigPath); - - xcodeProject = xcode.project(xcodeProjectPath); - - // Showing info about the tasks to do - debug('fixing issues in the generated project files:'); - debug('- "iOS Deployment Target" and "Deployment Target" to: ' + BUILD_VERSION_XCODE); - debug('- "Runpath Search Paths" to: ' + RUNPATH_SEARCH_PATHS_XCODE); - debug('- "Objective-C Bridging Header" to: ' + swiftBridgingHeadXcode); - debug('- "ENABLE_BITCODE" set to: ' + ENABLE_BITCODE_XCODE); - - - // Massaging the files - - // "build.xcconfig" - swiftOptions.push('LD_RUNPATH_SEARCH_PATHS = ' + RUNPATH_SEARCH_PATHS); - swiftOptions.push('SWIFT_OBJC_BRIDGING_HEADER = ' + swiftBridgingHead); - swiftOptions.push('IPHONEOS_DEPLOYMENT_TARGET = ' + BUILD_VERSION); - swiftOptions.push('ENABLE_BITCODE = ' + ENABLE_BITCODE); - // NOTE: Not needed - // swiftOptions.push('EMBEDDED_CONTENT_CONTAINS_SWIFT = YES'); - fs.appendFileSync(xcconfigPath, swiftOptions.join('\n')); - debug('file correctly fixed: ' + xcconfigPath); - - // "project.pbxproj" - // Parsing it - xcodeProject.parse(function (error) { - var configurations, buildSettings; - - if (error) { - debugerror('an error occurred during the parsing of the project file'); - - return; - } - - - configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection()); - // Adding or changing the parameters we need - Object.keys(configurations).forEach(function (config) { - buildSettings = configurations[config].buildSettings; - buildSettings.LD_RUNPATH_SEARCH_PATHS = RUNPATH_SEARCH_PATHS_XCODE; - buildSettings.SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeadXcode; - buildSettings.IPHONEOS_DEPLOYMENT_TARGET = BUILD_VERSION_XCODE; - buildSettings.ENABLE_BITCODE = ENABLE_BITCODE_XCODE; - buildSettings.SWIFT_VERSION = SWIFT_VERSION_XCODE; - }); - - // Writing the file again - fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8'); - debug('file correctly fixed: ' + xcodeProjectPath); - }); -}; diff --git a/src/ios/QRScanner-Bridging-Header.h b/src/ios/QRScanner-Bridging-Header.h deleted file mode 100644 index af802d69..00000000 --- a/src/ios/QRScanner-Bridging-Header.h +++ /dev/null @@ -1,5 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - -#import diff --git a/tests/project/config.xml b/tests/project/config.xml index b92e527e..ef979c38 100644 --- a/tests/project/config.xml +++ b/tests/project/config.xml @@ -21,13 +21,9 @@ - - - The test app uses the camera to scan QR codes. - diff --git a/tests/project/package.json b/tests/project/package.json index b3c65c30..fc215ec5 100644 --- a/tests/project/package.json +++ b/tests/project/package.json @@ -4,7 +4,7 @@ "scripts": { "clean": "rm -rf node_modules && rm -rf platforms && rm -rf plugins", "postinstall": "node scripts/timestamp.js && cordova prepare", - "test:ios": "cordova build ios && open platforms/ios/CvQRScnTst.xcodeproj", + "test:ios": "cordova prepare ios && cordova build ios && open platforms/ios/CvQRScnTst.xcodeproj", "test:browser": "cordova run browser", "test:android": "cordova build android && open -a /Applications/Android\\ Studio.app platforms/android" },