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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