1{"version":3,"file":"GoogleServices.js","names":["_path","data","_interopRequireDefault","require","_androidPlugins","_withDangerousMod","_fs","_warnings","obj","__esModule","default","DEFAULT_TARGET_PATH","googleServicesClassPath","googleServicesPlugin","googleServicesVersion","withClassPath","config","withProjectBuildGradle","modResults","language","contents","setClassPath","addWarningAndroid","exports","withApplyPlugin","withAppBuildGradle","applyPlugin","withGoogleServicesFile","withDangerousMod","setGoogleServicesFile","modRequest","projectRoot","getGoogleServicesFilePath","_config$android$googl","_config$android","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: '${googleServicesPlugin}'`;\n}\n"],"mappings":";;;;;;;;;;AACA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,sBAAA,CAAAC,OAAA;EAAAH,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAGA,SAAAG,gBAAA;EAAA,MAAAH,IAAA,GAAAE,OAAA;EAAAC,eAAA,YAAAA,CAAA;IAAA,OAAAH,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAI,kBAAA;EAAA,MAAAJ,IAAA,GAAAE,OAAA;EAAAE,iBAAA,YAAAA,CAAA;IAAA,OAAAJ,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAK,IAAA;EAAA,MAAAL,IAAA,GAAAE,OAAA;EAAAG,GAAA,YAAAA,CAAA;IAAA,OAAAL,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AACA,SAAAM,UAAA;EAAA,MAAAN,IAAA,GAAAE,OAAA;EAAAI,SAAA,YAAAA,CAAA;IAAA,OAAAN,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAAsD,SAAAC,uBAAAM,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEtD,MAAMG,mBAAmB,GAAG,oCAAoC;AAEhE,MAAMC,uBAAuB,GAAG,gCAAgC;AAChE,MAAMC,oBAAoB,GAAG,gCAAgC;;AAE7D;AACA,MAAMC,qBAAqB,GAAG,OAAO;AAE9B,MAAMC,aAA2B,GAAIC,MAAM,IAAK;EACrD,OAAO,IAAAC,wCAAsB,EAACD,MAAM,EAAGA,MAAM,IAAK;IAChD,IAAIA,MAAM,CAACE,UAAU,CAACC,QAAQ,KAAK,QAAQ,EAAE;MAC3CH,MAAM,CAACE,UA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