-
Notifications
You must be signed in to change notification settings - Fork 931
doctor: improve CocoaPods installation #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
54a334f
Separate CocoaPods installation functions to be reused
79e7ad3
Improve the UI of CocoaPods installation on `doctor`
c029636
Calculate the size of the cocoapods prompt question to remove it corr…
8beab8c
Update with `master`
3d543f9
Merge branch 'master' of https://github.com/react-native-community/cl…
0d3943b
Refactor install method declaration when installing cocoapods
1354e65
Use callbacks to clean `brewInstall` function
ba4f75c
Clean up question size calculation on cocoapods
5d914c9
Remove unneeded `.toLowerCase()`
6028441
Remove unused `try...catch` block
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 83 additions & 2 deletions
85
packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,92 @@ | ||
| import execa from 'execa'; | ||
| import chalk from 'chalk'; | ||
| import readline from 'readline'; | ||
| import wcwidth from 'wcwidth'; | ||
| import {logger} from '@react-native-community/cli-tools'; | ||
| import {checkSoftwareInstalled} from '../checkInstallation'; | ||
| import {installCocoaPods} from '../../../tools/installPods'; | ||
| import { | ||
| promptCocoaPodsInstallationQuestion, | ||
| runSudo, | ||
| } from '../../../tools/installPods'; | ||
| import {brewInstall} from '../../../tools/brewInstall'; | ||
| import {HealthCheckInterface} from '../types'; | ||
|
|
||
| function calculateQuestionSize(promptQuestion: string) { | ||
| return Math.max( | ||
| 1, | ||
| Math.ceil(wcwidth(promptQuestion) / (process.stdout.columns || 80)), | ||
| ); | ||
| } | ||
|
|
||
| function clearQuestion(promptQuestion: string) { | ||
| readline.moveCursor( | ||
| process.stdout, | ||
| 0, | ||
| -calculateQuestionSize(promptQuestion), | ||
| ); | ||
| readline.clearScreenDown(process.stdout); | ||
| } | ||
|
|
||
| export default { | ||
| label: 'CocoaPods', | ||
| getDiagnostics: async () => ({ | ||
| needsToBeFixed: await checkSoftwareInstalled('pod'), | ||
| }), | ||
| runAutomaticFix: async ({loader}) => await installCocoaPods(loader), | ||
| runAutomaticFix: async ({loader}) => { | ||
| loader.stop(); | ||
|
|
||
| const { | ||
| installMethod, | ||
| promptQuestion, | ||
| } = await promptCocoaPodsInstallationQuestion(); | ||
|
|
||
| // Capitalise `Homebrew` when printing on the screen | ||
| const installMethodCapitalized = | ||
| installMethod === 'homebrew' | ||
| ? installMethod.substr(0, 1).toUpperCase() + installMethod.substr(1) | ||
| : installMethod; | ||
| const loaderInstallationMessage = `CocoaPods (installing with ${installMethodCapitalized})`; | ||
| const loaderSucceedMessage = `CocoaPods (installed with ${installMethodCapitalized})`; | ||
|
|
||
| // Remove the prompt after the question of how to install CocoaPods is answered | ||
| clearQuestion(promptQuestion); | ||
|
|
||
| if (installMethod === 'gem') { | ||
| loader.start(loaderInstallationMessage); | ||
|
|
||
| const options = ['install', 'cocoapods', '--no-document']; | ||
|
|
||
| try { | ||
| // First attempt to install `cocoapods` | ||
| await execa('gem', options); | ||
|
|
||
| return loader.succeed(loaderSucceedMessage); | ||
| } catch (_error) { | ||
| // If that doesn't work then try with sudo | ||
| try { | ||
| await runSudo(`gem ${options.join(' ')}`); | ||
|
|
||
| return loader.succeed(loaderSucceedMessage); | ||
| } catch (error) { | ||
| loader.fail(); | ||
| logger.log(chalk.dim(`\n${error}`)); | ||
|
|
||
| return logger.log( | ||
| `An error occured while trying to install CocoaPods. Please try again manually: ${chalk.bold( | ||
| 'sudo gem install cocoapods', | ||
| )}`, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (installMethod === 'homebrew') { | ||
| return await brewInstall({ | ||
| pkg: 'cocoapods', | ||
| label: loaderInstallationMessage, | ||
| loader, | ||
| onSuccess: () => loader.succeed(loaderSucceedMessage), | ||
| }); | ||
| } | ||
| }, | ||
| } as HealthCheckInterface; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.