1{"version":3,"file":"GoogleServices.js","names":["DEFAULT_TARGET_PATH","googleServicesClassPath","googleServicesPlugin","googleServicesVersion","withClassPath","config","withProjectBuildGradle","modResults","language","contents","setClassPath","addWarningAndroid","withApplyPlugin","withAppBuildGradle","applyPlugin","withGoogleServicesFile","withDangerousMod","setGoogleServicesFile","modRequest","projectRoot","getGoogleServicesFilePath","android","googleServicesFile","targetPath","partialSourcePath","completeSourcePath","path","resolve","destinationPath","copyFilePathToPathAsync","e","console","log","Error","buildGradle","includes","replace","appBuildGradle","pattern","RegExp","match"],"sources":["../../src/android/GoogleServices.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config-types';\nimport path from 'path';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAppBuildGradle, withProjectBuildGradle } from '../plugins/android-plugins';\nimport { withDangerousMod } from '../plugins/withDangerousMod';\nimport { copyFilePathToPathAsync } from '../utils/fs';\nimport { addWarningAndroid } from '../utils/warnings';\n\nconst DEFAULT_TARGET_PATH = './android/app/google-services.json';\n\nconst googleServicesClassPath = 'com.google.gms:google-services';\nconst googleServicesPlugin = 'com.google.gms.google-services';\n\n// NOTE(brentvatne): This may be annoying to keep up to date...\nconst googleServicesVersion = '4.3.3';\n\nexport const withClassPath: ConfigPlugin = (config) => {\n  return withProjectBuildGradle(config, (config) => {\n    if (config.modResults.language === 'groovy') {\n      config.modResults.contents = setClassPath(config, config.modResults.contents);\n    } else {\n      addWarningAndroid(\n        'android.googleServicesFile',\n        `Cannot automatically configure project build.gradle if it's not groovy`\n      );\n    }\n    return config;\n  });\n};\n\nexport const withApplyPlugin: ConfigPlugin = (config) => {\n  return withAppBuildGradle(config, (config) => {\n    if (config.modResults.language === 'groovy') {\n      config.modResults.contents = applyPlugin(config, config.modResults.contents);\n    } else {\n      addWarningAndroid(\n        'android.googleServicesFile',\n        `Cannot automatically configure app build.gradle if it's not groovy`\n      );\n    }\n    return config;\n  });\n};\n\n/**\n * Add `google-services.json` to project\n */\nexport const withGoogleServicesFile: ConfigPlugin = (config) => {\n  return withDangerousMod(config, [\n    'android',\n    async (config) => {\n      await setGoogleServicesFile(config, config.modRequest.projectRoot);\n      return config;\n    },\n  ]);\n};\n\nexport function getGoogleServicesFilePath(config: Pick<ExpoConfig, 'android'>) {\n  return config.android?.googleServicesFile ?? null;\n}\n\nexport async function setGoogleServicesFile(\n  config: Pick<ExpoConfig, 'android'>,\n  projectRoot: string,\n  targetPath: string = DEFAULT_TARGET_PATH\n) {\n  const partialSourcePath = getGoogleServicesFilePath(config);\n  if (!partialSourcePath) {\n    return false;\n  }\n\n  const completeSourcePath = path.resolve(projectRoot, partialSourcePath);\n  const destinationPath = path.resolve(projectRoot, targetPath);\n\n  try {\n    await copyFilePathToPathAsync(completeSourcePath, destinationPath);\n  } catch (e) {\n    console.log(e);\n    throw new Error(\n      `Cannot copy google-services.json from ${completeSourcePath} to ${destinationPath}. Please make sure the source and destination paths exist.`\n    );\n  }\n  return true;\n}\n\n/**\n * Adding the Google Services plugin\n * NOTE(brentvatne): string replacement is a fragile approach! we need a\n * better solution than this.\n */\nexport function setClassPath(config: Pick<ExpoConfig, 'android'>, buildGradle: string) {\n  const googleServicesFile = getGoogleServicesFilePath(config);\n  if (!googleServicesFile) {\n    return buildGradle;\n  }\n\n  if (buildGradle.includes(googleServicesClassPath)) {\n    return buildGradle;\n  }\n\n  //\n  return buildGradle.replace(\n    /dependencies\\s?{/,\n    `dependencies {\n        classpath '${googleServicesClassPath}:${googleServicesVersion}'`\n  );\n}\n\nexport function applyPlugin(config: Pick<ExpoConfig, 'android'>, appBuildGradle: string) {\n  const googleServicesFile = getGoogleServicesFilePath(config);\n  if (!googleServicesFile) {\n    return appBuildGradle;\n  }\n\n  // Make sure the project does not have the plugin already\n  const pattern = new RegExp(`apply\\\\s+plugin:\\\\s+['\"]${googleServicesPlugin}['\"]`);\n  if (appBuildGradle.match(pattern)) {\n    return appBuildGradle;\n  }\n\n  // Add it to the end of the file\n  return appBuildGradle + `\\napply plugin: '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