-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doctor: improve
ios-deploy
installation (#726)
* Separate CocoaPods installation functions to be reused * Improve the UI of CocoaPods installation on `doctor` * Calculate the size of the cocoapods prompt question to remove it correctly * Refactor install method declaration when installing cocoapods * Use callbacks to clean `brewInstall` function * Clean up question size calculation on cocoapods * Move message removal functions to `common` in `doctor` * Add prompt message to show options for method of installation for `ios-deploy` * Fix unknown export * Minor refactor on `ora` type import * Remove unneeded `.toLowerCase()` * Remove unused `try...catch` block * Minor refactor * Log error message when installing `cocoapods` & `ios-deploy` * Revert `ios-deploy` installation command
- Loading branch information
Showing
5 changed files
with
115 additions
and
55 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
113 changes: 87 additions & 26 deletions
113
packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts
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 |
---|---|---|
@@ -1,58 +1,119 @@ | ||
import execa from 'execa'; | ||
import chalk from 'chalk'; | ||
// @ts-ignore untyped | ||
import inquirer from 'inquirer'; | ||
import {logger} from '@react-native-community/cli-tools'; | ||
import {checkSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; | ||
import {packageManager} from './packageManagers'; | ||
import {logManualInstallation} from './common'; | ||
import {logManualInstallation, removeMessage} from './common'; | ||
import {HealthCheckInterface} from '../types'; | ||
import {Ora} from 'ora'; | ||
|
||
const getInstallationCommand = () => { | ||
const label = 'ios-deploy'; | ||
|
||
const installationWithYarn = 'yarn global add ios-deploy'; | ||
const installationWithNpm = 'npm install ios-deploy --global'; | ||
|
||
const identifyInstallationCommand = () => { | ||
if (packageManager === PACKAGE_MANAGERS.YARN) { | ||
return 'yarn global add ios-deploy'; | ||
return installationWithYarn; | ||
} | ||
|
||
if (packageManager === PACKAGE_MANAGERS.NPM) { | ||
return 'npm install ios-deploy --global'; | ||
return installationWithNpm; | ||
} | ||
|
||
return undefined; | ||
}; | ||
|
||
const installLibrary = async ({ | ||
installationCommand, | ||
packageManagerToUse, | ||
loader, | ||
}: { | ||
installationCommand: string; | ||
packageManagerToUse: 'yarn' | 'npm'; | ||
loader: Ora; | ||
}) => { | ||
try { | ||
loader.start(`${label} (installing with ${packageManagerToUse})`); | ||
|
||
const installationCommandArgs = installationCommand.split(' '); | ||
|
||
await execa(installationCommandArgs[0], installationCommandArgs.splice(1)); | ||
|
||
loader.succeed(`${label} (installed with ${packageManagerToUse})`); | ||
} catch (error) { | ||
loader.fail(); | ||
logger.log(chalk.dim(`\n${error.message}`)); | ||
|
||
logManualInstallation({ | ||
healthcheck: 'ios-deploy', | ||
command: installationCommand, | ||
}); | ||
} | ||
}; | ||
|
||
export default { | ||
label: 'ios-deploy', | ||
label, | ||
isRequired: false, | ||
getDiagnostics: async () => ({ | ||
needsToBeFixed: await checkSoftwareInstalled('ios-deploy'), | ||
}), | ||
runAutomaticFix: async ({loader}) => { | ||
const installationCommand = getInstallationCommand(); | ||
loader.stop(); | ||
|
||
const installationCommand = identifyInstallationCommand(); | ||
|
||
// This means that we couldn't "guess" the package manager | ||
if (installationCommand === undefined) { | ||
loader.fail(); | ||
const promptQuestion = `ios-deploy needs to be installed either by ${chalk.bold( | ||
'yarn', | ||
)} ${chalk.reset('or')} ${chalk.bold( | ||
'npm', | ||
)} ${chalk.reset()}, which one do you want to use?`; | ||
const installWithYarn = 'yarn'; | ||
const installWithNpm = 'npm'; | ||
const skipInstallation = 'Skip installation'; | ||
|
||
// Then we just print out the URL that the user can head to download the library | ||
logManualInstallation({ | ||
healthcheck: 'ios-deploy', | ||
url: 'https://github.com/ios-control/ios-deploy#readme', | ||
}); | ||
return; | ||
} | ||
const {chosenPackageManager} = await inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'chosenPackageManager', | ||
message: promptQuestion, | ||
choices: [installWithYarn, installWithNpm, skipInstallation], | ||
}, | ||
]); | ||
|
||
try { | ||
const installationCommandArgs = installationCommand.split(' '); | ||
removeMessage(`? ${promptQuestion} ${chosenPackageManager}`); | ||
|
||
await execa( | ||
installationCommandArgs[0], | ||
installationCommandArgs.splice(1), | ||
); | ||
if (chosenPackageManager === skipInstallation) { | ||
loader.fail(); | ||
|
||
loader.succeed(); | ||
} catch (_error) { | ||
loader.fail(); | ||
// Then we just print out the URL that the user can head to download the library | ||
logManualInstallation({ | ||
healthcheck: 'ios-deploy', | ||
url: 'https://github.com/ios-control/ios-deploy#readme', | ||
}); | ||
|
||
logManualInstallation({ | ||
healthcheck: 'ios-deploy', | ||
command: installationCommand, | ||
return; | ||
} | ||
|
||
const shouldInstallWithYarn = chosenPackageManager === installWithYarn; | ||
|
||
return installLibrary({ | ||
installationCommand: shouldInstallWithYarn | ||
? installationWithYarn | ||
: installationWithNpm, | ||
loader, | ||
packageManagerToUse: chosenPackageManager, | ||
}); | ||
} | ||
|
||
return installLibrary({ | ||
installationCommand, | ||
packageManagerToUse: packageManager!.toLowerCase() as 'yarn' | 'npm', | ||
loader, | ||
}); | ||
}, | ||
} as HealthCheckInterface; |
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