From f54212152b04fab5472caf66da7921a344ddcf98 Mon Sep 17 00:00:00 2001 From: thib92 Date: Wed, 11 Sep 2019 12:49:43 +0200 Subject: [PATCH 1/5] Convert printFixOptions to TypeScript --- .../doctor/{printFixOptions.js => printFixOptions.ts} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename packages/cli/src/commands/doctor/{printFixOptions.js => printFixOptions.ts} (78%) 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); From a8acbb5dadf689565758e02b950d319e381d5dd4 Mon Sep 17 00:00:00 2001 From: thib92 Date: Wed, 11 Sep 2019 13:01:09 +0200 Subject: [PATCH 2/5] checkInstallation versionRange common to TS --- packages/cli/package.json | 1 + ...eckInstallation.js => checkInstallation.ts} | 18 +++++++++++------- .../healthchecks/{common.js => common.ts} | 11 +++++------ .../{versionRanges.js => versionRanges.ts} | 1 - yarn.lock | 5 +++++ 5 files changed, 22 insertions(+), 14 deletions(-) rename packages/cli/src/commands/doctor/{checkInstallation.js => checkInstallation.ts} (62%) rename packages/cli/src/commands/doctor/healthchecks/{common.js => common.ts} (80%) rename packages/cli/src/commands/doctor/{versionRanges.js => versionRanges.ts} (95%) 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/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/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" From 67fa443b6931b6f80146b35e2e08ffcc7bca9aa7 Mon Sep 17 00:00:00 2001 From: thib92 Date: Wed, 11 Sep 2019 13:27:40 +0200 Subject: [PATCH 3/5] Not working: move types to cli-types --- .../cli-types/src/commands/doctor/index.ts | 79 +++++++++++++++++++ packages/cli-types/src/index.ts | 2 + 2 files changed, 81 insertions(+) create mode 100644 packages/cli-types/src/commands/doctor/index.ts diff --git a/packages/cli-types/src/commands/doctor/index.ts b/packages/cli-types/src/commands/doctor/index.ts new file mode 100644 index 000000000..cae0af27c --- /dev/null +++ b/packages/cli-types/src/commands/doctor/index.ts @@ -0,0 +1,79 @@ +// @flow +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-types/src/index.ts b/packages/cli-types/src/index.ts index 15eca2521..6bce23f25 100644 --- a/packages/cli-types/src/index.ts +++ b/packages/cli-types/src/index.ts @@ -11,6 +11,8 @@ import { AndroidDependencyParams, } from './android'; +export {EnvironmentInfo, HealthCheckInterface} from './commands/doctor'; + export type InquirerPrompt = any; export interface Command { From 62a1c3ab5b0b474ef493103629a7632cc93c52c9 Mon Sep 17 00:00:00 2001 From: thib92 Date: Wed, 11 Sep 2019 23:58:56 +0200 Subject: [PATCH 4/5] Move types to cli package --- packages/cli-types/src/index.ts | 2 - packages/cli/src/commands/doctor/types.js | 79 ------------------- .../src/commands/doctor/types.ts} | 1 - 3 files changed, 82 deletions(-) delete mode 100644 packages/cli/src/commands/doctor/types.js rename packages/{cli-types/src/commands/doctor/index.ts => cli/src/commands/doctor/types.ts} (99%) diff --git a/packages/cli-types/src/index.ts b/packages/cli-types/src/index.ts index 6bce23f25..15eca2521 100644 --- a/packages/cli-types/src/index.ts +++ b/packages/cli-types/src/index.ts @@ -11,8 +11,6 @@ import { AndroidDependencyParams, } from './android'; -export {EnvironmentInfo, HealthCheckInterface} from './commands/doctor'; - export type InquirerPrompt = any; export interface Command { diff --git a/packages/cli/src/commands/doctor/types.js b/packages/cli/src/commands/doctor/types.js deleted file mode 100644 index 3793e8d9b..000000000 --- a/packages/cli/src/commands/doctor/types.js +++ /dev/null @@ -1,79 +0,0 @@ -// @flow -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-types/src/commands/doctor/index.ts b/packages/cli/src/commands/doctor/types.ts similarity index 99% rename from packages/cli-types/src/commands/doctor/index.ts rename to packages/cli/src/commands/doctor/types.ts index cae0af27c..9c5a5e7a8 100644 --- a/packages/cli-types/src/commands/doctor/index.ts +++ b/packages/cli/src/commands/doctor/types.ts @@ -1,4 +1,3 @@ -// @flow import Ora from 'ora'; export type EnvironmentInfo = { From 8ecab9d47600fdb8bea5c0d274a05c1f5d384361 Mon Sep 17 00:00:00 2001 From: thib92 Date: Thu, 12 Sep 2019 00:15:22 +0200 Subject: [PATCH 5/5] Use $FlowFixMe for converted files Restore Flow types --- packages/cli/src/commands/doctor/doctor.js | 1 + .../healthchecks/androidHomeEnvVariable.js | 1 + .../doctor/healthchecks/androidNDK.js | 3 + .../doctor/healthchecks/androidSDK.js | 3 + .../commands/doctor/healthchecks/cocoaPods.js | 1 + .../commands/doctor/healthchecks/iosDeploy.js | 2 + .../commands/doctor/healthchecks/nodeJS.js | 3 + .../doctor/healthchecks/packageManagers.js | 2 + .../commands/doctor/healthchecks/watchman.js | 2 + .../src/commands/doctor/healthchecks/xcode.js | 3 + packages/cli/src/commands/doctor/types.js | 79 +++++++++++++++++++ 11 files changed, 100 insertions(+) create mode 100644 packages/cli/src/commands/doctor/types.js 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/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/types.js b/packages/cli/src/commands/doctor/types.js new file mode 100644 index 000000000..3793e8d9b --- /dev/null +++ b/packages/cli/src/commands/doctor/types.js @@ -0,0 +1,79 @@ +// @flow +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, +};