Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@react-native-community/cli-platform-ios": "^2.2.0",
"@react-native-community/cli-tools": "^2.0.2",
"chalk": "^1.1.1",
"command-exists": "^1.2.8",
"commander": "^2.19.0",
"compression": "^1.7.1",
"connect": "^3.6.5",
Expand Down
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
62 changes: 41 additions & 21 deletions packages/cli/src/tools/installPods.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ 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';

const COCOAPODS_INSTALLATION_TIMEOUT = 30000;
import {NoopLoader} from './loader';

async function installPods({
projectName,
Expand All @@ -16,6 +14,7 @@ async function installPods({
projectName: string,
loader?: typeof Ora,
}) {
loader = loader || new NoopLoader();
try {
if (!fs.existsSync('ios')) {
return;
Expand All @@ -30,11 +29,12 @@ async function installPods({
}

try {
await commandExists('pod');
// Check if "pod" is available and usable. It happens that there are
// multiple versions of "pod" command and even though it's there, it exits
// with a failure
await execa('pod', ['--version']);
} catch (e) {
if (loader) {
loader.stop();
}
loader.info();

const {shouldInstallCocoaPods} = await inquirer.prompt([
{
Expand All @@ -49,20 +49,23 @@ 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,
);
loader.start('Installing CocoaPods');

try {
// First attempt to install `cocoapods`
await execa('gem', ['install', 'cocoapods']);
await execa('gem', ['install', 'cocoapods', '--no-document']);
loader.succeed();
} catch (_error) {
try {
// If that doesn't work then try with sudo
await execa('sudo', ['gem', 'install', 'cocoapods']);
await execa('sudo', [
'gem',
'install',
'cocoapods',
'--no-document',
]);
} catch (error) {
loader.fail();
logger.log(error.stderr);

throw new Error(
Expand All @@ -71,19 +74,36 @@ async function installPods({
)}`,
);
}
} finally {
clearTimeout(cocoaPodsInstallationTimeMessage);
}

// 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 {
loader.start(
`Updating CocoaPods repositories ${chalk.dim(
'(this make take a few minutes)',
)}`,
);
await execa('pod', ['repo', 'update']);
} catch (error) {
// "pod" command outputs errors to stdout (at least some of them)
logger.log(error.stderr || error.stdout);
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/',
)}`,
);
}
}
}

try {
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
11 changes: 6 additions & 5 deletions packages/cli/src/tools/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import Ora from 'ora';
import logger from './logger';

class OraMock {
class OraNoop {
succeed() {}
fail() {}
start() {}
start(message?: string) {}
info(message?: string) {}
}

function getLoader(): typeof Ora {
return logger.isVerbose() ? OraMock : Ora;
export function getLoader(): typeof Ora {
return logger.isVerbose() ? OraNoop : Ora;
}

export {getLoader};
export const NoopLoader = OraNoop;
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2948,11 +2948,6 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"

command-exists@^1.2.8:
version "1.2.8"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==

commander@^2.19.0, commander@~2.19.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
Expand Down