1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.getGoogleServicesFile = getGoogleServicesFile;
7exports.getGoogleSignInReversedClientId = getGoogleSignInReversedClientId;
8exports.setGoogleConfig = setGoogleConfig;
9exports.setGoogleServicesFile = setGoogleServicesFile;
10exports.setGoogleSignInReversedClientId = setGoogleSignInReversedClientId;
11exports.withGoogleServicesFile = exports.withGoogle = void 0;
12function _plist() {
13  const data = _interopRequireDefault(require("@expo/plist"));
14  _plist = function () {
15    return data;
16  };
17  return data;
18}
19function _assert() {
20  const data = _interopRequireDefault(require("assert"));
21  _assert = function () {
22    return data;
23  };
24  return data;
25}
26function _fs() {
27  const data = _interopRequireDefault(require("fs"));
28  _fs = function () {
29    return data;
30  };
31  return data;
32}
33function _path() {
34  const data = _interopRequireDefault(require("path"));
35  _path = function () {
36    return data;
37  };
38  return data;
39}
40function _Paths() {
41  const data = require("./Paths");
42  _Paths = function () {
43    return data;
44  };
45  return data;
46}
47function _Scheme() {
48  const data = require("./Scheme");
49  _Scheme = function () {
50    return data;
51  };
52  return data;
53}
54function _Xcodeproj() {
55  const data = require("./utils/Xcodeproj");
56  _Xcodeproj = function () {
57    return data;
58  };
59  return data;
60}
61function _iosPlugins() {
62  const data = require("../plugins/ios-plugins");
63  _iosPlugins = function () {
64    return data;
65  };
66  return data;
67}
68function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69const withGoogle = config => {
70  return (0, _iosPlugins().withInfoPlist)(config, config => {
71    config.modResults = setGoogleConfig(config, config.modResults, config.modRequest);
72    return config;
73  });
74};
75exports.withGoogle = withGoogle;
76const withGoogleServicesFile = config => {
77  return (0, _iosPlugins().withXcodeProject)(config, config => {
78    config.modResults = setGoogleServicesFile(config, {
79      projectRoot: config.modRequest.projectRoot,
80      project: config.modResults
81    });
82    return config;
83  });
84};
85exports.withGoogleServicesFile = withGoogleServicesFile;
86function readGoogleServicesInfoPlist(relativePath, {
87  projectRoot
88}) {
89  const googleServiceFilePath = _path().default.resolve(projectRoot, relativePath);
90  const contents = _fs().default.readFileSync(googleServiceFilePath, 'utf8');
91  (0, _assert().default)(contents, 'GoogleService-Info.plist is empty');
92  return _plist().default.parse(contents);
93}
94function getGoogleSignInReversedClientId(config, modRequest) {
95  var _infoPlist$REVERSED_C;
96  const googleServicesFileRelativePath = getGoogleServicesFile(config);
97  if (googleServicesFileRelativePath === null) {
98    return null;
99  }
100  const infoPlist = readGoogleServicesInfoPlist(googleServicesFileRelativePath, modRequest);
101  return (_infoPlist$REVERSED_C = infoPlist.REVERSED_CLIENT_ID) !== null && _infoPlist$REVERSED_C !== void 0 ? _infoPlist$REVERSED_C : null;
102}
103function getGoogleServicesFile(config) {
104  var _config$ios$googleSer, _config$ios;
105  return (_config$ios$googleSer = (_config$ios = config.ios) === null || _config$ios === void 0 ? void 0 : _config$ios.googleServicesFile) !== null && _config$ios$googleSer !== void 0 ? _config$ios$googleSer : null;
106}
107function setGoogleSignInReversedClientId(config, infoPlist, modRequest) {
108  const reversedClientId = getGoogleSignInReversedClientId(config, modRequest);
109  if (reversedClientId === null) {
110    return infoPlist;
111  }
112  return (0, _Scheme().appendScheme)(reversedClientId, infoPlist);
113}
114function setGoogleConfig(config, infoPlist, modRequest) {
115  infoPlist = setGoogleSignInReversedClientId(config, infoPlist, modRequest);
116  return infoPlist;
117}
118function setGoogleServicesFile(config, {
119  projectRoot,
120  project
121}) {
122  const googleServicesFileRelativePath = getGoogleServicesFile(config);
123  if (googleServicesFileRelativePath === null) {
124    return project;
125  }
126  const googleServiceFilePath = _path().default.resolve(projectRoot, googleServicesFileRelativePath);
127  _fs().default.copyFileSync(googleServiceFilePath, _path().default.join((0, _Paths().getSourceRoot)(projectRoot), 'GoogleService-Info.plist'));
128  const projectName = (0, _Xcodeproj().getProjectName)(projectRoot);
129  const plistFilePath = `${projectName}/GoogleService-Info.plist`;
130  if (!project.hasFile(plistFilePath)) {
131    project = (0, _Xcodeproj().addResourceFileToGroup)({
132      filepath: plistFilePath,
133      groupName: projectName,
134      project,
135      isBuildFile: true,
136      verbose: true
137    });
138  }
139  return project;
140}
141//# sourceMappingURL=Google.js.map