{"version":3,"names":["runPodInstall","loader","directory","shouldHandleRepoUpdate","start","chalk","dim","execa","error","stderr","stdout","includes","runPodUpdate","fail","logger","CLIError","link","docs","log","underline","runSudo","command","Promise","resolve","reject","sudo","exec","name","installCocoaPodsWithGem","options","_error","join","installCocoaPods","stop","succeed","installPods","NoopLoader","fs","existsSync","process","chdir","hasPods","runBundleInstall","e","info"],"sources":["../../src/tools/installPods.ts"],"sourcesContent":["import fs from 'fs';\nimport execa from 'execa';\nimport chalk from 'chalk';\nimport {\n logger,\n NoopLoader,\n link,\n CLIError,\n} from '@react-native-community/cli-tools';\nimport sudo from 'sudo-prompt';\nimport runBundleInstall from './runBundleInstall';\nimport {Loader} from '../types';\n\nasync function runPodInstall(\n loader: Loader,\n directory: string,\n shouldHandleRepoUpdate: boolean = true,\n) {\n try {\n loader.start(\n `Installing CocoaPods dependencies ${chalk.dim(\n '(this may take a few minutes)',\n )}`,\n );\n\n await execa('bundle', ['exec', 'pod', 'install']);\n } catch (error) {\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, directory, false);\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 )} and follow the React Native CLI QuickStart guide for macOS and iOS.`,\n );\n }\n }\n}\n\nasync function runPodUpdate(loader: Loader) {\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\nfunction runSudo(command: string): Promise {\n return new Promise((resolve, reject) => {\n sudo.exec(command, {name: 'React Native CLI'}, (error) => {\n if (error) {\n reject(error);\n }\n\n resolve();\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: Loader) {\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({\n directory,\n loader,\n}: {\n directory: string;\n loader?: Loader;\n}) {\n loader = loader || new NoopLoader();\n try {\n if (!fs.existsSync('ios')) {\n return;\n }\n\n process.chdir('ios');\n\n const hasPods = fs.existsSync('Podfile');\n\n if (!hasPods) {\n return;\n }\n\n if (fs.existsSync('../Gemfile')) {\n await runBundleInstall(loader);\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, directory);\n } finally {\n process.chdir('..');\n }\n}\n\nexport {runSudo, installCocoaPods};\n\nexport default installPods;\n"],"mappings":";;;;;;;;AAAA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAAA;EAAA;IAAA;EAAA;EAAA;AAAA;AACA;EAA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