1{"version":3,"file":"Google.js","names":["withGoogle","config","withInfoPlist","modResults","setGoogleConfig","modRequest","withGoogleServicesFile","withXcodeProject","setGoogleServicesFile","projectRoot","project","readGoogleServicesInfoPlist","relativePath","googleServiceFilePath","path","resolve","contents","fs","readFileSync","assert","plist","parse","getGoogleSignInReservedClientId","reservedClientId","ios","googleSignIn","googleServicesFileRelativePath","getGoogleServicesFile","infoPlist","REVERSED_CLIENT_ID","googleServicesFile","setGoogleSignInReservedClientId","appendScheme","copyFileSync","join","getSourceRoot","projectName","getProjectName","plistFilePath","hasFile","addResourceFileToGroup","filepath","groupName","isBuildFile","verbose"],"sources":["../../src/ios/Google.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport plist from '@expo/plist';\nimport assert from 'assert';\nimport fs from 'fs';\nimport path from 'path';\nimport { XcodeProject } from 'xcode';\n\nimport { ConfigPlugin, ModProps } from '../Plugin.types';\nimport { withInfoPlist, withXcodeProject } from '../plugins/ios-plugins';\nimport { InfoPlist } from './IosConfig.types';\nimport { getSourceRoot } from './Paths';\nimport { appendScheme } from './Scheme';\nimport { addResourceFileToGroup, getProjectName } from './utils/Xcodeproj';\n\nexport const withGoogle: ConfigPlugin = (config) => {\n return withInfoPlist(config, (config) => {\n config.modResults = setGoogleConfig(config, config.modResults, config.modRequest);\n return config;\n });\n};\n\nexport const withGoogleServicesFile: ConfigPlugin = (config) => {\n return withXcodeProject(config, (config) => {\n config.modResults = setGoogleServicesFile(config, {\n projectRoot: config.modRequest.projectRoot,\n project: config.modResults,\n });\n return config;\n });\n};\n\nfunction readGoogleServicesInfoPlist(\n relativePath: string,\n { projectRoot }: { projectRoot: string }\n) {\n const googleServiceFilePath = path.resolve(projectRoot, relativePath);\n const contents = fs.readFileSync(googleServiceFilePath, 'utf8');\n assert(contents, 'GoogleService-Info.plist is empty');\n return plist.parse(contents);\n}\n\nexport function getGoogleSignInReservedClientId(\n config: Pick<ExpoConfig, 'ios'>,\n modRequest: Pick<ModProps<InfoPlist>, 'projectRoot'>\n): string | null {\n const reservedClientId = config.ios?.config?.googleSignIn?.reservedClientId ?? null;\n if (reservedClientId) {\n return reservedClientId;\n }\n\n const googleServicesFileRelativePath = getGoogleServicesFile(config);\n if (googleServicesFileRelativePath === null) {\n return null;\n }\n\n const infoPlist = readGoogleServicesInfoPlist(googleServicesFileRelativePath, modRequest);\n\n return infoPlist.REVERSED_CLIENT_ID ?? null;\n}\n\nexport function getGoogleServicesFile(config: Pick<ExpoConfig, 'ios'>) {\n return config.ios?.googleServicesFile ?? null;\n}\n\nexport function setGoogleSignInReservedClientId(\n config: Pick<ExpoConfig, 'ios'>,\n infoPlist: InfoPlist,\n modRequest: Pick<ModProps<InfoPlist>, 'projectRoot'>\n): InfoPlist {\n const reservedClientId = getGoogleSignInReservedClientId(config, modRequest);\n\n if (reservedClientId === null) {\n return infoPlist;\n }\n\n return appendScheme(reservedClientId, infoPlist);\n}\n\nexport function setGoogleConfig(\n config: Pick<ExpoConfig, 'ios'>,\n infoPlist: InfoPlist,\n modRequest: ModProps<InfoPlist>\n): InfoPlist {\n infoPlist = setGoogleSignInReservedClientId(config, infoPlist, modRequest);\n return infoPlist;\n}\n\nexport function setGoogleServicesFile(\n config: Pick<ExpoConfig, 'ios'>,\n { projectRoot, project }: { project: XcodeProject; projectRoot: string }\n): XcodeProject {\n const googleServicesFileRelativePath = getGoogleServicesFile(config);\n if (googleServicesFileRelativePath === null) {\n return project;\n }\n\n const googleServiceFilePath = path.resolve(projectRoot, googleServicesFileRelativePath);\n fs.copyFileSync(\n googleServiceFilePath,\n path.join(getSourceRoot(projectRoot), 'GoogleService-Info.plist')\n );\n\n const projectName = getProjectName(projectRoot);\n const plistFilePath = `${projectName}/GoogleService-Info.plist`;\n if (!project.hasFile(plistFilePath)) {\n project = addResourceFileToGroup({\n filepath: plistFilePath,\n groupName: projectName,\n project,\n isBuildFile: true,\n verbose: true,\n });\n }\n return project;\n}\n"],"mappings":";;;;;;;;;;;;AACA;EAAA;;EA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