Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Some automations for Android #198
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Nov 20, 2016
1 parent 399c087 commit 3b27bfc
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions scripts/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function promptQuestionsResult(result) {
if(usingAndroid) {
writeGradleFile(result);
writeGoogleServiceCopyHook();
writeGoogleServiceGradleHook();
}
console.log('Firebase post install completed. To re-run this script, navigate to the root directory of `nativescript-plugin-firebase` in your `node_modules` folder and run: `npm run config`.');
}
Expand Down Expand Up @@ -315,6 +316,56 @@ module.exports = function() {
}
}

function writeGoogleServiceGradleHook() {
console.log("Install firebase-build-gradle hook.");
try {
var scriptContent =
`
var path = require("path");
var fs = require("fs");
module.exports = function() {
console.log("Configure firebase");
var buildGradlePath = path.join(__dirname, "..", "..", "platforms", "android", "build.gradle");
if (fs.existsSync(buildGradlePath)) {
var buildGradleContent = fs.readFileSync(buildGradlePath).toString();
if (buildGradleContent.indexOf('classpath "com.google.gms:google-services:3.0.0"') != -1) {
return;
}
var search = -1;
search = buildGradleContent.indexOf("repositories", 0);
if (search == -1) {
return;
}
search = buildGradleContent.indexOf("dependencies", search);
if (search == -1) {
return;
}
search = buildGradleContent.indexOf("}", search);
if (search == -1) {
return;
}
buildGradleContent = buildGradleContent.substr(0, search - 1) + ' classpath "com.google.gms:google-services:3.0.0"\\n ' + buildGradleContent.substr(search - 1);
fs.writeFileSync(buildGradlePath, buildGradleContent);
}
};
`;
var scriptPath = path.join(appRoot, "hooks", "after-prepare", "firebase-build-gradle.js");
fs.writeFileSync(scriptPath, scriptContent);
} catch(e) {
console.log("Failed to install firebase-build-gradle hook.");
console.log(e);
}
}

/**
* Determines if the answer validates as selected
*
Expand Down

0 comments on commit 3b27bfc

Please sign in to comment.