move plugin management from ui-core to server-core
Summary: Follow up of D32665064, this diff moves all plugin management logic from flipper-ui to flipper-server. Things like downloading, installing, querying new plugins. Loading plugins is handled separately in the next diff. Reviewed By: nikoant Differential Revision: D32666537 fbshipit-source-id: 9786b82987f00180bb26200e38735b334dc4d5c3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f9b72ac69e
commit
64747dc417
@@ -98,4 +98,91 @@ export interface DownloadablePluginDetails extends ConcretePluginDetails {
|
||||
lastUpdated: Date;
|
||||
}
|
||||
|
||||
export default PluginDetails;
|
||||
export type UpdateResult =
|
||||
| {kind: 'not-installed'; version: string}
|
||||
| {kind: 'up-to-date'}
|
||||
| {kind: 'error'; error: Error}
|
||||
| {kind: 'update-available'; version: string};
|
||||
|
||||
export type UpdatablePlugin = {
|
||||
updateStatus: UpdateResult;
|
||||
};
|
||||
|
||||
export type UpdatablePluginDetails = InstalledPluginDetails & UpdatablePlugin;
|
||||
|
||||
export function getPluginDetails(packageJson: any): PluginDetails {
|
||||
const specVersion =
|
||||
packageJson.$schema &&
|
||||
packageJson.$schema ===
|
||||
'https://fbflipper.com/schemas/plugin-package/v2.json'
|
||||
? 2
|
||||
: 1;
|
||||
switch (specVersion) {
|
||||
case 1:
|
||||
return getPluginDetailsV1(packageJson);
|
||||
case 2:
|
||||
return getPluginDetailsV2(packageJson);
|
||||
default:
|
||||
throw new Error(`Unknown plugin format version: ${specVersion}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Plugins packaged using V1 are distributed as sources and compiled in run-time.
|
||||
function getPluginDetailsV1(packageJson: any): PluginDetails {
|
||||
return {
|
||||
specVersion: 1,
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
main: 'dist/bundle.js',
|
||||
source: packageJson.main,
|
||||
id: packageJson.name,
|
||||
gatekeeper: packageJson.gatekeeper,
|
||||
icon: packageJson.icon,
|
||||
title: packageJson.title || packageJson.name,
|
||||
description: packageJson.description,
|
||||
category: packageJson.category,
|
||||
bugs: packageJson.bugs,
|
||||
flipperSDKVersion: packageJson?.peerDependencies?.['flipper-plugin'],
|
||||
pluginType: packageJson?.pluginType,
|
||||
supportedDevices: packageJson?.supportedDevices,
|
||||
supportedApps: packageJson?.supportedApps,
|
||||
engines: packageJson.engines,
|
||||
};
|
||||
}
|
||||
|
||||
// Plugins packaged using V2 are pre-bundled, so compilation in run-time is not required for them.
|
||||
function getPluginDetailsV2(packageJson: any): PluginDetails {
|
||||
return {
|
||||
specVersion: 2,
|
||||
name: packageJson.name,
|
||||
version: packageJson.version,
|
||||
main: packageJson.main,
|
||||
source: packageJson.flipperBundlerEntry,
|
||||
id: packageJson.id || packageJson.name,
|
||||
gatekeeper: packageJson.gatekeeper,
|
||||
icon: packageJson.icon,
|
||||
title:
|
||||
packageJson.title || packageJson.id || getTitleFromName(packageJson.name),
|
||||
description: packageJson.description,
|
||||
category: packageJson.category,
|
||||
bugs: packageJson.bugs,
|
||||
flipperSDKVersion: packageJson?.peerDependencies?.['flipper-plugin'],
|
||||
pluginType: packageJson?.pluginType,
|
||||
supportedDevices: packageJson?.supportedDevices,
|
||||
supportedApps: packageJson?.supportedApps,
|
||||
engines: packageJson.engines,
|
||||
publishedDocs: packageJson.publishedDocs,
|
||||
};
|
||||
}
|
||||
|
||||
function getTitleFromName(name: string): string {
|
||||
const prefix = 'flipper-plugin-';
|
||||
if (name.startsWith(prefix)) {
|
||||
return name.substr(prefix.length);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
export function isPluginJson(packageJson: any): boolean {
|
||||
return packageJson?.keywords?.includes('flipper-plugin');
|
||||
}
|
||||
|
||||
@@ -7,7 +7,15 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {DeviceSpec, DeviceType, OS as PluginOS} from './PluginDetails';
|
||||
import {
|
||||
BundledPluginDetails,
|
||||
DeviceSpec,
|
||||
DeviceType,
|
||||
DownloadablePluginDetails,
|
||||
InstalledPluginDetails,
|
||||
OS as PluginOS,
|
||||
UpdatablePluginDetails,
|
||||
} from './PluginDetails';
|
||||
import {LauncherSettings, ProcessConfig, Settings} from './settings';
|
||||
|
||||
// In the future, this file would deserve it's own package, as it doesn't really relate to plugins.
|
||||
@@ -152,6 +160,20 @@ export type FlipperServerCommands = {
|
||||
'keychain-write': (service: string, token: string) => Promise<void>;
|
||||
'keychain-read': (service: string) => Promise<string>;
|
||||
'keychain-unset': (service: string) => Promise<void>;
|
||||
'plugins-load-dynamic-plugins': () => Promise<InstalledPluginDetails[]>;
|
||||
'plugins-get-bundled-plugins': () => Promise<BundledPluginDetails[]>;
|
||||
'plugins-get-installed-plugins': () => Promise<InstalledPluginDetails[]>;
|
||||
'plugins-get-updatable-plugins': (
|
||||
query: string | undefined,
|
||||
) => Promise<UpdatablePluginDetails[]>;
|
||||
'plugin-start-download': (
|
||||
plugin: DownloadablePluginDetails,
|
||||
) => Promise<InstalledPluginDetails>;
|
||||
'plugins-install-from-npm': (name: string) => Promise<InstalledPluginDetails>;
|
||||
'plugins-install-from-file': (
|
||||
path: string,
|
||||
) => Promise<InstalledPluginDetails>;
|
||||
'plugins-remove-plugins': (names: string[]) => Promise<void>;
|
||||
};
|
||||
|
||||
export type ENVIRONMENT_VARIABLES =
|
||||
|
||||
Reference in New Issue
Block a user