{"version":3,"names":["runPodInstall","loader","options","shouldHandleRepoUpdate","start","chalk","bold","newArchEnabled","dim","execa","env","RCT_NEW_ARCH_ENABLED","error","logger","debug","stderr","stdout","includes","runPodUpdate","fail","CLIError","link","docs","guide","log","underline","installCocoaPodsWithGem","_error","runSudo","join","installCocoaPods","stop","succeed","installPods","NoopLoader","iosFolderPath","fs","existsSync","process","chdir","hasPods","skipBundleInstall","runBundleInstall","e","info"],"sources":["../../src/tools/installPods.ts"],"sourcesContent":["import fs from 'fs';\nimport execa from 'execa';\nimport type {Ora} from 'ora';\nimport chalk from 'chalk';\nimport {\n logger,\n NoopLoader,\n link,\n CLIError,\n runSudo,\n} from '@react-native-community/cli-tools';\nimport runBundleInstall from './runBundleInstall';\n\ninterface PodInstallOptions {\n skipBundleInstall?: boolean;\n newArchEnabled?: boolean;\n iosFolderPath?: string;\n}\n\ninterface RunPodInstallOptions {\n shouldHandleRepoUpdate?: boolean;\n newArchEnabled?: boolean;\n}\n\nasync function runPodInstall(loader: Ora, options?: RunPodInstallOptions) {\n const shouldHandleRepoUpdate = options?.shouldHandleRepoUpdate || true;\n try {\n loader.start(\n `Installing CocoaPods dependencies ${chalk.bold(\n options?.newArchEnabled ? 'with New Architecture' : '',\n )} ${chalk.dim('(this may take a few minutes)')}`,\n );\n\n await execa('bundle', ['exec', 'pod', 'install'], {\n env: {\n RCT_NEW_ARCH_ENABLED: options?.newArchEnabled ? '1' : '0',\n },\n });\n } catch (error) {\n logger.debug(error as string);\n // \"pod\" command outputs errors to stdout (at least some of them)\n const stderr = (error as any).stderr || (error as any).stdout;\n\n /**\n * If CocoaPods failed due to repo being out of date, it will\n * include the update command in the error message.\n *\n * `shouldHandleRepoUpdate` will be set to `false` to\n * prevent infinite loop (unlikely scenario)\n */\n if (stderr.includes('pod repo update') && shouldHandleRepoUpdate) {\n await runPodUpdate(loader);\n await runPodInstall(loader, {\n shouldHandleRepoUpdate: false,\n newArchEnabled: options?.newArchEnabled,\n });\n } else {\n loader.fail();\n logger.error(stderr);\n\n throw new CLIError(\n `Looks like your iOS environment is not properly set. Please go to ${link.docs(\n 'environment-setup',\n 'ios',\n {guide: 'native'},\n )} and follow the React Native CLI QuickStart guide for macOS and iOS.`,\n );\n }\n }\n}\n\nasync function runPodUpdate(loader: Ora) {\n try {\n loader.start(\n `Updating CocoaPods repositories ${chalk.dim(\n '(this may take a few minutes)',\n )}`,\n );\n await execa('pod', ['repo', 'update']);\n } catch (error) {\n // \"pod\" command outputs errors to stdout (at least some of them)\n logger.log((error as any).stderr || (error as any).stdout);\n loader.fail();\n\n throw new CLIError(\n `Failed to update CocoaPods repositories for iOS project.\\nPlease try again manually: \"pod repo update\".\\nCocoaPods documentation: ${chalk.dim.underline(\n 'https://cocoapods.org/',\n )}`,\n );\n }\n}\n\nasync function installCocoaPodsWithGem() {\n const options = ['install', 'cocoapods', '--no-document'];\n\n try {\n // First attempt to install `cocoapods`\n await execa('gem', options);\n } catch (_error) {\n // If that doesn't work then try with sudo\n await runSudo(`gem ${options.join(' ')}`);\n }\n}\n\nasync function installCocoaPods(loader: Ora) {\n loader.stop();\n\n loader.start('Installing CocoaPods');\n\n try {\n await installCocoaPodsWithGem();\n\n return loader.succeed();\n } catch (error) {\n loader.fail();\n logger.error((error as any).stderr);\n\n throw new CLIError(\n `An error occured while trying to install CocoaPods, which is required by this template.\\nPlease try again manually: sudo gem install cocoapods.\\nCocoaPods documentation: ${chalk.dim.underline(\n 'https://cocoapods.org/',\n )}`,\n );\n }\n}\n\nasync function installPods(loader?: Ora, options?: PodInstallOptions) {\n loader = loader || new NoopLoader();\n try {\n if (!options?.iosFolderPath && !fs.existsSync('ios')) {\n return;\n }\n\n process.chdir(options?.iosFolderPath ?? 'ios');\n\n const hasPods = fs.existsSync('Podfile');\n\n if (!hasPods) {\n return;\n }\n\n if (fs.existsSync('../Gemfile') && !options?.skipBundleInstall) {\n await runBundleInstall(loader);\n } else if (!fs.existsSync('../Gemfile')) {\n throw new CLIError(\n 'Could not find the Gemfile. Currently the CLI requires to have this file in the root directory of the project to install CocoaPods. If your configuration is different, please install the CocoaPods manually.',\n );\n }\n\n try {\n // Check if \"pod\" is available and usable. It happens that there are\n // multiple versions of \"pod\" command and even though it's there, it exits\n // with a failure\n await execa('pod', ['--version']);\n } catch (e) {\n loader.info();\n await installCocoaPods(loader);\n }\n\n await runPodInstall(loader, {newArchEnabled: options?.newArchEnabled});\n } finally {\n process.chdir('..');\n }\n}\n\nexport {installCocoaPods};\n\nexport default installPods;\n"],"mappings":";;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAEA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AAOA;AAAkD;AAalD,eAAeA,aAAa,CAACC,MAAW,EAAEC,OAA8B,EAAE;EACxE,MAAMC,sBAAsB,GAAG,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,sBAAsB,KAAI,IAAI;EACtE,IAAI;IACFF,MAAM,CAACG,KAAK,CACT,qCAAoCC,gBAAK,CAACC,IAAI,CAC7C,CAAAJ,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,cAAc,IAAG,uBAAuB,GAAG,EAAE,CACtD,IAAGF,gBAAK,CAACG,GAAG,CAAC,+BAA+B,CAAE,EAAC,CAClD;IAED,MAAM,IAAAC,gBAAK,EAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE;MAChDC,GAAG,EAAE;QACHC,oBAAoB,EAAE,CAAAT,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,cAAc,IAAG,GAAG,GAAG;MACxD;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOK,KAAK,EAAE;IACdC,kBAAM,CAACC,KAAK,CAACF,KAAK,CAAW;IAC7B;IACA,MAAMG,MAAM,GAAIH,KAAK,CAASG,MA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