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

doctor: add health check description field #743

Merged
merged 4 commits into from
Sep 23, 2019
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
16 changes: 8 additions & 8 deletions packages/cli/src/commands/doctor/checkInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export enum PACKAGE_MANAGERS {
NPM = 'NPM',
}

const checkSoftwareInstalled = async (command: string) => {
const isSoftwareNotInstalled = async (command: string): Promise<boolean> => {
try {
await commandExists(command);

return false;
} catch (_ignored) {
return 'should be installed';
return true;
}
};

Expand All @@ -22,14 +22,14 @@ const doesSoftwareNeedToBeFixed = ({
}: {
version: string;
versionRange: string;
}) => {
}): boolean => {
const coercedVersion = semver.coerce(version);

return (
(version === 'Not Found' ||
coercedVersion === null ||
!semver.satisfies(coercedVersion, versionRange)) &&
`version ${versionRange} is required`
version === 'Not Found' ||
coercedVersion === null ||
!semver.satisfies(coercedVersion, versionRange)
);
};

export {checkSoftwareInstalled, doesSoftwareNeedToBeFixed};
export {isSoftwareNotInstalled, doesSoftwareNeedToBeFixed};
2 changes: 1 addition & 1 deletion packages/cli/src/commands/doctor/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default (async (_, __, options) => {
return {
label: healthcheck.label,
needsToBeFixed: Boolean(needsToBeFixed),
description: String(needsToBeFixed),
description: healthcheck.description,
runAutomaticFix: healthcheck.runAutomaticFix,
isRequired,
type: needsToBeFixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe('androidHomeEnvVariables', () => {
jest.resetAllMocks();
});

it('returns a message if no ANDROID_HOME is defined', async () => {
it('returns true if no ANDROID_HOME is defined', async () => {
delete process.env.ANDROID_HOME;

const environmentInfo = await getEnvironmentInfo();
const diagnostics = await androidHomeEnvVariables.getDiagnostics(
environmentInfo,
);
expect(typeof diagnostics.needsToBeFixed).toBe('string');
expect(diagnostics.needsToBeFixed).toBe(true);
});

it('returns false if ANDROID_HOME is defined', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const message = `Read more about how to set the ${label} at ${chalk.dim(
export default {
label,
getDiagnostics: async () => ({
needsToBeFixed: !process.env.ANDROID_HOME && message,
needsToBeFixed: !process.env.ANDROID_HOME,
}),
runAutomaticFix: async ({loader}: {loader: Ora}) => {
loader.info();
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/doctor/healthchecks/androidNDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {EnvironmentInfo, HealthCheckInterface} from '../types';

export default {
label: 'Android NDK',
description: 'required for building React Native from the source',
getDiagnostics: async ({SDKs}: EnvironmentInfo) => {
const androidSdk = SDKs['Android SDK'];
return {
needsToBeFixed: doesSoftwareNeedToBeFixed({
version:
androidSdk === 'Not Found' ? 'Not Found' : androidSdk['Android NDK'],
androidSdk === 'Not Found' ? androidSdk : androidSdk['Android NDK'],
versionRange: versionRanges.ANDROID_NDK,
}),
};
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/commands/doctor/healthchecks/androidSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const installMessage = `Read more about how to update Android SDK at ${chalk.dim

export default {
label: 'Android SDK',
description: 'required for building and installing your app on Android',
getDiagnostics: async ({SDKs}) => {
let sdks = SDKs['Android SDK'];

Expand Down Expand Up @@ -48,12 +49,11 @@ export default {

return {
needsToBeFixed:
(sdks === 'Not Found' && installMessage) ||
(sdks !== 'Not Found' &&
doesSoftwareNeedToBeFixed({
version: sdks['Build Tools'][0],
versionRange: versionRanges.ANDROID_SDK,
})),
sdks === 'Not Found' ||
doesSoftwareNeedToBeFixed({
version: sdks['Build Tools'][0],
versionRange: versionRanges.ANDROID_SDK,
}),
};
},
runAutomaticFix: async ({loader, environmentInfo}) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import execa from 'execa';
import chalk from 'chalk';
import {logger} from '@react-native-community/cli-tools';
import {checkSoftwareInstalled} from '../checkInstallation';
import {isSoftwareNotInstalled} from '../checkInstallation';
import {
promptCocoaPodsInstallationQuestion,
runSudo,
Expand All @@ -12,8 +12,9 @@ import {HealthCheckInterface} from '../types';

export default {
label: 'CocoaPods',
description: 'required for installing iOS dependencies',
getDiagnostics: async () => ({
needsToBeFixed: await checkSoftwareInstalled('pod'),
needsToBeFixed: await isSoftwareNotInstalled('pod'),
}),
runAutomaticFix: async ({loader}) => {
loader.stop();
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 {isSoftwareNotInstalled, PACKAGE_MANAGERS} from '../checkInstallation';
import {packageManager} from './packageManagers';
import {logManualInstallation, removeMessage} from './common';
import {HealthCheckInterface} from '../types';
Expand Down Expand Up @@ -57,8 +57,10 @@ const installLibrary = async ({
export default {
label,
isRequired: false,
description:
'required for installing your app on a physical device with the CLI',
getDiagnostics: async () => ({
needsToBeFixed: await checkSoftwareInstalled('ios-deploy'),
needsToBeFixed: await isSoftwareNotInstalled('ios-deploy'),
}),
runAutomaticFix: async ({loader}) => {
loader.stop();
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/commands/doctor/healthchecks/watchman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const label = 'Watchman';

export default {
label,
description:
'used for watching changes in the filesystem when in development mode',
getDiagnostics: async ({Binaries}) => ({
needsToBeFixed: doesSoftwareNeedToBeFixed({
version: Binaries.Watchman.version,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/doctor/healthchecks/xcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {HealthCheckInterface} from '../types';

export default {
label: 'Xcode',
description: 'required for building and installing your app on iOS',
getDiagnostics: async ({IDEs}) => ({
needsToBeFixed: doesSoftwareNeedToBeFixed({
version: IDEs.Xcode.version.split('/')[0],
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/doctor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export type HealthCheckInterface = {
label: string;
visible?: boolean | void;
isRequired?: boolean;
description?: string;
getDiagnostics: (
environmentInfo: EnvironmentInfo,
) => Promise<{version?: string; needsToBeFixed: boolean | string}>;
Expand All @@ -95,7 +96,7 @@ export type HealthCheckInterface = {
export type HealthCheckResult = {
label: string;
needsToBeFixed: boolean;
description: string;
description: string | undefined;
runAutomaticFix: RunAutomaticFix;
isRequired: boolean;
type?: string;
Expand Down