-
Notifications
You must be signed in to change notification settings - Fork 932
feat: automatically run pod install when running init command
#373
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
thymikee
merged 20 commits into
react-native-community:master
from
lucasbento:feat/automatically-run-pod-install
May 12, 2019
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9a65bce
Specify `.xcworkspace` on run instructions instead of `.xcodeproj`
21ffb3f
Add `command-exists` package
dc72c00
Remove unneeded space after log message
9b9e659
Run `pod install` and check for cocoa pods when running `init` command
2c9b8ba
Put pods installation directly on `init` file and verify if `Podfile`…
33d4d76
Revert change to space
a539f7a
Remove unneeded `console.log`
20e2922
`cd` back to the directory after pod installation
7d52e53
Throw with `CLIError` instead of `Error`
df35444
Remove unneeded `try…catch`
5b06aaa
Fix wrong uppercased word
d424c8d
Try to install `cocoapods` without sudo before trying with it
e7342d6
Run pods installation only on macOS
db8e0bb
Check which extension for the project to print out on the run instruc…
e2a1490
Update with `master`
3785aea
Use `fs` instead of `fs-extra`
a590772
Move `installPods` to separate file
39f76f9
Add missing `logger` import
8be9c93
Fix warnings on duplicated variable declaration
c5e5dae
fixups
thymikee 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
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // @flow | ||
| import fs from 'fs-extra'; | ||
| 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'; | ||
|
|
||
| async function installPods({ | ||
| projectName, | ||
| loader, | ||
| }: { | ||
| projectName: string, | ||
| loader: typeof Ora, | ||
| }) { | ||
| try { | ||
| process.chdir('ios'); | ||
|
|
||
| const hasPods = await fs.pathExists('Podfile'); | ||
|
|
||
| if (!hasPods) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await commandExists('pod'); | ||
| } catch (e) { | ||
| loader.stop(); | ||
|
|
||
| const {shouldInstallCocoaPods} = await inquirer.prompt([ | ||
| { | ||
| type: 'confirm', | ||
| name: 'shouldInstallCocoaPods', | ||
| message: 'CocoaPods is not installed, do you want to install it?', | ||
| }, | ||
| ]); | ||
|
|
||
| if (shouldInstallCocoaPods) { | ||
| try { | ||
| // First attempt to install `cocoapods` | ||
| await execa('gem', ['install', 'cocoapods']); | ||
| } catch (_error) { | ||
| try { | ||
| // If that doesn't work then try with sudo | ||
| await execa('sudo', ['gem', 'install', 'cocoapods']); | ||
| } catch (error) { | ||
| logger.log(error.stderr); | ||
|
|
||
| throw new Error( | ||
| `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( | ||
| 'https://cocoapods.org/', | ||
| )}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // This only shows when `CocoaPods` is automatically installed, | ||
| // if it's already installed then we just show the `Installing dependencies` step | ||
| loader.start('Installing CocoaPods dependencies'); | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| await execa('pod', ['install']); | ||
| } catch (error) { | ||
| // "pod" command outputs errors to stdout (at least some of them) | ||
| logger.log(error.stderr || error.stdout); | ||
|
|
||
| throw new Error( | ||
| `Failed to install CocoaPods dependencies for iOS project, which is required by this template.\nPlease try again manually: "cd ./${projectName}/ios && pod install".\nCocoaPods documentation: ${chalk.dim.underline( | ||
| 'https://cocoapods.org/', | ||
| )}`, | ||
| ); | ||
| } | ||
| } catch (error) { | ||
| throw error; | ||
| } finally { | ||
| process.chdir('..'); | ||
| } | ||
| } | ||
|
|
||
| export default installPods; |
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.