"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const ios_plugins_1 = require("../plugins/ios-plugins"); const Paths_1 = require("./Paths"); const Scheme_1 = require("./Scheme"); const Xcodeproj_1 = require("./utils/Xcodeproj"); exports.withGoogle = ios_plugins_1.createInfoPlistPlugin(setGoogleConfig, 'withGoogle'); exports.withGoogleServicesFile = config => { return ios_plugins_1.withXcodeProject(config, config => { config.modResults = setGoogleServicesFile(config, { projectRoot: config.modRequest.projectRoot, project: config.modResults, }); return config; }); }; function getGoogleSignInReservedClientId(config) { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.ios) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.googleSignIn) === null || _c === void 0 ? void 0 : _c.reservedClientId) !== null && _d !== void 0 ? _d : null; } exports.getGoogleSignInReservedClientId = getGoogleSignInReservedClientId; function getGoogleServicesFile(config) { var _a, _b; return (_b = (_a = config.ios) === null || _a === void 0 ? void 0 : _a.googleServicesFile) !== null && _b !== void 0 ? _b : null; } exports.getGoogleServicesFile = getGoogleServicesFile; function setGoogleSignInReservedClientId(config, infoPlist) { const reservedClientId = getGoogleSignInReservedClientId(config); if (reservedClientId === null) { return infoPlist; } return Scheme_1.appendScheme(reservedClientId, infoPlist); } exports.setGoogleSignInReservedClientId = setGoogleSignInReservedClientId; function setGoogleConfig(config, infoPlist) { infoPlist = setGoogleSignInReservedClientId(config, infoPlist); return infoPlist; } exports.setGoogleConfig = setGoogleConfig; function setGoogleServicesFile(config, { projectRoot, project }) { const googleServicesFileRelativePath = getGoogleServicesFile(config); if (googleServicesFileRelativePath === null) { return project; } const googleServiceFilePath = path_1.default.resolve(projectRoot, googleServicesFileRelativePath); fs_extra_1.default.copyFileSync(googleServiceFilePath, path_1.default.join(Paths_1.getSourceRoot(projectRoot), 'GoogleService-Info.plist')); const projectName = Xcodeproj_1.getProjectName(projectRoot); const plistFilePath = `${projectName}/GoogleService-Info.plist`; if (!project.hasFile(plistFilePath)) { project = Xcodeproj_1.addResourceFileToGroup({ filepath: plistFilePath, groupName: projectName, project, isBuildFile: true, }); } return project; } exports.setGoogleServicesFile = setGoogleServicesFile; //# sourceMappingURL=Google.js.map