diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 824daf4c9..f1bfffd34 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -291,43 +291,53 @@ async function createFromTemplate({ if (process.platform === 'darwin') { const installPodsValue = String(installCocoaPods); - if (installPodsValue === 'true') { - didInstallPods = true; - await installPods(loader); - loader.succeed(); - setEmptyHashForCachedDependencies(projectName); - } else if (installPodsValue === 'undefined') { - const {installCocoapods} = await prompt({ - type: 'confirm', - name: 'installCocoapods', - message: `Do you want to install CocoaPods now? ${chalk.reset.dim( - 'Only needed if you run your project in Xcode directly', - )}`, - }); - didInstallPods = installCocoapods; - - if (installCocoapods) { + try { + if (installPodsValue === 'true') { + didInstallPods = true; await installPods(loader); loader.succeed(); setEmptyHashForCachedDependencies(projectName); + } else if (installPodsValue === 'undefined') { + const {installCocoapods} = await prompt({ + type: 'confirm', + name: 'installCocoapods', + message: `Do you want to install CocoaPods now? ${chalk.reset.dim( + 'Only needed if you run your project in Xcode directly', + )}`, + }); + didInstallPods = installCocoapods; + + if (installCocoapods) { + await installPods(loader); + loader.succeed(); + setEmptyHashForCachedDependencies(projectName); + } } + } catch (error) { + logger.error( + `Installing Cocoapods failed. This doesn't affect project initialization and you can safely proceed. However, you will need to install Cocoapods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n\nError: ${ + (error as Error).message as string + }\n`, + ); } } } else { didInstallPods = false; loader.succeed('Dependencies installation skipped'); } + + fs.removeSync(templateSourceDir); } catch (e) { - loader.fail(); - if (e instanceof Error) { - logger.error( - 'Installing pods failed. This doesn\'t affect project initialization and you can safely proceed. \nHowever, you will need to install pods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n', - ); - logger.debug(e as any); + logger.log('\n'); + if (e instanceof CLIError) { + logger.error(e.message); + } else if (e instanceof Error) { + logger.error(`An unexpected error occurred: ${e.message}.`); } didInstallPods = false; - } finally { + logger.debug(e as any); fs.removeSync(templateSourceDir); + process.exit(1); } if (process.platform === 'darwin') {