Skip to content

Commit 6169a70

Browse files
RMET-3654 - Use hook to add Azure repo for Capacitor apps (#42)
* feat: replace config-file with edit-config to support Capacitor References: https://outsystemsrd.atlassian.net/browse/RMET-3654 * Revert "feat: replace config-file with edit-config to support Capacitor" This reverts commit 34cc97f. * feat: add capacitor hook to add Azure repo to build.gradle References: https://outsystemsrd.atlassian.net/browse/RMET-3654 * chore(release): raise to version 2.11.1-OS15 References: https://outsystemsrd.atlassian.net/browse/RMET-3654
1 parent e039be7 commit 6169a70

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.11.1-OS15]
8+
### Fixes
9+
- android | Add hook to add Azure repo to `build.gradle` (https://outsystemsrd.atlassian.net/browse/RMET-3654).
10+
711
## [2.11.1-OS14]
812
### Fixes
913
- iOS | Fix deeplink handling for iOS 18 (https://outsystemsrd.atlassian.net/browse/RMET-4236).
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const platform = process.env.CAPACITOR_PLATFORM_NAME;
5+
console.log("\OneSignal plugin - running hook after update - for " + platform);
6+
const projectDirPath = process.env.CAPACITOR_ROOT_DIR;
7+
8+
if (platform == 'android') {
9+
fixAndroidAzureRepository();
10+
}
11+
12+
/**
13+
* Add the azure repository (where OneSignal native Android library is housed) to project root's build.gradle
14+
* Because capacitor plugins are injected as separate gradle modules, this is necessary for release builds lintVital gradle tasks to pass.
15+
*/
16+
function fixAndroidAzureRepository() {
17+
const gradleFilePath = path.resolve(projectDirPath, 'android/build.gradle');
18+
const azureUrl = 'https://pkgs.dev.azure.com/OutSystemsRD/9e79bc5b-69b2-4476-9ca5-d67594972a52/_packaging/PublicArtifactRepository/maven/v1';
19+
const mavenBlock = ` maven {
20+
url "${azureUrl}"
21+
}`;
22+
23+
let gradleContent = fs.readFileSync(gradleFilePath, 'utf8');
24+
25+
if (gradleContent.includes(azureUrl)) {
26+
console.log('\t[SKIPPED] Azure repository already in root build.gradle.');
27+
} else {
28+
const allprojectsStart = gradleContent.indexOf('allprojects {');
29+
if (allprojectsStart === -1) {
30+
console.warn('\t[WARNING] Could not find allprojects { ... } block. Unable to add Azure Repository');
31+
return;
32+
}
33+
const repositoriesStart = gradleContent.indexOf('repositories {', allprojectsStart);
34+
if (repositoriesStart === -1) {
35+
console.warn('\t[WARNING] Could not find allprojects { repositories { ... } } block. Unable to add Azure Repository');
36+
return;
37+
}
38+
// Track braces to find end of repositories block
39+
let braceCount = 0;
40+
let i = repositoriesStart + 'repositories {'.length - 1;
41+
let endIndex = -1;
42+
while (i < gradleContent.length) {
43+
if (gradleContent[i] === '{') braceCount++;
44+
else if (gradleContent[i] === '}') braceCount--;
45+
46+
if (braceCount === 0) {
47+
endIndex = i;
48+
break;
49+
}
50+
i++;
51+
}
52+
if (endIndex === -1) {
53+
console.warn('\t[WARNING] Could not find allprojects { repositories { ... } } block. Unable to add Azure Repository');
54+
return;
55+
}
56+
const closingBraceLineStartIndex = gradleContent.lastIndexOf('\n', endIndex);
57+
// Insert the maven block at the end of the repositories block (before closing brace), because gradle searches repositories by order.
58+
// The Azure repo should be the last one since it will only apply for a few dependencies.
59+
// Otherwise this could slow down gradle build.
60+
const updatedContent = gradleContent.slice(0, closingBraceLineStartIndex) + '\n' + mavenBlock + gradleContent.slice(closingBraceLineStartIndex);
61+
fs.writeFileSync(gradleFilePath, updatedContent, 'utf8');
62+
console.log('\t[SUCCESS] Added Azure repository maven block to the root build.gradle.');
63+
}
64+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.11.1-OS14",
2+
"version": "2.11.1-OS15",
33
"name": "onesignal-cordova-plugin",
44
"cordova_name": "OneSignal Push Notifications",
55
"description": "OneSignal is a high volume Push Notification service for mobile apps. In addition to basic notification delivery, OneSignal also provides tools to localize, target, schedule, and automate notifications that you send.",
@@ -67,7 +67,8 @@
6767
"homepage": "https://github.com/onesignal/OneSignal-Cordova-SDK#readme",
6868
"scripts": {
6969
"build": "vite build",
70-
"test": "jest --coverage --ci"
70+
"test": "jest --coverage --ci",
71+
"capacitor:update:after": "node capacitor_hooks/insert_azure_repository.js"
7172
},
7273
"devDependencies": {
7374
"jest": "^29.7.0",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
id="onesignal-cordova-plugin"
5-
version="2.11.1-OS14">
5+
version="2.11.1-OS15">
66

77
<name>OneSignal Push Notifications</name>
88
<author>Josh Kasten, Bradley Hesse, Rodrigo Gomez-Palacio</author>

0 commit comments

Comments
 (0)