Make healthchecks async
Summary: Rework the healthchecks. * Makes them healthcheck run api async so they can do more. * Adds isRequired to the top level categories - this specifies if the category itself is required. The isRequired attributes of its constituent checks specifies if they are required within that category. * Move isRequired outside the result of the healthcheck functions, because its static. Reviewed By: mweststrate Differential Revision: D18425189 fbshipit-source-id: 9d5c136a426732375d32cd27a758d9c92d123214
This commit is contained in:
committed by
Facebook Github Bot
parent
5bdba4935a
commit
fc1e4098ed
1
doctor/.ignore
Symbolic link
1
doctor/.ignore
Symbolic link
@@ -0,0 +1 @@
|
||||
.gitignore
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flipper-doctor",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"description": "Utility for checking for issues with a flipper installation",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
||||
@@ -7,24 +7,10 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {getEnvInfo} from './environmentInfo';
|
||||
import {getHealthchecks} from './index';
|
||||
import {runHealthchecks} from './index';
|
||||
|
||||
(async () => {
|
||||
const environmentInfo = await getEnvInfo();
|
||||
const healthchecks = getHealthchecks();
|
||||
const results = Object.entries(healthchecks).map(([key, category]) => [
|
||||
key,
|
||||
category
|
||||
? {
|
||||
label: category.label,
|
||||
results: category.healthchecks.map(({label, run}) => ({
|
||||
label,
|
||||
result: run(environmentInfo),
|
||||
})),
|
||||
}
|
||||
: {},
|
||||
]);
|
||||
const results = await runHealthchecks();
|
||||
|
||||
console.log(JSON.stringify(results, null, 2));
|
||||
})();
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {EnvironmentInfo} from './environmentInfo';
|
||||
import {getEnvInfo, EnvironmentInfo} from './environmentInfo';
|
||||
export {getEnvInfo} from './environmentInfo';
|
||||
|
||||
type HealthcheckCategory = {
|
||||
label: string;
|
||||
isRequired: boolean;
|
||||
healthchecks: Healthcheck[];
|
||||
};
|
||||
|
||||
@@ -21,24 +23,25 @@ type Healthchecks = {
|
||||
|
||||
type Healthcheck = {
|
||||
label: string;
|
||||
isRequired?: boolean;
|
||||
run: (
|
||||
env: EnvironmentInfo,
|
||||
) => {
|
||||
) => Promise<{
|
||||
hasProblem: boolean;
|
||||
isRequired?: boolean;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
export function getHealthchecks(): Healthchecks {
|
||||
return {
|
||||
android: {
|
||||
label: 'Android',
|
||||
isRequired: false,
|
||||
healthchecks: [
|
||||
{
|
||||
label: 'SDK Installed',
|
||||
run: (e: EnvironmentInfo) => ({
|
||||
hasProblem: e.SDKs['Android SDK'] != 'Not Found',
|
||||
isRequired: false,
|
||||
isRequired: true,
|
||||
run: async (e: EnvironmentInfo) => ({
|
||||
hasProblem: e.SDKs['Android SDK'] === 'Not Found',
|
||||
}),
|
||||
},
|
||||
],
|
||||
@@ -47,12 +50,13 @@ export function getHealthchecks(): Healthchecks {
|
||||
? {
|
||||
ios: {
|
||||
label: 'iOS',
|
||||
isRequired: false,
|
||||
healthchecks: [
|
||||
{
|
||||
label: 'SDK Installed',
|
||||
run: (e: EnvironmentInfo) => ({
|
||||
isRequired: true,
|
||||
run: async (e: EnvironmentInfo) => ({
|
||||
hasProblem: e.SDKs['iOS SDK'].Platforms.length === 0,
|
||||
isRequired: false,
|
||||
}),
|
||||
},
|
||||
],
|
||||
@@ -61,3 +65,32 @@ export function getHealthchecks(): Healthchecks {
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
export async function runHealthchecks() {
|
||||
const environmentInfo = await getEnvInfo();
|
||||
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, 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 results;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user