UNPKG

2.8 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const fs_extra_1 = __importDefault(require("fs-extra"));
7const path_1 = require("path");
8const DEFAULT_TARGET_PATH = './android/app/google-services.json';
9function 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}
13exports.getGoogleServicesFilePath = getGoogleServicesFilePath;
14async 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}
29exports.setGoogleServicesFile = setGoogleServicesFile;
30const googleServicesClassPath = 'com.google.gms:google-services';
31const googleServicesPlugin = 'com.google.gms.google-services';
32// NOTE(brentvatne): This may be annoying to keep up to date...
33const googleServicesVersion = '4.3.3';
34/**
35 * Adding the Google Services plugin
36 * NOTE(brentvatne): string replacement is a fragile approach! we need a
37 * better solution than this.
38 */
39function 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}
51exports.setClassPath = setClassPath;
52function applyPlugin(config, appBuildGradle) {
53 let googleServicesFile = getGoogleServicesFilePath(config);
54 if (!googleServicesFile) {
55 return appBuildGradle;
56 }
57 // Make sure the project does not have the plugin already
58 let pattern = new RegExp(`apply\\s+plugin:\\s+['"]${googleServicesPlugin}['"]`);
59 if (appBuildGradle.match(pattern)) {
60 return appBuildGradle;
61 }
62 // Add it to the end of the file
63 return appBuildGradle + `\napply plugin: '${googleServicesPlugin}'`;
64}
65exports.applyPlugin = applyPlugin;
66//# sourceMappingURL=GoogleServices.js.map
\No newline at end of file