1"use strict"; 2 3Object.defineProperty(exports, "__esModule", { 4 value: true 5}); 6exports.getGoogleServicesFile = getGoogleServicesFile; 7exports.getGoogleSignInReservedClientId = getGoogleSignInReservedClientId; 8exports.setGoogleConfig = setGoogleConfig; 9exports.setGoogleServicesFile = setGoogleServicesFile; 10exports.setGoogleSignInReservedClientId = setGoogleSignInReservedClientId; 11exports.withGoogleServicesFile = exports.withGoogle = void 0; 12 13function _plist() { 14 const data = _interopRequireDefault(require("@expo/plist")); 15 16 _plist = function () { 17 return data; 18 }; 19 20 return data; 21} 22 23function _assert() { 24 const data = _interopRequireDefault(require("assert")); 25 26 _assert = function () { 27 return data; 28 }; 29 30 return data; 31} 32 33function _fs() { 34 const data = _interopRequireDefault(require("fs")); 35 36 _fs = function () { 37 return data; 38 }; 39 40 return data; 41} 42 43function _path() { 44 const data = _interopRequireDefault(require("path")); 45 46 _path = function () { 47 return data; 48 }; 49 50 return data; 51} 52 53function _iosPlugins() { 54 const data = require("../plugins/ios-plugins"); 55 56 _iosPlugins = function () { 57 return data; 58 }; 59 60 return data; 61} 62 63function _Paths() { 64 const data = require("./Paths"); 65 66 _Paths = function () { 67 return data; 68 }; 69 70 return data; 71} 72 73function _Scheme() { 74 const data = require("./Scheme"); 75 76 _Scheme = function () { 77 return data; 78 }; 79 80 return data; 81} 82 83function _Xcodeproj() { 84 const data = require("./utils/Xcodeproj"); 85 86 _Xcodeproj = function () { 87 return data; 88 }; 89 90 return data; 91} 92 93function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 94 95const withGoogle = config => { 96 return (0, _iosPlugins().withInfoPlist)(config, config => { 97 config.modResults = setGoogleConfig(config, config.modResults, config.modRequest); 98 return config; 99 }); 100}; 101 102exports.withGoogle = withGoogle; 103 104const withGoogleServicesFile = config => { 105 return (0, _iosPlugins().withXcodeProject)(config, config => { 106 config.modResults = setGoogleServicesFile(config, { 107 projectRoot: config.modRequest.projectRoot, 108 project: config.modResults 109 }); 110 return config; 111 }); 112}; 113 114exports.withGoogleServicesFile = withGoogleServicesFile; 115 116function readGoogleServicesInfoPlist(relativePath, { 117 projectRoot 118}) { 119 const googleServiceFilePath = _path().default.resolve(projectRoot, relativePath); 120 121 const contents = _fs().default.readFileSync(googleServiceFilePath, 'utf8'); 122 123 (0, _assert().default)(contents, 'GoogleService-Info.plist is empty'); 124 return _plist().default.parse(contents); 125} 126 127function getGoogleSignInReservedClientId(config, modRequest) { 128 var _config$ios$config$go, _config$ios, _config$ios$config, _config$ios$config$go2, _infoPlist$REVERSED_C; 129 130 const reservedClientId = (_config$ios$config$go = (_config$ios = config.ios) === null || _config$ios === void 0 ? void 0 : (_config$ios$config = _config$ios.config) === null || _config$ios$config === void 0 ? void 0 : (_config$ios$config$go2 = _config$ios$config.googleSignIn) === null || _config$ios$config$go2 === void 0 ? void 0 : _config$ios$config$go2.reservedClientId) !== null && _config$ios$config$go !== void 0 ? _config$ios$config$go : null; 131 132 if (reservedClientId) { 133 return reservedClientId; 134 } 135 136 const googleServicesFileRelativePath = getGoogleServicesFile(config); 137 138 if (googleServicesFileRelativePath === null) { 139 return null; 140 } 141 142 const infoPlist = readGoogleServicesInfoPlist(googleServicesFileRelativePath, modRequest); 143 return (_infoPlist$REVERSED_C = infoPlist.REVERSED_CLIENT_ID) !== null && _infoPlist$REVERSED_C !== void 0 ? _infoPlist$REVERSED_C : null; 144} 145 146function getGoogleServicesFile(config) { 147 var _config$ios$googleSer, _config$ios2; 148 149 return (_config$ios$googleSer = (_config$ios2 = config.ios) === null || _config$ios2 === void 0 ? void 0 : _config$ios2.googleServicesFile) !== null && _config$ios$googleSer !== void 0 ? _config$ios$googleSer : null; 150} 151 152function setGoogleSignInReservedClientId(config, infoPlist, modRequest) { 153 const reservedClientId = getGoogleSignInReservedClientId(config, modRequest); 154 155 if (reservedClientId === null) { 156 return infoPlist; 157 } 158 159 return (0, _Scheme().appendScheme)(reservedClientId, infoPlist); 160} 161 162function setGoogleConfig(config, infoPlist, modRequest) { 163 infoPlist = setGoogleSignInReservedClientId(config, infoPlist, modRequest); 164 return infoPlist; 165} 166 167function setGoogleServicesFile(config, { 168 projectRoot, 169 project 170}) { 171 const googleServicesFileRelativePath = getGoogleServicesFile(config); 172 173 if (googleServicesFileRelativePath === null) { 174 return project; 175 } 176 177 const googleServiceFilePath = _path().default.resolve(projectRoot, googleServicesFileRelativePath); 178 179 _fs().default.copyFileSync(googleServiceFilePath, _path().default.join((0, _Paths().getSourceRoot)(projectRoot), 'GoogleService-Info.plist')); 180 181 const projectName = (0, _Xcodeproj().getProjectName)(projectRoot); 182 const plistFilePath = `${projectName}/GoogleService-Info.plist`; 183 184 if (!project.hasFile(plistFilePath)) { 185 project = (0, _Xcodeproj().addResourceFileToGroup)({ 186 filepath: plistFilePath, 187 groupName: projectName, 188 project, 189 isBuildFile: true, 190 verbose: true 191 }); 192 } 193 194 return project; 195} 196//# sourceMappingURL=Google.js.map