1{"version":3,"file":"Version.js","names":["withVersion","config","withAppBuildGradle","modResults","language","contents","setVersionCode","setVersionName","addWarningAndroid","withBuildScriptExtMinimumVersion","props","withProjectBuildGradle","setMinBuildScriptExtVersion","buildGradle","name","minVersion","regex","RegExp","currentVersion","match","currentVersionNum","Number","replace","Math","max","getVersionName","version","versionName","pattern","getVersionCode","android","versionCode"],"sources":["../../src/android/Version.ts"],"sourcesContent":["import { ExpoConfig } from '@expo/config-types';\n\nimport { ConfigPlugin } from '../Plugin.types';\nimport { withAppBuildGradle, withProjectBuildGradle } from '../plugins/android-plugins';\nimport { addWarningAndroid } from '../utils/warnings';\n\nexport const withVersion: ConfigPlugin = (config) => {\n  return withAppBuildGradle(config, (config) => {\n    if (config.modResults.language === 'groovy') {\n      config.modResults.contents = setVersionCode(config, config.modResults.contents);\n      config.modResults.contents = setVersionName(config, config.modResults.contents);\n    } else {\n      addWarningAndroid(\n        'android.versionCode',\n        `Cannot automatically configure app build.gradle if it's not groovy`\n      );\n    }\n    return config;\n  });\n};\n\n/** Sets a numeric version for a value in the project.gradle buildscript.ext object to be at least the provided props.minVersion, if the existing value is greater then no change will be made. */\nexport const withBuildScriptExtMinimumVersion: ConfigPlugin<{\n  name: string;\n  minVersion: number;\n}> = (config, props) => {\n  return withProjectBuildGradle(config, (config) => {\n    if (config.modResults.language === 'groovy') {\n      config.modResults.contents = setMinBuildScriptExtVersion(config.modResults.contents, props);\n    } else {\n      addWarningAndroid(\n        'withBuildScriptExtVersion',\n        `Cannot automatically configure project build.gradle if it's not groovy`\n      );\n    }\n    return config;\n  });\n};\n\nexport function setMinBuildScriptExtVersion(\n  buildGradle: string,\n  { name, minVersion }: { name: string; minVersion: number }\n) {\n  const regex = new RegExp(`(${name}\\\\s?=\\\\s?)(\\\\d+(?:\\\\.\\\\d+)?)`);\n  const currentVersion = buildGradle.match(regex)?.[2];\n  if (!currentVersion) {\n    addWarningAndroid(\n      'withBuildScriptExtVersion',\n      `Cannot set minimum buildscript.ext.${name} version because the property \"${name}\" cannot be found or does not have a numeric value.`\n    );\n    // TODO: Maybe just add the property...\n    return buildGradle;\n  }\n\n  const currentVersionNum = Number(currentVersion);\n  return buildGradle.replace(regex, `$1${Math.max(minVersion, currentVersionNum)}`);\n}\n\nexport function getVersionName(config: Pick<ExpoConfig, 'version'>) {\n  return config.version ?? null;\n}\n\nexport function setVersionName(config: Pick<ExpoConfig, 'version'>, buildGradle: string) {\n  const versionName = getVersionName(config);\n  if (versionName === null) {\n    return buildGradle;\n  }\n\n  const pattern = new RegExp(`versionName \".*\"`);\n  return buildGradle.replace(pattern, `versionName \"${versionName}\"`);\n}\n\nexport function getVersionCode(config: Pick<ExpoConfig, 'android'>) {\n  return config.android?.versionCode ?? 1;\n}\n\nexport function setVersionCode(config: Pick<ExpoConfig, 'android'>, buildGradle: string) {\n  const versionCode = getVersionCode(config);\n  if (versionCode === null) {\n    return buildGradle;\n  }\n\n  const pattern = new RegExp(`versionCode.*`);\n  return buildGradle.replace(pattern, `versionCode ${versionCode}`);\n}\n"],"mappings":";;;;;;;;;;;AAGA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEO,MAAMA,WAAyB,GAAIC,MAAM,IAAK;EACnD,OAAO,IAAAC,oCAAkB,EAACD,MAAM,EAAGA,MAAM,IAAK;IAC5C,IAAIA,MAAM,CAACE,UAAU,CAACC,QAAQ,KAAK,QAAQ,EAAE;MAC3CH,MAAM,CAACE,UAAU,CAACE,QAAQ,GAAGC,cAAc,CAACL,MAAM,EAAEA,MAAM,CAACE,UAAU,CAACE,QAAQ,CAAC;MAC/EJ,MAAM,CAACE,UAAU,CAACE,QAAQ,GAAGE,cAAc,CAACN,MAAM,EAAEA,MAAM,CAACE,UAAU,CAACE,QAAQ,CAAC;IACjF,CAAC,MAAM;MACL,IAAAG,6BAAiB,EACf,qBAAqB,EACpB,oEAAmE,CACrE;IACH;IACA,OAAOP,MAAM;EACf,CAA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