Basic Doctor UI
Summary: - Basic Doctor UI showing issues with installation - Run healthchecks in background on startup and show warning message if something is wrong Reviewed By: jknoxville Differential Revision: D18502599 fbshipit-source-id: 194939a080ba7412ed3293d95c533bfad7031d3b
This commit is contained in:
committed by
Facebook Github Bot
parent
c1de6f4276
commit
ddb135ac39
@@ -7,10 +7,29 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {runHealthchecks} from './index';
|
||||
import {getHealthchecks} from './index';
|
||||
import {getEnvInfo} from './environmentInfo';
|
||||
|
||||
(async () => {
|
||||
const results = await runHealthchecks();
|
||||
const environmentInfo = await getEnvInfo();
|
||||
console.log(JSON.stringify(environmentInfo));
|
||||
const healthchecks = getHealthchecks();
|
||||
const results = await Promise.all(
|
||||
Object.entries(healthchecks).map(async ([key, category]) => [
|
||||
key,
|
||||
category
|
||||
? {
|
||||
label: category.label,
|
||||
results: await Promise.all(
|
||||
category.healthchecks.map(async ({label, run}) => ({
|
||||
label,
|
||||
result: await run(environmentInfo),
|
||||
})),
|
||||
),
|
||||
}
|
||||
: {},
|
||||
]),
|
||||
);
|
||||
|
||||
console.log(JSON.stringify(results, null, 2));
|
||||
})();
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {getEnvInfo, EnvironmentInfo} from './environmentInfo';
|
||||
export {getEnvInfo} from './environmentInfo';
|
||||
import {exec} from 'child_process';
|
||||
import {promisify} from 'util';
|
||||
import {EnvironmentInfo, getEnvInfo} from './environmentInfo';
|
||||
export {getEnvInfo} from './environmentInfo';
|
||||
|
||||
type HealthcheckCategory = {
|
||||
label: string;
|
||||
@@ -31,6 +31,7 @@ type Healthcheck = {
|
||||
env: EnvironmentInfo,
|
||||
) => Promise<{
|
||||
hasProblem: boolean;
|
||||
helpUrl?: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
@@ -54,7 +55,6 @@ export function getHealthchecks(): Healthchecks {
|
||||
healthchecks: [
|
||||
{
|
||||
label: 'OpenSSL Installed',
|
||||
isRequired: true,
|
||||
run: async (_: EnvironmentInfo) => {
|
||||
const isAvailable = await commandSucceeds('openssl version');
|
||||
return {
|
||||
@@ -75,6 +75,12 @@ export function getHealthchecks(): Healthchecks {
|
||||
hasProblem: e.SDKs['Android SDK'] === 'Not Found',
|
||||
}),
|
||||
},
|
||||
{
|
||||
label: 'ANDROID_HOME set',
|
||||
run: async (e: EnvironmentInfo) => ({
|
||||
hasProblem: !!process.env.ANDROID_HOME,
|
||||
}),
|
||||
},
|
||||
],
|
||||
},
|
||||
...(process.platform === 'darwin'
|
||||
@@ -127,33 +133,35 @@ export function getHealthchecks(): Healthchecks {
|
||||
export async function runHealthchecks(): Promise<Array<CategoryResult>> {
|
||||
const environmentInfo = await getEnvInfo();
|
||||
const healthchecks: Healthchecks = getHealthchecks();
|
||||
const results: Array<CategoryResult> = (await Promise.all(
|
||||
Object.entries(healthchecks).map(async ([key, category]) => {
|
||||
if (!category) {
|
||||
return null;
|
||||
}
|
||||
const categoryResult: CategoryResult = [
|
||||
key,
|
||||
{
|
||||
label: category.label,
|
||||
results: await Promise.all(
|
||||
category.healthchecks.map(async ({label, run, isRequired}) => ({
|
||||
label,
|
||||
isRequired: isRequired ?? true,
|
||||
result: await run(environmentInfo).catch(e => {
|
||||
console.error(e);
|
||||
// TODO Improve result type to be: OK | Problem(message, fix...)
|
||||
return {
|
||||
hasProblem: true,
|
||||
};
|
||||
}),
|
||||
})),
|
||||
),
|
||||
},
|
||||
];
|
||||
return categoryResult;
|
||||
}),
|
||||
)).filter(notNull);
|
||||
const results: Array<CategoryResult> = (
|
||||
await Promise.all(
|
||||
Object.entries(healthchecks).map(async ([key, category]) => {
|
||||
if (!category) {
|
||||
return null;
|
||||
}
|
||||
const categoryResult: CategoryResult = [
|
||||
key,
|
||||
{
|
||||
label: category.label,
|
||||
results: await Promise.all(
|
||||
category.healthchecks.map(async ({label, run, isRequired}) => ({
|
||||
label,
|
||||
isRequired: isRequired ?? true,
|
||||
result: await run(environmentInfo).catch(e => {
|
||||
console.error(e);
|
||||
// TODO Improve result type to be: OK | Problem(message, fix...)
|
||||
return {
|
||||
hasProblem: true,
|
||||
};
|
||||
}),
|
||||
})),
|
||||
),
|
||||
},
|
||||
];
|
||||
return categoryResult;
|
||||
}),
|
||||
)
|
||||
).filter(notNull);
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user