diff --git a/packages/cli/package.json b/packages/cli/package.json index 27775be15..7f4689f80 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -66,6 +66,7 @@ "react-native": "^0.60.0" }, "devDependencies": { + "@types/command-exists": "^1.2.0", "@types/graceful-fs": "^4.1.3", "@types/semver": "^6.0.2", "slash": "^3.0.0", diff --git a/packages/cli/src/commands/doctor/checkInstallation.js b/packages/cli/src/commands/doctor/checkInstallation.ts similarity index 62% rename from packages/cli/src/commands/doctor/checkInstallation.js rename to packages/cli/src/commands/doctor/checkInstallation.ts index 03e329dc5..cbcd83866 100644 --- a/packages/cli/src/commands/doctor/checkInstallation.js +++ b/packages/cli/src/commands/doctor/checkInstallation.ts @@ -1,4 +1,3 @@ -// @flow import semver from 'semver'; import commandExists from 'command-exists'; @@ -21,11 +20,16 @@ const doesSoftwareNeedToBeFixed = ({ version, versionRange, }: { - version: string, - versionRange: string, -}) => - (version === 'Not Found' || - !semver.satisfies(semver.coerce(version), versionRange)) && - `version ${versionRange} is required`; + version: string; + versionRange: string; +}) => { + const coercedVersion = semver.coerce(version); + return ( + (version === 'Not Found' || + coercedVersion === null || + !semver.satisfies(coercedVersion, versionRange)) && + `version ${versionRange} is required` + ); +}; export {PACKAGE_MANAGERS, checkSoftwareInstalled, doesSoftwareNeedToBeFixed}; diff --git a/packages/cli/src/commands/doctor/doctor.js b/packages/cli/src/commands/doctor/doctor.js index b8a56bcd7..f310f8cac 100644 --- a/packages/cli/src/commands/doctor/doctor.js +++ b/packages/cli/src/commands/doctor/doctor.js @@ -5,6 +5,7 @@ import {logger} from '@react-native-community/cli-tools'; import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks'; // $FlowFixMe - converted to TS import {getLoader} from '../../tools/loader'; +// $FlowFixMe - converted to TS import printFixOptions, {KEYS} from './printFixOptions'; import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from './runAutomaticFix'; import type {ConfigT} from 'types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js index d3422d864..2135ced6b 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidHomeEnvVariable.js @@ -1,6 +1,7 @@ // @flow import chalk from 'chalk'; import Ora from 'ora'; +// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; import type {HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidNDK.js b/packages/cli/src/commands/doctor/healthchecks/androidNDK.js index d3481e1fe..3550d1aa3 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidNDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidNDK.js @@ -1,8 +1,11 @@ // @flow import chalk from 'chalk'; import Ora from 'ora'; +// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; +// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; +// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import type {EnvironmentInfo, HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js b/packages/cli/src/commands/doctor/healthchecks/androidSDK.js index e3a464c60..947b3c9c9 100644 --- a/packages/cli/src/commands/doctor/healthchecks/androidSDK.js +++ b/packages/cli/src/commands/doctor/healthchecks/androidSDK.js @@ -1,8 +1,11 @@ // @flow import chalk from 'chalk'; import Ora from 'ora'; +// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; +// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; +// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; import execa from 'execa'; import type {EnvironmentInfo, HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js index 77b8ceadb..92874f0c1 100644 --- a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js +++ b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js @@ -1,4 +1,5 @@ // @flow +// $FlowFixMe - converted to TS import {checkSoftwareInstalled} from '../checkInstallation'; // $FlowFixMe - converted to TS import {installCocoaPods} from '../../../tools/installPods'; diff --git a/packages/cli/src/commands/doctor/healthchecks/common.js b/packages/cli/src/commands/doctor/healthchecks/common.ts similarity index 80% rename from packages/cli/src/commands/doctor/healthchecks/common.js rename to packages/cli/src/commands/doctor/healthchecks/common.ts index 11d0008c6..e90662857 100644 --- a/packages/cli/src/commands/doctor/healthchecks/common.js +++ b/packages/cli/src/commands/doctor/healthchecks/common.ts @@ -1,9 +1,8 @@ -// @flow import {logger} from '@react-native-community/cli-tools'; import chalk from 'chalk'; // Space is necessary to keep correct ordering on screen -const logMessage = message => logger.log(` ${message}`); +const logMessage = (message: string) => logger.log(` ${message}`); const logManualInstallation = ({ healthcheck = '', @@ -11,10 +10,10 @@ const logManualInstallation = ({ command, message, }: { - healthcheck?: string, - url?: string, - command?: string, - message?: string, + healthcheck?: string; + url?: string; + command?: string; + message?: string; }) => { if (message) { return logMessage(message); diff --git a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js index c5639c1b4..90498b332 100644 --- a/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js +++ b/packages/cli/src/commands/doctor/healthchecks/iosDeploy.js @@ -1,8 +1,10 @@ // @flow import execa from 'execa'; import Ora from 'ora'; +// $FlowFixMe - converted to TS import {checkSoftwareInstalled, PACKAGE_MANAGERS} from '../checkInstallation'; import {packageManager} from './packageManagers'; +// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; import type {HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js b/packages/cli/src/commands/doctor/healthchecks/nodeJS.js index a4dfdd8eb..ce0a4b91a 100644 --- a/packages/cli/src/commands/doctor/healthchecks/nodeJS.js +++ b/packages/cli/src/commands/doctor/healthchecks/nodeJS.js @@ -1,7 +1,10 @@ // @flow import Ora from 'ora'; +// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; +// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; +// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; import type {EnvironmentInfo, HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js index 0ffb26c79..f2e369b4b 100644 --- a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js +++ b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js @@ -1,10 +1,12 @@ // @flow import fs from 'fs'; import Ora from 'ora'; +// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; import { PACKAGE_MANAGERS, doesSoftwareNeedToBeFixed, + // $FlowFixMe - converted to TS } from '../checkInstallation'; // $FlowFixMe - converted to TS import {install} from '../../../tools/install'; diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.js b/packages/cli/src/commands/doctor/healthchecks/watchman.js index 2b392f9c4..4706b6746 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.js +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.js @@ -1,6 +1,8 @@ // @flow import Ora from 'ora'; +// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; +// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; // $FlowFixMe - converted to TS import {install} from '../../../tools/install'; diff --git a/packages/cli/src/commands/doctor/healthchecks/xcode.js b/packages/cli/src/commands/doctor/healthchecks/xcode.js index 74ac04a7c..dffd1e408 100644 --- a/packages/cli/src/commands/doctor/healthchecks/xcode.js +++ b/packages/cli/src/commands/doctor/healthchecks/xcode.js @@ -1,7 +1,10 @@ // @flow import Ora from 'ora'; +// $FlowFixMe - converted to TS import versionRanges from '../versionRanges'; +// $FlowFixMe - converted to TS import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; +// $FlowFixMe - converted to TS import {logManualInstallation} from './common'; import type {EnvironmentInfo, HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/printFixOptions.js b/packages/cli/src/commands/doctor/printFixOptions.ts similarity index 78% rename from packages/cli/src/commands/doctor/printFixOptions.js rename to packages/cli/src/commands/doctor/printFixOptions.ts index 9134f8c0f..7902ded79 100644 --- a/packages/cli/src/commands/doctor/printFixOptions.js +++ b/packages/cli/src/commands/doctor/printFixOptions.ts @@ -1,4 +1,3 @@ -// @flow import chalk from 'chalk'; import {logger} from '@react-native-community/cli-tools'; @@ -9,7 +8,7 @@ const KEYS = { EXIT: '\r', }; -const printOption = option => logger.log(` \u203A ${option}`); +const printOption = (option: string) => logger.log(` \u203A ${option}`); const printOptions = () => { logger.log(); logger.log(chalk.bold('Usage')); @@ -30,11 +29,12 @@ const printOptions = () => { }; export {KEYS}; -export default ({onKeyPress}: {onKeyPress: any}) => { +export default ({onKeyPress}: {onKeyPress: (...args: any[]) => void}) => { printOptions(); - // $FlowFixMe - process.stdin.setRawMode(true); + if (process.stdin.setRawMode) { + process.stdin.setRawMode(true); + } process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', onKeyPress); diff --git a/packages/cli/src/commands/doctor/types.ts b/packages/cli/src/commands/doctor/types.ts new file mode 100644 index 000000000..9c5a5e7a8 --- /dev/null +++ b/packages/cli/src/commands/doctor/types.ts @@ -0,0 +1,78 @@ +import Ora from 'ora'; + +export type EnvironmentInfo = { + System: { + OS: string; + CPU: string; + Memory: string; + Shell: { + version: string; + path: string; + }; + }; + Binaries: { + Node: { + version: string; + path: string; + }; + Yarn: { + version: string; + path: string; + }; + npm: { + version: string; + path: string; + }; + Watchman: { + version: string; + path: string; + }; + }; + SDKs: { + 'iOS SDK': { + Platforms: string[]; + }; + 'Android SDK': { + 'API Levels': string[]; + 'Build Tools': string[]; + 'System Images': string[]; + 'Android NDK': string; + }; + }; + IDEs: { + 'Android Studio': string; + Emacs: { + version: string; + path: string; + }; + Nano: { + version: string; + path: string; + }; + VSCode: { + version: string; + path: string; + }; + Vim: { + version: string; + path: string; + }; + Xcode: { + version: string; + path: string; + }; + }; +}; + +export type HealthCheckInterface = { + label: string; + visible?: boolean | void; + isRequired?: boolean; + getDiagnostics: ( + environmentInfo: EnvironmentInfo, + ) => Promise<{version?: string; needsToBeFixed: boolean | string}>; + runAutomaticFix: (args: { + loader: typeof Ora; + environmentInfo: EnvironmentInfo; + }) => Promise | void; +}; diff --git a/packages/cli/src/commands/doctor/versionRanges.js b/packages/cli/src/commands/doctor/versionRanges.ts similarity index 95% rename from packages/cli/src/commands/doctor/versionRanges.js rename to packages/cli/src/commands/doctor/versionRanges.ts index d1909f150..d67496bd6 100644 --- a/packages/cli/src/commands/doctor/versionRanges.js +++ b/packages/cli/src/commands/doctor/versionRanges.ts @@ -1,4 +1,3 @@ -// @flow export default { // Common NODE_JS: '>= 8.3', diff --git a/yarn.lock b/yarn.lock index 3dc75009c..c33e45351 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2027,6 +2027,11 @@ dependencies: "@babel/types" "^7.3.0" +"@types/command-exists@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@types/command-exists/-/command-exists-1.2.0.tgz#d97e0ed10097090e4ab0367ed425b0312fad86f3" + integrity sha512-ugsxEJfsCuqMLSuCD4PIJkp5Uk2z6TCMRCgYVuhRo5cYQY3+1xXTQkSlPtkpGHuvWMjS2KTeVQXxkXRACMbM6A== + "@types/events@*": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"