Skip to content
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

chore: use Homebrew for installing ios-deploy #2013

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
127 changes: 19 additions & 108 deletions packages/cli-doctor/src/tools/healthchecks/iosDeploy.ts
Original file line number Diff line number Diff line change
@@ -1,124 +1,35 @@
import execa from 'execa';
import {isSoftwareNotInstalled} from '../checkInstallation';
import {HealthCheckInterface} from '../../types';
import {brewInstall} from '../brewInstall';
import chalk from 'chalk';
import prompts from 'prompts';
import {isSoftwareNotInstalled, PACKAGE_MANAGERS} from '../checkInstallation';
import {packageManager} from './packageManagers';
import {logError, removeMessage} from './common';
import {HealthCheckInterface, Loader} from '../../types';

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 installationWithYarn;
}

if (packageManager === PACKAGE_MANAGERS.NPM) {
return installationWithNpm;
}

return undefined;
};

const installLibrary = async ({
installationCommand,
packageManagerToUse,
loader,
}: {
installationCommand: string;
packageManagerToUse: 'yarn' | 'npm';
loader: Loader;
}) => {
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) {
logError({
healthcheck: label,
loader,
error: error as Error,
command: installationCommand,
});
}
};
const packageName = 'ios-deploy';

export default {
label,
label: packageName,
isRequired: false,
description:
'Required for installing your app on a physical device with the CLI',
getDiagnostics: async () => ({
needsToBeFixed: await isSoftwareNotInstalled('ios-deploy'),
needsToBeFixed: await isSoftwareNotInstalled(packageName),
}),
runAutomaticFix: async ({loader, logManualInstallation}) => {
loader.stop();

const installationCommand = identifyInstallationCommand();

// This means that we couldn't "guess" the package manager
if (installationCommand === undefined) {
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 = {title: 'yarn', value: 'yarn'};
const installWithNpm = {title: 'npm', value: 'npm'};
const skipInstallation = {
title: 'Skip installation',
value: 'skip',
};

const {chosenPackageManager} = await prompts([
{
type: 'select',
name: 'chosenPackageManager',
message: promptQuestion,
choices: [installWithYarn, installWithNpm, skipInstallation],
},
]);

removeMessage(`? ${promptQuestion} ${chosenPackageManager}`);

if (
chosenPackageManager === skipInstallation.value ||
!chosenPackageManager // e.g. when user presses Esc
) {
await brewInstall({
pkg: packageName,
label: packageName,
loader,
onSuccess: () => {
loader.succeed(
`Successfully installed ${chalk.bold(packageName)} with Homebrew`,
);
},
onFail: () => {
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',
healthcheck: packageName,
url: 'https://github.com/ios-control/ios-deploy#installation',
});

return;
}

const shouldInstallWithYarn =
chosenPackageManager === installWithYarn.value;

return installLibrary({
installationCommand: shouldInstallWithYarn
? installationWithYarn
: installationWithNpm,
loader,
packageManagerToUse: chosenPackageManager,
});
}

return installLibrary({
installationCommand,
packageManagerToUse: packageManager!.toLowerCase() as 'yarn' | 'npm',
loader,
},
});
},
} as HealthCheckInterface;
2 changes: 1 addition & 1 deletion packages/cli-platform-ios/src/commands/runIOS/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ async function runOnDevice(
if (isIOSDeployInstalled.error) {
throw new CLIError(
`Failed to install the app on the device because we couldn't execute the "ios-deploy" command. Please install it by running "${chalk.bold(
'npm install -g ios-deploy',
'brew install ios-deploy',
)}" and try again.`,
);
}
Expand Down