Load marketplace plugins from PluginManager
Summary: Expand PluginManager as to be able to load and install plugins from Marketplace. Reviewed By: passy Differential Revision: D37749802 fbshipit-source-id: 7d7e23427cc9d01f5c953b90e5b346a9d6bab19f
This commit is contained in:
committed by
Facebook GitHub Bot
parent
04b433fe1d
commit
b9e1039b7a
@@ -34,6 +34,7 @@ import {
|
||||
installPluginFromNpm,
|
||||
} from 'flipper-plugin-lib';
|
||||
import {ServerAddOnManager} from './ServerAddManager';
|
||||
import {loadMarketplacePlugins} from './loadMarketplacePlugins';
|
||||
|
||||
const maxInstalledPluginVersionsToKeep = 2;
|
||||
|
||||
@@ -98,6 +99,30 @@ export class PluginManager {
|
||||
return bundledPlugins;
|
||||
}
|
||||
|
||||
async loadMarketplacePlugins() {
|
||||
console.info('Load available plugins from marketplace');
|
||||
return loadMarketplacePlugins(this.flipperServer, '');
|
||||
}
|
||||
|
||||
async installPluginForMarketplace(name: string) {
|
||||
console.info(`Install plugin '${name}' from marketplace`);
|
||||
|
||||
const plugins = await this.loadMarketplacePlugins();
|
||||
const plugin = plugins.find((p) => p.id === name);
|
||||
if (plugin) {
|
||||
console.info(`Plugin '${name}' is available, attempt to install`);
|
||||
try {
|
||||
return await this.downloadPlugin(plugin);
|
||||
} catch (e) {
|
||||
console.warn(`Unable to install plugin '${name}'. Error:`, e);
|
||||
}
|
||||
} else {
|
||||
console.info('Plugin not available in marketplace');
|
||||
}
|
||||
|
||||
throw new Error(`Unable to install plugin '${name}' from marketplace`);
|
||||
}
|
||||
|
||||
async downloadPlugin(
|
||||
plugin: DownloadablePluginDetails,
|
||||
): Promise<InstalledPluginDetails> {
|
||||
|
||||
Reference in New Issue
Block a user