forked from react-native-community/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…act-native-community#373) * Specify `.xcworkspace` on run instructions instead of `.xcodeproj` * Add `command-exists` package * Remove unneeded space after log message * Run `pod install` and check for cocoa pods when running `init` command * Put pods installation directly on `init` file and verify if `Podfile` exists before running * Revert change to space * Remove unneeded `console.log` * `cd` back to the directory after pod installation * Throw with `CLIError` instead of `Error` * Remove unneeded `try…catch` * Fix wrong uppercased word * Try to install `cocoapods` without sudo before trying with it * Run pods installation only on macOS * Check which extension for the project to print out on the run instructions for iOS * Use `fs` instead of `fs-extra` * Move `installPods` to separate file * Add missing `logger` import * Fix warnings on duplicated variable declaration * fixups
- Loading branch information
Showing
5 changed files
with
124 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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