diff --git a/packages/cli/package.json b/packages/cli/package.json index d33618da4..563ec7596 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -28,7 +28,6 @@ "@react-native-community/cli-platform-ios": "^2.2.0", "@react-native-community/cli-tools": "^2.0.2", "chalk": "^1.1.1", - "command-exists": "^1.2.8", "commander": "^2.19.0", "compression": "^1.7.1", "connect": "^3.6.5", diff --git a/packages/cli/src/commands/init/init.js b/packages/cli/src/commands/init/init.js index b55557fe8..35099c883 100644 --- a/packages/cli/src/commands/init/init.js +++ b/packages/cli/src/commands/init/init.js @@ -154,7 +154,7 @@ async function installDependencies({ npm?: boolean, loader: typeof Ora, }) { - loader.start('Installing all required dependencies'); + loader.start('Installing dependencies'); await PackageManager.installAll({ preferYarn: !npm, diff --git a/packages/cli/src/tools/installPods.js b/packages/cli/src/tools/installPods.js index 44947238a..04d6e9e5a 100644 --- a/packages/cli/src/tools/installPods.js +++ b/packages/cli/src/tools/installPods.js @@ -4,10 +4,8 @@ import execa from 'execa'; import chalk from 'chalk'; import Ora from 'ora'; import inquirer from 'inquirer'; -import commandExists from 'command-exists'; import {logger} from '@react-native-community/cli-tools'; - -const COCOAPODS_INSTALLATION_TIMEOUT = 30000; +import {NoopLoader} from './loader'; async function installPods({ projectName, @@ -16,6 +14,7 @@ async function installPods({ projectName: string, loader?: typeof Ora, }) { + loader = loader || new NoopLoader(); try { if (!fs.existsSync('ios')) { return; @@ -30,11 +29,12 @@ async function installPods({ } try { - await commandExists('pod'); + // Check if "pod" is available and usable. It happens that there are + // multiple versions of "pod" command and even though it's there, it exits + // with a failure + await execa('pod', ['--version']); } catch (e) { - if (loader) { - loader.stop(); - } + loader.info(); const {shouldInstallCocoaPods} = await inquirer.prompt([ { @@ -49,20 +49,23 @@ async function installPods({ ]); if (shouldInstallCocoaPods) { - // Show a helpful notice when installation takes more than usually - const cocoaPodsInstallationTimeMessage = setTimeout( - () => - logger.info('Installing CocoaPods, this may take a few minutes'), - COCOAPODS_INSTALLATION_TIMEOUT, - ); + loader.start('Installing CocoaPods'); + try { // First attempt to install `cocoapods` - await execa('gem', ['install', 'cocoapods']); + await execa('gem', ['install', 'cocoapods', '--no-document']); + loader.succeed(); } catch (_error) { try { // If that doesn't work then try with sudo - await execa('sudo', ['gem', 'install', 'cocoapods']); + await execa('sudo', [ + 'gem', + 'install', + 'cocoapods', + '--no-document', + ]); } catch (error) { + loader.fail(); logger.log(error.stderr); throw new Error( @@ -71,19 +74,36 @@ async function installPods({ )}`, ); } - } finally { - clearTimeout(cocoaPodsInstallationTimeMessage); } - // This only shows when `CocoaPods` is automatically installed, - // if it's already installed then we just show the `Installing dependencies` step - if (loader) { - loader.start('Installing CocoaPods dependencies'); + try { + loader.start( + `Updating CocoaPods repositories ${chalk.dim( + '(this make take a few minutes)', + )}`, + ); + await execa('pod', ['repo', 'update']); + } catch (error) { + // "pod" command outputs errors to stdout (at least some of them) + logger.log(error.stderr || error.stdout); + loader.fail(); + + throw new Error( + `Failed to update CocoaPods repositories for iOS project.\nPlease try again manually: "pod repo update".\nCocoaPods documentation: ${chalk.dim.underline( + 'https://cocoapods.org/', + )}`, + ); } } } try { + loader.succeed(); + loader.start( + `Installing CocoaPods dependencies ${chalk.dim( + '(this make take a few minutes)', + )}`, + ); await execa('pod', ['install']); } catch (error) { // "pod" command outputs errors to stdout (at least some of them) diff --git a/packages/cli/src/tools/loader.js b/packages/cli/src/tools/loader.js index 525cc5c9d..b0c480975 100644 --- a/packages/cli/src/tools/loader.js +++ b/packages/cli/src/tools/loader.js @@ -2,14 +2,15 @@ import Ora from 'ora'; import logger from './logger'; -class OraMock { +class OraNoop { succeed() {} fail() {} - start() {} + start(message?: string) {} + info(message?: string) {} } -function getLoader(): typeof Ora { - return logger.isVerbose() ? OraMock : Ora; +export function getLoader(): typeof Ora { + return logger.isVerbose() ? OraNoop : Ora; } -export {getLoader}; +export const NoopLoader = OraNoop; diff --git a/yarn.lock b/yarn.lock index b6ccd26b8..a7f24014f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2948,11 +2948,6 @@ combined-stream@^1.0.6, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" -command-exists@^1.2.8: - version "1.2.8" - resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291" - integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw== - commander@^2.19.0, commander@~2.19.0: version "2.19.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"