Skip to content

Commit

Permalink
Merge pull request #9 from OutSystems/fix/RMET-1497/gradle-build-extras
Browse files Browse the repository at this point in the history
RMET-1497 ::: Hook to add google services dependency to build.gradle
  • Loading branch information
CarlsCorrea committed Apr 20, 2022
2 parents 4d535dd + 6d12c65 commit fb60973
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
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

0 comments on commit fb60973

Please sign in to comment.