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",
|
"name": "flipper-doctor",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"description": "Utility for checking for issues with a flipper installation",
|
"description": "Utility for checking for issues with a flipper installation",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
|
|||||||
@@ -7,24 +7,10 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {getEnvInfo} from './environmentInfo';
|
import {runHealthchecks} from './index';
|
||||||
import {getHealthchecks} from './index';
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const environmentInfo = await getEnvInfo();
|
const results = await runHealthchecks();
|
||||||
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),
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
: {},
|
|
||||||
]);
|
|
||||||
|
|
||||||
console.log(JSON.stringify(results, null, 2));
|
console.log(JSON.stringify(results, null, 2));
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -7,10 +7,12 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {EnvironmentInfo} from './environmentInfo';
|
import {getEnvInfo, EnvironmentInfo} from './environmentInfo';
|
||||||
|
export {getEnvInfo} from './environmentInfo';
|
||||||
|
|
||||||
type HealthcheckCategory = {
|
type HealthcheckCategory = {
|
||||||
label: string;
|
label: string;
|
||||||
|
isRequired: boolean;
|
||||||
healthchecks: Healthcheck[];
|
healthchecks: Healthcheck[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -21,24 +23,25 @@ type Healthchecks = {
|
|||||||
|
|
||||||
type Healthcheck = {
|
type Healthcheck = {
|
||||||
label: string;
|
label: string;
|
||||||
|
isRequired?: boolean;
|
||||||
run: (
|
run: (
|
||||||
env: EnvironmentInfo,
|
env: EnvironmentInfo,
|
||||||
) => {
|
) => Promise<{
|
||||||
hasProblem: boolean;
|
hasProblem: boolean;
|
||||||
isRequired?: boolean;
|
}>;
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getHealthchecks(): Healthchecks {
|
export function getHealthchecks(): Healthchecks {
|
||||||
return {
|
return {
|
||||||
android: {
|
android: {
|
||||||
label: 'Android',
|
label: 'Android',
|
||||||
|
isRequired: false,
|
||||||
healthchecks: [
|
healthchecks: [
|
||||||
{
|
{
|
||||||
label: 'SDK Installed',
|
label: 'SDK Installed',
|
||||||
run: (e: EnvironmentInfo) => ({
|
isRequired: true,
|
||||||
hasProblem: e.SDKs['Android SDK'] != 'Not Found',
|
run: async (e: EnvironmentInfo) => ({
|
||||||
isRequired: false,
|
hasProblem: e.SDKs['Android SDK'] === 'Not Found',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -47,12 +50,13 @@ export function getHealthchecks(): Healthchecks {
|
|||||||
? {
|
? {
|
||||||
ios: {
|
ios: {
|
||||||
label: 'iOS',
|
label: 'iOS',
|
||||||
|
isRequired: false,
|
||||||
healthchecks: [
|
healthchecks: [
|
||||||
{
|
{
|
||||||
label: 'SDK Installed',
|
label: 'SDK Installed',
|
||||||
run: (e: EnvironmentInfo) => ({
|
isRequired: true,
|
||||||
|
run: async (e: EnvironmentInfo) => ({
|
||||||
hasProblem: e.SDKs['iOS SDK'].Platforms.length === 0,
|
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