Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMET-1497 ::: Hook to add google services dependency to build.gradle #9

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

The changes documented here do not include those from the original repository.


## [5.0.0-OS3]
## 2022-04-19
- Hook to add google services dependency to build.gradle. [RMET-1497](https://outsystemsrd.atlassian.net/browse/RMET-1497)

## [5.0.0-OS2]

## 2021-11-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ module.exports = function (context) {
var configParser = new ConfigParser(configXML);
var app_domain_name = configParser.getGlobalPreference("FIREBASE_DOMAIN_URL_PREFIX");

/* the code below is probably unnecessary
var pluginXMLPath = path.join(pluginPath, 'plugin.xml');
var new_xml = path.join(pluginPath, 'plugin.xml')
var dataPluginXML = fs.readFileSync(pluginXMLPath).toString();
var etree = et.parse(dataPluginXML);

var preferences = etree.findall('./preference');
for (var i = 0; i < preferences.length; i++) {
if (preferences[i].get('name') == "APP_DOMAIN_NAME") {
var pref = preferences[i];
pref.set("default", app_domain_name);
}
}

var root = etree.getroot();
root.insert(1, pref);

var resultXml = etree.write();
fs.writeFileSync(new_xml, resultXml, "utf-8");
*/

//ANDROID
//go inside the AndroidManifest and change value for APP_DOMAIN_NAME
var manifestPath = path.join(projectRoot, 'platforms/android/app/src/main/AndroidManifest.xml');
Expand Down
50 changes: 50 additions & 0 deletions hooks/android/build_gradle_add_dependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env node

module.exports = function(ctx) {
var fs = require('fs'),
os = require("os"),
readline = require("readline"),
deferral = require('q').defer();

var googleServicesStr = "if (project.extensions.findByName('googleServices') == null) { apply plugin: 'com.google.gms.google-services' }"
var googleServicesStrExists = false
var classpathsStrToVerify = "com.google.gms:google-services:4.3.10"
var classpathsStr = '\t\tclasspath "com.google.gms:google-services:4.3.10"'
var rootBuildGradlePath = "platforms/android/build.gradle"
var appBuildGradlePath = "platforms/android/app/build.gradle"

var lineReader = readline.createInterface({
terminal: false,
input : fs.createReadStream(rootBuildGradlePath)
});
lineReader.on("line", function(line) {
if (!line.includes(classpathsStrToVerify)) {
fs.appendFileSync('./build.gradle', line.toString() + os.EOL);
if (/.*\ dependencies \{.*/.test(line)) {
fs.appendFileSync('./build.gradle', classpathsStr + os.EOL);
}
}

}).on("close", function () {
fs.rename('./build.gradle', rootBuildGradlePath, deferral.resolve);
});

var lineReaderApp = readline.createInterface({
terminal: false,
input : fs.createReadStream(appBuildGradlePath)
});
lineReaderApp.on("line", function (line) {
if (line.includes(googleServicesStr)) {
googleServicesStrExists = true;
}
});
lineReaderApp.on("close", function () {
if (!googleServicesStrExists) {
fs.appendFileSync('./' + appBuildGradlePath, googleServicesStr + os.EOL);
fs.rename('./' + appBuildGradlePath, appBuildGradlePath, deferral.resolve);
}

});

return deferral.promise;
};
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-firebase-dynamiclinks",
"version": "5.0.0-OS2",
"version": "5.0.0-OS3",
"description": "Cordova plugin for Firebase Dynamic Links",
"cordova": {
"id": "cordova-plugin-firebase-dynamiclinks",
Expand Down
9 changes: 5 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-firebase-dynamiclinks"
version="5.0.0-OS2">
version="5.0.0-OS3">

<name>FirebaseDynamicLinksPlugin</name>
<description>Cordova plugin for Firebase Dynamic Links</description>
Expand All @@ -21,11 +21,12 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<preference name="APP_DOMAIN_NAME" default="firebase_domain_url_prefix"/>
<preference name="APP_DOMAIN_PATH" default="/" />

<dependency id="cordova-plugin-firebase-analytics" url="https://github.com/OutSystems/cordova-plugin-firebase-analytics.git#5.0.0-OS2"/>
<dependency id="cordova-plugin-firebase-analytics" url="https://github.com/OutSystems/cordova-plugin-firebase-analytics.git#5.0.0-OS3"/>

<platform name="android">

<hook type="after_prepare" src="hooks/androidCopyPreferences.js" />
<hook type="after_prepare" src="hooks/android/androidCopyPreferences.js" />
<hook type="before_plugin_install" src="hooks/android/build_gradle_add_dependency.js" />

<preference name="ANDROID_FIREBASE_DYNAMICLINKS_VERSION" default="20.1.+"/>

Expand Down Expand Up @@ -57,7 +58,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"
<platform name="ios">
<preference name="IOS_FIREBASE_DYNAMICLINKS_VERSION" default="~> 8.6.0"/>

<hook type="after_prepare" src="hooks/iOSCopyPreferences.js" />
<hook type="after_prepare" src="hooks/ios/iOSCopyPreferences.js" />

<config-file parent="/*" target="config.xml">
<preference name="DOMAIN_URI_PREFIX" value="https://$APP_DOMAIN_NAME$APP_DOMAIN_PATH"/>
Expand Down