From b61607644e2c9055ea8c67a653fabc552876b6c3 Mon Sep 17 00:00:00 2001 From: Lucas Bento Date: Mon, 23 Sep 2019 11:07:30 +0200 Subject: [PATCH 1/4] Add `description` field for each health check --- packages/cli/src/commands/doctor/doctor.ts | 2 +- packages/cli/src/commands/doctor/types.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/doctor/doctor.ts b/packages/cli/src/commands/doctor/doctor.ts index 8dec8f4fc..d8e818028 100644 --- a/packages/cli/src/commands/doctor/doctor.ts +++ b/packages/cli/src/commands/doctor/doctor.ts @@ -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 diff --git a/packages/cli/src/commands/doctor/types.ts b/packages/cli/src/commands/doctor/types.ts index b710eaa17..e051cc52d 100644 --- a/packages/cli/src/commands/doctor/types.ts +++ b/packages/cli/src/commands/doctor/types.ts @@ -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}>; @@ -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; From 4048b93660f31435a4ad36b61274568489f2a1d8 Mon Sep 17 00:00:00 2001 From: Lucas Bento Date: Mon, 23 Sep 2019 11:07:39 +0200 Subject: [PATCH 2/4] Add a few descriptions to health checks --- packages/cli/src/commands/doctor/healthchecks/androidNDK.ts | 1 + packages/cli/src/commands/doctor/healthchecks/androidSDK.ts | 1 + packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts | 1 + packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts | 2 ++ packages/cli/src/commands/doctor/healthchecks/watchman.ts | 2 ++ 5 files changed, 7 insertions(+) diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts index 994d2a501..d26d30259 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts @@ -7,6 +7,7 @@ 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 { diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts index 7424995dd..7b820f826 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts @@ -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']; diff --git a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts index 9d50c1f31..792b8f003 100644 --- a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts +++ b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts @@ -12,6 +12,7 @@ import {HealthCheckInterface} from '../types'; export default { label: 'CocoaPods', + description: 'required for installing iOS dependencies', getDiagnostics: async () => ({ needsToBeFixed: await checkSoftwareInstalled('pod'), }), diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts index 877fda56a..3383ce6ac 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts @@ -57,6 +57,8 @@ 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'), }), diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.ts b/packages/cli/src/commands/doctor/healthchecks/watchman.ts index c0a5f9cbf..64e898001 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.ts +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.ts @@ -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, From ec7a0a153e03db1001546c65548497d9056082cf Mon Sep 17 00:00:00 2001 From: Lucas Bento Date: Mon, 23 Sep 2019 11:22:14 +0200 Subject: [PATCH 3/4] Refactor description message being returned on `needsToBeFixed` field --- .../cli/src/commands/doctor/checkInstallation.ts | 16 ++++++++-------- .../commands/doctor/healthchecks/androidNDK.ts | 2 +- .../commands/doctor/healthchecks/androidSDK.ts | 11 +++++------ .../commands/doctor/healthchecks/cocoaPods.ts | 4 ++-- .../commands/doctor/healthchecks/iosDeploy.ts | 4 ++-- .../src/commands/doctor/healthchecks/xcode.ts | 1 + 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/cli/src/commands/doctor/checkInstallation.ts b/packages/cli/src/commands/doctor/checkInstallation.ts index bb65d0d56..e896a00cb 100644 --- a/packages/cli/src/commands/doctor/checkInstallation.ts +++ b/packages/cli/src/commands/doctor/checkInstallation.ts @@ -6,13 +6,13 @@ export enum PACKAGE_MANAGERS { NPM = 'NPM', } -const checkSoftwareInstalled = async (command: string) => { +const isSoftwareNotInstalled = async (command: string): Promise => { try { await commandExists(command); return false; } catch (_ignored) { - return 'should be installed'; + return true; } }; @@ -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}; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts index d26d30259..360ba32f4 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.ts @@ -13,7 +13,7 @@ export default { return { needsToBeFixed: doesSoftwareNeedToBeFixed({ version: - androidSdk === 'Not Found' ? 'Not Found' : androidSdk['Android NDK'], + androidSdk === 'Not Found' ? androidSdk : androidSdk['Android NDK'], versionRange: versionRanges.ANDROID_NDK, }), }; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts index 7b820f826..a53b56487 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.ts @@ -49,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}) => { diff --git a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts index 792b8f003..a797848d0 100644 --- a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts +++ b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.ts @@ -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, @@ -14,7 +14,7 @@ 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(); diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts index 3383ce6ac..f90cc2ed8 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.ts @@ -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'; @@ -60,7 +60,7 @@ export default { 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(); diff --git a/packages/cli/src/commands/doctor/healthchecks/xcode.ts b/packages/cli/src/commands/doctor/healthchecks/xcode.ts index 128632b0c..503a74490 100644 --- a/packages/cli/src/commands/doctor/healthchecks/xcode.ts +++ b/packages/cli/src/commands/doctor/healthchecks/xcode.ts @@ -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], From 48d4b9400fe83fd7aa057665bd6ede72bda62937 Mon Sep 17 00:00:00 2001 From: Lucas Bento Date: Mon, 23 Sep 2019 11:22:22 +0200 Subject: [PATCH 4/4] Update `ANDROID_HOME` tests --- .../healthchecks/__tests__/androidHomeEnvVariable.test.ts | 4 ++-- .../commands/doctor/healthchecks/androidHomeEnvVariable.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts index 37362ed54..a32bb2c42 100644 --- a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts +++ b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidHomeEnvVariable.test.ts @@ -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 () => { diff --git a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts index cbb865060..823c88e23 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts +++ b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.ts @@ -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();