Skip to content

Commit

Permalink
fix: Correctly display errors in react-native init (#2394)
Browse files Browse the repository at this point in the history
* fix: Display correct error when config file does not exist

* fix: move cocoaPods Error

* fix: prettify output

* fix: pass an error

* fix: do cleanup before exiting process

---------

Co-authored-by: szymonrybczak <[email protected]>
  • Loading branch information
islandryu and szymonrybczak authored Sep 9, 2024
1 parent f9195cd commit 0e1c828
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 0e1c828

Please sign in to comment.