1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const fs_extra_1 = __importDefault(require("fs-extra"));
|
7 | const path_1 = require("path");
|
8 | const DEFAULT_TARGET_PATH = './android/app/google-services.json';
|
9 | function getGoogleServicesFilePath(config) {
|
10 | var _a, _b;
|
11 | return _b = (_a = config.android) === null || _a === void 0 ? void 0 : _a.googleServicesFile, (_b !== null && _b !== void 0 ? _b : null);
|
12 | }
|
13 | exports.getGoogleServicesFilePath = getGoogleServicesFilePath;
|
14 | async function setGoogleServicesFile(config, projectDirectory, targetPath = DEFAULT_TARGET_PATH) {
|
15 | let partialSourcePath = getGoogleServicesFilePath(config);
|
16 | if (!partialSourcePath) {
|
17 | return false;
|
18 | }
|
19 | const completeSourcePath = path_1.resolve(projectDirectory, partialSourcePath);
|
20 | const destinationPath = path_1.resolve(projectDirectory, targetPath);
|
21 | try {
|
22 | await fs_extra_1.default.copy(completeSourcePath, destinationPath);
|
23 | }
|
24 | catch (e) {
|
25 | throw new Error(`Cannot copy google-services.json from ${completeSourcePath} to ${destinationPath}. Please make sure the source and destination paths exist.`);
|
26 | }
|
27 | return true;
|
28 | }
|
29 | exports.setGoogleServicesFile = setGoogleServicesFile;
|
30 | const googleServicesClassPath = 'com.google.gms:google-services';
|
31 | const googleServicesPlugin = 'com.google.gms.google-services';
|
32 |
|
33 | const googleServicesVersion = '4.3.3';
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function setClassPath(config, buildGradle) {
|
40 | let googleServicesFile = getGoogleServicesFilePath(config);
|
41 | if (!googleServicesFile) {
|
42 | return buildGradle;
|
43 | }
|
44 | if (buildGradle.includes(googleServicesClassPath)) {
|
45 | return buildGradle;
|
46 | }
|
47 |
|
48 | return buildGradle.replace(/dependencies\s?{/, `dependencies {
|
49 | classpath '${googleServicesClassPath}:${googleServicesVersion}'`);
|
50 | }
|
51 | exports.setClassPath = setClassPath;
|
52 | function applyPlugin(config, appBuildGradle) {
|
53 | let googleServicesFile = getGoogleServicesFilePath(config);
|
54 | if (!googleServicesFile) {
|
55 | return appBuildGradle;
|
56 | }
|
57 |
|
58 | let pattern = new RegExp(`apply\\s+plugin:\\s+['"]${googleServicesPlugin}['"]`);
|
59 | if (appBuildGradle.match(pattern)) {
|
60 | return appBuildGradle;
|
61 | }
|
62 |
|
63 | return appBuildGradle + `\napply plugin: '${googleServicesPlugin}'`;
|
64 | }
|
65 | exports.applyPlugin = applyPlugin;
|
66 |
|
\ | No newline at end of file |