Skip to content

Commit

Permalink
Merge pull request #33 from bpidluzhnyy/capacitor-base
Browse files Browse the repository at this point in the history
Updates for Cordova SDK 11.0 release
  • Loading branch information
volodymyrtaliar committed Oct 21, 2022
2 parents 63657d6 + f382d9e commit 0d3550a
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Dynamics SDK for iOS and Android are installed as part of the `capacitor-plugin-
The integration uses the iOS "Dynamic Framework" version of BlackBerry Dynamics as the static library is no longer supported.
There are a few options to integrate BlackBerry Dynamics SDK for iOS.
#### Using latest released version - default
By default, `capacitor-plugin-bbd-base` plugin will integrate **latest** available BlackBerry Dynamics SDK for iOS using following podspec: `https://software.download.blackberry.com/repository/framework/dynamics/ios/10.2.0.83/BlackBerryDynamics-10.2.0.83.podspec`.
By default, `capacitor-plugin-bbd-base` plugin will integrate **latest** available BlackBerry Dynamics SDK for iOS using following podspec: `https://software.download.blackberry.com/repository/framework/dynamics/ios/11.0.1.137/BlackBerryDynamics-11.0.1.137.podspec`.
> NOTE: If one of the below integration methods was used there is an option to reset **default** configuration by running following command:
`$ npx set-dynamics-podspec --default`
`$ ionic cap build ios`
Expand All @@ -43,7 +43,7 @@ By default, `capacitor-plugin-bbd-base` plugin will integrate **latest** availab
There is possibility to integrate other released build of BlackBerry Dynamics SDK for iOS.
Following command should be run:
```
$ npx set-dynamics-podspec --url "https://software.download.blackberry.com/repository/framework/dynamics/ios/10.1.0.36/BlackBerryDynamics-10.1.0.36.podspec"
$ npx set-dynamics-podspec --url "https://software.download.blackberry.com/repository/framework/dynamics/ios/10.2.0.83/BlackBerryDynamics-10.2.0.83.podspec"
$ ionic cap build ios
```
#### Using locally downloaded version
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "capacitor-plugin-bbd-base",
"version": "1.0.0",
"dynamicsPodSpec":"https://software.download.blackberry.com/repository/framework/dynamics/ios/10.2.0.83/BlackBerryDynamics-10.2.0.83.podspec",
"version": "1.1.0",
"dynamicsPodSpec":"https://software.download.blackberry.com/repository/framework/dynamics/ios/11.0.1.137/BlackBerryDynamics-11.0.1.137.podspec",
"description": "BlackBerry Dynamics Capacitor Base plugin.",
"license": "SEE LICENSE IN LICENSE",
"homepage": "https://community.blackberry.com",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="capacitor-plugin-bbd-base" version="1.0.0">
id="capacitor-plugin-bbd-base" version="1.1.0">
<name>BlackBerry Dynamics Capacitor Base plugin</name>
<description>
This is Base plugin. It adds all the needed configuration to enable using
Expand Down
6 changes: 3 additions & 3 deletions scripts/gradle/bbd.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ allprojects {
}

dependencies {
implementation 'com.blackberry.blackberrydynamics:android_handheld_platform:10.2.0.79'
implementation 'com.blackberry.blackberrydynamics:android_handheld_backup_support:10.2.0.79'
implementation 'com.blackberry.blackberrydynamics:android_webview:10.2.0.79'
implementation 'com.blackberry.blackberrydynamics:android_handheld_platform:11.0.1.140'
implementation 'com.blackberry.blackberrydynamics:android_handheld_backup_support:11.0.1.140'
implementation 'com.blackberry.blackberrydynamics:android_webview:11.0.1.140'

implementation 'androidx.legacy:legacy-support-v4:1.0.0'

Expand Down
12 changes: 9 additions & 3 deletions scripts/hooks/bbdCapacitorCleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
* limitations under the License.
*/

(function () {
const { checkAndExitOrContinueOnUninstall, replaceAndSave, readBundleIdFromCapacitorConfig } = require('./helper');
(function () {
const {
checkAndExitOrContinueOnUninstall,
replaceAndSave,
removeAssertDeploymentTarget,
readBundleIdFromCapacitorConfig
} = require('./helper');

// We should run this script only if we uninstall capacitor-plugin-bbd-base plugin.
// In other circumstances like 'npm i' or 'yarn' or 'npm uninstall' or 'npm i <other_module>' we should exit.
Expand Down Expand Up @@ -151,7 +156,7 @@
]
]);
replaceAndSave(capacitorPodFilePath, [
[`platform :ios, '14.0'`, `platform :ios, '12.0'`],
[`platform :ios, '14.0'`, `platform :ios, '13.0'`],
[/pod 'BlackBerryDynamics', (:podspec|:path) => '(.+)'/, '']
]);
replaceAndSave(capacitorPodSpecFile, [
Expand All @@ -163,6 +168,7 @@
replaceAndSave(capacitorCLIPodsSpecPath, [
[`s.dependency 'BlackBerryDynamics'`, '']
]);
removeAssertDeploymentTarget(capacitorPodFilePath);
} catch (error) {
console.log(error);
}
Expand Down
16 changes: 11 additions & 5 deletions scripts/hooks/bbdCapacitorInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
* limitations under the License.
*/

(function () {
const { checkAndExitOrContinueOnInstall, patchCAPBridgeViewController, replaceAndSave } = require('./helper');
(function () {
const {
checkAndExitOrContinueOnInstall,
patchCAPBridgeViewController,
replaceAndSave,
addAssertDeploymentTarget
} = require('./helper');

// We should run this script only if we install capacitor-plugin-bbd-base plugin.
// In other circumstances like 'npm i' or 'yarn' or 'npm uninstall' or 'npm i <other_module>' we should exit.
Expand Down Expand Up @@ -64,8 +69,7 @@
capacitorPodFile = path.join(projectRoot, 'ios', 'App', 'Podfile'),
BlackBerryDependencyPhrase = `s.dependency 'BlackBerryDynamics'`,
SwiftVersionPhrase = `s.swift_version = '5.1'`,
addYourPodsHerePhrase = '# Add your Pods here',
platformVersion = version => `platform :ios, '${version}'`;
addYourPodsHerePhrase = '# Add your Pods here';

if (!fse.existsSync(cordovaPluginsPodsSpecPath)) {
console.log('File not found at path: ', cordovaPluginsPodsSpecPath);
Expand Down Expand Up @@ -94,13 +98,15 @@
const podsSpecPhrase = `pod 'BlackBerryDynamics', :podspec => '${dynamicsPodSpec}'`;

replaceAndSave(capacitorPodFile, [
[platformVersion('12.0'), platformVersion('14.0')],
[/platform :ios, \'([\d\.\d]+)\'/, "platform :ios, '14.0'"],
[
addYourPodsHerePhrase,
`${addYourPodsHerePhrase}\n\t${podsSpecPhrase}`
]
]);

addAssertDeploymentTarget(capacitorPodFile);

// add dependency to Capacitor pod file
const capacitorPodSpecFile = path.join(projectRoot, 'node_modules', '@capacitor', 'ios', 'Capacitor.podspec');
replaceAndSave(capacitorPodSpecFile, [
Expand Down
62 changes: 56 additions & 6 deletions scripts/hooks/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const linkerFlags = {
};

const podsPhrases = {
BlackBerryDynamics: "pod 'BlackBerryDynamics', :podspec => " +
"'https://software.download.blackberry.com/repository/framework/dynamics/ios/10.2.0.83/BlackBerryDynamics-10.2.0.83.podspec'",
BlackBerryLauncher: "pod 'BlackBerryLauncher', :path => '../../node_modules/cordova-plugin-bbd-launcher'",
};

Expand Down Expand Up @@ -155,14 +153,17 @@ exports.updateLauncher = () => {
const podFilePath = path.join(projectRoot, 'ios', 'App', 'Podfile');

if ('cordova-plugin-bbd-launcher' in packageJson.dependencies) {
let fileContext = fs.readFileSync(podFilePath);
if (fileContext.includes(podsPhrases.BlackBerryLauncher))
let fileContext = fs.readFileSync(podFilePath).toString();
if (fileContext.includes(podsPhrases.BlackBerryLauncher)) {
return;
}

podsPhrases.BlackBerryDynamics = getBlackBerryDynamicsPodPhrase(fileContext);

replaceAndSave(podFilePath, [
[
podsPhrases.BlackBerryDynamics,
`${podsPhrases.BlackBerryDynamics}\n\t${podsPhrases.BlackBerryLauncher}`
addAfter(podsPhrases.BlackBerryDynamics, podsPhrases.BlackBerryLauncher)
]
]);
} else {
Expand All @@ -188,13 +189,53 @@ exports.cleanUpCAPBridgeViewController = () => {
]);
}

const targetVersion = '14.0';
const requireHelperPhrase = "require_relative '../../node_modules/" +
"capacitor-plugin-bbd-base/scripts/hooks/ios/update_deployment_target.rb'" +
"\n";
const postInstallPhrase = [
`post_install do |installer|`,
` project = Xcodeproj::Project.open('App.xcodeproj')`,
` update_deployment_target project, ${targetVersion}`,
` project.save`,
``,
` update_deployment_target installer.pods_project, ${targetVersion}`,
`end`
].join("\n");
const assertDeploymentTargetReplacePhrase = [
`post_install do |installer|`,
` assertDeploymentTarget(installer)`,
`end`
].join("\n");

exports.addAssertDeploymentTarget = (capacitorPodFile) => {
let podFileContent = fse.readFileSync(
capacitorPodFile,
{ encoding: "utf-8" }
).toString();

if (podFileContent.includes("assertDeploymentTarget(installer)")) {
podFileContent = podFileContent.replace(assertDeploymentTargetReplacePhrase, "");
}

podFileContent = requireHelperPhrase + podFileContent + postInstallPhrase;
fse.writeFileSync(capacitorPodFile, podFileContent);
}

exports.removeAssertDeploymentTarget = (capacitorPodFile) => {
replaceAndSave(capacitorPodFile, [
[requireHelperPhrase, ""],
[postInstallPhrase, assertDeploymentTargetReplacePhrase]
]);
}

function replaceAndSave(filePath, collection) {
if (!fs.existsSync(filePath)) {
throw new Error(`File not exists at path ${filePath}`)
}
const encoding = { encoding: 'utf8' };

let fileContext = fs.readFileSync(filePath, encoding);
let fileContext = fs.readFileSync(filePath, encoding).toString();

for (const [search, replace] of collection) {
fileContext = fileContext.replace(search, replace);
Expand All @@ -221,4 +262,13 @@ function addLinkerForBuildType(buildType, linker) {
}
}

function getBlackBerryDynamicsPodPhrase(context) {
const [match] = context.match(/pod 'BlackBerryDynamics', (:podspec|:path) => '(.+)'/);
return match;
}

function addAfter(phrase, newPhrase) {
return `${phrase}\n\t${newPhrase}`
}

exports.replaceAndSave = replaceAndSave;
2 changes: 1 addition & 1 deletion scripts/hooks/ios/BlackBerryDynamics.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Pod::Spec.new do |spec|
spec.description = <<-DESC
Framework for building secure enterprise applications managed by BlackBerry Unified Endpoint Management (UEM).
DESC
spec.platform = :ios, '13.0'
spec.platform = :ios, '14.0'
spec.source = { :git => "", :tag => "#{spec.version}" }
spec.requires_arc = true
spec.swift_version = '5.0'
Expand Down
8 changes: 4 additions & 4 deletions scripts/hooks/ios/setDynamicsPodspec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
const { dynamicsPodSpec } = require(path.join(bbdBasePath, 'package.json'));
const pattern = /pod 'BlackBerryDynamics', (:podspec|:path) => '(.+)'/;

const parce = (arg, options = { value: null }) => {
const parse = (arg, options = { value: null }) => {
const argument = {
index: null,
value: null
Expand All @@ -46,9 +46,9 @@
}

const pod = {
path: parce('--path'),
url: parce('--url'),
default: parce('--default', { value: true })
path: parse('--path'),
url: parse('--url'),
default: parse('--default', { value: true })
}

let spec;
Expand Down
26 changes: 26 additions & 0 deletions scripts/hooks/ios/update_deployment_target.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2022 BlackBerry Limited. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

def update_deployment_target(project, version)
project.targets.each do |target|
target.build_configurations.each do |config|
deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f
if deployment_target < version && deployment_target != 0.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = "#{version}"
end
end
end
end

0 comments on commit 0d3550a

Please sign in to comment.