Skip to content

fix: run pod repo update after installing CocoaPods #513

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 6 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
60 changes: 46 additions & 14 deletions packages/cli/src/tools/installPods.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import inquirer from 'inquirer';
import commandExists from 'command-exists';
import {logger} from '@react-native-community/cli-tools';

const COCOAPODS_INSTALLATION_TIMEOUT = 30000;

async function installPods({
projectName,
loader,
Expand All @@ -33,7 +31,7 @@ async function installPods({
await commandExists('pod');
} catch (e) {
if (loader) {
loader.stop();
loader.info();
}

const {shouldInstallCocoaPods} = await inquirer.prompt([
Expand All @@ -49,12 +47,14 @@ 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,
);
if (loader) {
loader.start(
`Installing CocoaPods ${chalk.dim(
'(this make take a few minutes)',
)}`,
);
}

try {
// First attempt to install `cocoapods`
await execa('gem', ['install', 'cocoapods']);
Expand All @@ -63,6 +63,9 @@ async function installPods({
// If that doesn't work then try with sudo
await execa('sudo', ['gem', 'install', 'cocoapods']);
} catch (error) {
if (loader) {
loader.fail();
}
logger.log(error.stderr);

throw new Error(
Expand All @@ -72,18 +75,47 @@ async function installPods({
);
}
} finally {
clearTimeout(cocoaPodsInstallationTimeMessage);
if (loader) {
loader.succeed();
}
}

// 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 {
if (loader) {
loader.start('Updating CocoaPods repositories');
}

await execa('pod', ['repo', 'update']);
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log(error.stderr || error.stdout);

if (loader) {
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/',
)}`,
);
} finally {
if (loader) {
loader.succeed();
}
}
}
}

try {
if (loader) {
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)
Expand Down