-
Notifications
You must be signed in to change notification settings - Fork 931
doctor: improve ios-deploy installation
#726
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
18 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
0cfd212
Move message removal functions to `common` in `doctor`
13e754c
Add prompt message to show options for method of installation for `io…
dba1672
Fix unknown export
efd8595
Minor refactor on `ora` type import
af44a4f
Remove unneeded `.toLowerCase()`
bd7da87
Remove unused `try...catch` block
904c82d
Update with `master`
e8a7340
Minor refactor
9e85885
Log error message when installing `cocoapods` & `ios-deploy`
28f1f5f
Revert `ios-deploy` installation command
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
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
113 changes: 87 additions & 26 deletions
113
packages/cli/src/commands/doctor/healthchecks/iosDeploy.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,58 +1,119 @@ | ||
| import execa from 'execa'; | ||
| import chalk from 'chalk'; | ||
| // @ts-ignore untyped | ||
| import inquirer from 'inquirer'; | ||
| import {logger} from '@react-native-community/cli-tools'; | ||
| import {checkSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; | ||
| import {packageManager} from './packageManagers'; | ||
| import {logManualInstallation} from './common'; | ||
| import {logManualInstallation, removeMessage} from './common'; | ||
| import {HealthCheckInterface} from '../types'; | ||
| import {Ora} from 'ora'; | ||
|
|
||
| const getInstallationCommand = () => { | ||
| const label = 'ios-deploy'; | ||
|
|
||
| const installationWithYarn = 'yarn global add ios-deploy'; | ||
| const installationWithNpm = 'npm install ios-deploy --global'; | ||
|
|
||
| const identifyInstallationCommand = () => { | ||
| if (packageManager === PACKAGE_MANAGERS.YARN) { | ||
| return 'yarn global add ios-deploy'; | ||
| return installationWithYarn; | ||
| } | ||
|
|
||
| if (packageManager === PACKAGE_MANAGERS.NPM) { | ||
| return 'npm install ios-deploy --global'; | ||
| return installationWithNpm; | ||
| } | ||
|
|
||
| return undefined; | ||
| }; | ||
|
|
||
| const installLibrary = async ({ | ||
| installationCommand, | ||
| packageManagerToUse, | ||
| loader, | ||
| }: { | ||
| installationCommand: string; | ||
| packageManagerToUse: 'yarn' | 'npm'; | ||
| loader: Ora; | ||
| }) => { | ||
| try { | ||
| loader.start(`${label} (installing with ${packageManagerToUse})`); | ||
|
|
||
| const installationCommandArgs = installationCommand.split(' '); | ||
|
|
||
| await execa(installationCommandArgs[0], installationCommandArgs.splice(1)); | ||
lucasbento marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| loader.succeed(`${label} (installed with ${packageManagerToUse})`); | ||
| } catch (error) { | ||
| loader.fail(); | ||
| logger.log(chalk.dim(`\n${error.message}`)); | ||
|
|
||
| logManualInstallation({ | ||
| healthcheck: 'ios-deploy', | ||
| command: installationCommand, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| export default { | ||
| label: 'ios-deploy', | ||
| label, | ||
| isRequired: false, | ||
| getDiagnostics: async () => ({ | ||
| needsToBeFixed: await checkSoftwareInstalled('ios-deploy'), | ||
| }), | ||
| runAutomaticFix: async ({loader}) => { | ||
| const installationCommand = getInstallationCommand(); | ||
| loader.stop(); | ||
|
|
||
| const installationCommand = identifyInstallationCommand(); | ||
|
|
||
| // This means that we couldn't "guess" the package manager | ||
| if (installationCommand === undefined) { | ||
| loader.fail(); | ||
| const promptQuestion = `ios-deploy needs to be installed either by ${chalk.bold( | ||
| 'yarn', | ||
| )} ${chalk.reset('or')} ${chalk.bold( | ||
| 'npm', | ||
| )} ${chalk.reset()}, which one do you want to use?`; | ||
| const installWithYarn = 'yarn'; | ||
| const installWithNpm = 'npm'; | ||
| const skipInstallation = 'Skip installation'; | ||
|
|
||
| // Then we just print out the URL that the user can head to download the library | ||
| logManualInstallation({ | ||
| healthcheck: 'ios-deploy', | ||
| url: 'https://github.com/ios-control/ios-deploy#readme', | ||
| }); | ||
| return; | ||
| } | ||
| const {chosenPackageManager} = await inquirer.prompt([ | ||
| { | ||
| type: 'list', | ||
| name: 'chosenPackageManager', | ||
| message: promptQuestion, | ||
| choices: [installWithYarn, installWithNpm, skipInstallation], | ||
| }, | ||
| ]); | ||
|
|
||
| try { | ||
| const installationCommandArgs = installationCommand.split(' '); | ||
| removeMessage(`? ${promptQuestion} ${chosenPackageManager}`); | ||
|
|
||
| await execa( | ||
| installationCommandArgs[0], | ||
| installationCommandArgs.splice(1), | ||
| ); | ||
| if (chosenPackageManager === skipInstallation) { | ||
| loader.fail(); | ||
|
|
||
| loader.succeed(); | ||
| } catch (_error) { | ||
| loader.fail(); | ||
| // Then we just print out the URL that the user can head to download the library | ||
| logManualInstallation({ | ||
| healthcheck: 'ios-deploy', | ||
| url: 'https://github.com/ios-control/ios-deploy#readme', | ||
| }); | ||
|
|
||
| logManualInstallation({ | ||
| healthcheck: 'ios-deploy', | ||
| command: installationCommand, | ||
| return; | ||
| } | ||
|
|
||
| const shouldInstallWithYarn = chosenPackageManager === installWithYarn; | ||
|
|
||
| return installLibrary({ | ||
| installationCommand: shouldInstallWithYarn | ||
| ? installationWithYarn | ||
| : installationWithNpm, | ||
| loader, | ||
| packageManagerToUse: chosenPackageManager, | ||
| }); | ||
| } | ||
|
|
||
| return installLibrary({ | ||
| installationCommand, | ||
| packageManagerToUse: packageManager!.toLowerCase() as 'yarn' | 'npm', | ||
| loader, | ||
| }); | ||
| }, | ||
| } 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
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.