Move flipper-doctor check running to flipper-server-core
Summary: Per title. Two new server API's: get-healthchecks, and run-healtcheck. Types have all been moved to flipper-common, so that they can be used by doctor, server-core and ui-core packages. Since it were quite some, moved them into a FlipperDoctor namespace. Reviewed By: nikoant Differential Revision: D32720510 fbshipit-source-id: 37aa35cde6ebd58479cf0dffec5b7b2da6d22198
This commit is contained in:
committed by
Facebook GitHub Bot
parent
2a4fe77404
commit
2480ed30c5
@@ -19,6 +19,7 @@
|
||||
"async-mutex": "^0.3.2",
|
||||
"flipper-plugin-lib": "0.0.0",
|
||||
"flipper-common": "0.0.0",
|
||||
"flipper-doctor": "0.0.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"invariant": "^2.2.4",
|
||||
"js-base64": "^3.7.2",
|
||||
|
||||
@@ -35,6 +35,7 @@ import {saveSettings} from './utils/settings';
|
||||
import {saveLauncherSettings} from './utils/launcherSettings';
|
||||
import {KeytarManager} from './utils/keytar';
|
||||
import {PluginManager} from './plugins/PluginManager';
|
||||
import {runHealthcheck, getHealthChecks} from './utils/runHealthchecks';
|
||||
|
||||
/**
|
||||
* FlipperServer takes care of all incoming device & client connections.
|
||||
@@ -269,6 +270,8 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
'plugins-install-from-npm': (name) =>
|
||||
this.pluginManager.installPluginFromNpm(name),
|
||||
'plugin-source': (path) => this.pluginManager.loadSource(path),
|
||||
'doctor-get-healthchecks': getHealthChecks,
|
||||
'doctor-run-healthcheck': runHealthcheck,
|
||||
};
|
||||
|
||||
registerDevice(device: ServerDevice) {
|
||||
|
||||
76
desktop/flipper-server-core/src/utils/runHealthchecks.tsx
Normal file
76
desktop/flipper-server-core/src/utils/runHealthchecks.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {getHealthchecks, getEnvInfo} from 'flipper-doctor';
|
||||
import {FlipperDoctor} from 'flipper-common';
|
||||
import produce from 'immer';
|
||||
|
||||
export async function getHealthChecks(
|
||||
options: FlipperDoctor.HealthcheckSettings,
|
||||
) {
|
||||
return produce(getHealthchecks(), (healthchecks) => {
|
||||
if (!options.settings.enableAndroid) {
|
||||
healthchecks.android = {
|
||||
label: healthchecks.android.label,
|
||||
isSkipped: true,
|
||||
skipReason:
|
||||
'Healthcheck is skipped, because "Android Development" option is disabled in the Flipper settings',
|
||||
};
|
||||
}
|
||||
if (!options.settings.enableIOS) {
|
||||
healthchecks.ios = {
|
||||
label: healthchecks.ios.label,
|
||||
isSkipped: true,
|
||||
skipReason:
|
||||
'Healthcheck is skipped, because "iOS Development" option is disabled in the Flipper settings',
|
||||
};
|
||||
}
|
||||
Object.keys(healthchecks).forEach((cat) => {
|
||||
const category = healthchecks[cat as keyof typeof healthchecks];
|
||||
if ('healthchecks' in category) {
|
||||
category.healthchecks.forEach((h) => {
|
||||
delete h.run;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function runHealthcheck(
|
||||
options: FlipperDoctor.HealthcheckSettings,
|
||||
categoryName: keyof FlipperDoctor.Healthchecks,
|
||||
ruleName: string,
|
||||
): Promise<FlipperDoctor.HealthcheckResult> {
|
||||
const healthchecks = getHealthchecks();
|
||||
const category = healthchecks[categoryName];
|
||||
if (!category) {
|
||||
throw new Error('Unknown category: ' + categoryName);
|
||||
}
|
||||
if (!('healthchecks' in category)) {
|
||||
throw new Error('Skipped category: ' + categoryName);
|
||||
}
|
||||
const check = category.healthchecks.find((h) => h.key === ruleName);
|
||||
if (!check) {
|
||||
throw new Error('Unknown healthcheck: ' + ruleName);
|
||||
}
|
||||
|
||||
const environmentInfo = await getEnvInfo();
|
||||
const checkResult = await check.run!(environmentInfo, options.settings);
|
||||
return checkResult.hasProblem && check.isRequired
|
||||
? {
|
||||
status: 'FAILED',
|
||||
message: checkResult.message,
|
||||
}
|
||||
: checkResult.hasProblem && !check.isRequired
|
||||
? {
|
||||
status: 'WARNING',
|
||||
message: checkResult.message,
|
||||
}
|
||||
: {status: 'SUCCESS', message: checkResult.message};
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
"rootDir": "src"
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "../doctor"
|
||||
},
|
||||
{
|
||||
"path": "../flipper-common"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user