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

Commit da55c2a

Browse files
Some automations for Android #198
1 parent 4eddc18 commit da55c2a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

scripts/installer.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function promptQuestionsResult(result) {
138138
if(usingAndroid) {
139139
writeGradleFile(result);
140140
writeGoogleServiceCopyHook();
141+
writeGoogleServiceGradleHook();
141142
}
142143
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`.');
143144
}
@@ -315,6 +316,56 @@ module.exports = function() {
315316
}
316317
}
317318

319+
function writeGoogleServiceGradleHook() {
320+
console.log("Install firebase-build-gradle hook.");
321+
try {
322+
var scriptContent =
323+
`
324+
var path = require("path");
325+
var fs = require("fs");
326+
327+
module.exports = function() {
328+
329+
console.log("Configure firebase");
330+
var buildGradlePath = path.join(__dirname, "..", "..", "platforms", "android", "build.gradle");
331+
if (fs.existsSync(buildGradlePath)) {
332+
var buildGradleContent = fs.readFileSync(buildGradlePath).toString();
333+
334+
if (buildGradleContent.indexOf('classpath "com.google.gms:google-services:3.0.0"') != -1) {
335+
return;
336+
}
337+
338+
var search = -1;
339+
340+
search = buildGradleContent.indexOf("repositories", 0);
341+
if (search == -1) {
342+
return;
343+
}
344+
345+
search = buildGradleContent.indexOf("dependencies", search);
346+
if (search == -1) {
347+
return;
348+
}
349+
350+
search = buildGradleContent.indexOf("}", search);
351+
if (search == -1) {
352+
return;
353+
}
354+
355+
buildGradleContent = buildGradleContent.substr(0, search - 1) + ' classpath "com.google.gms:google-services:3.0.0"\\n ' + buildGradleContent.substr(search - 1);
356+
357+
fs.writeFileSync(buildGradlePath, buildGradleContent);
358+
}
359+
};
360+
`;
361+
var scriptPath = path.join(appRoot, "hooks", "after-prepare", "firebase-build-gradle.js");
362+
fs.writeFileSync(scriptPath, scriptContent);
363+
} catch(e) {
364+
console.log("Failed to install firebase-build-gradle hook.");
365+
console.log(e);
366+
}
367+
}
368+
318369
/**
319370
* Determines if the answer validates as selected
320371
*

0 commit comments

Comments
 (0)