Move the code related to plugin loading / installation to "flipper-plugin-lib"
Summary: Sorry for so long diff, but actually there are no functional changes, just refactoring to make further changes of Plugin Manager easier to understand. I've de-coupled the code related to plugin management from UI code and moved it from PluginInstaller UI component (which will be replaced soon by new UI) to "flipper-plugin-lib". So pretty much everything related to plugin discovery and installation now consolidated in this package. Additionally, this refactoring enables re-using of plugin management code in "flipper-pkg", e.g. to create CLI command for plugin installation from NPM, e.g.: `flipper-pkg install flipper-plugin-reactotron`. Reviewed By: passy Differential Revision: D23679346 fbshipit-source-id: 82e7b9de9afa08c508c1b228c2038b4ba423571c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
72ff87d7cd
commit
e48707151a
46
desktop/plugin-lib/src/getNpmHostedPlugins.ts
Normal file
46
desktop/plugin-lib/src/getNpmHostedPlugins.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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 {default as algoliasearch, SearchIndex} from 'algoliasearch';
|
||||
|
||||
const ALGOLIA_APPLICATION_ID = 'OFCNCOG2CU';
|
||||
const ALGOLIA_API_KEY = 'f54e21fa3a2a0160595bb058179bfb1e';
|
||||
|
||||
function provideSearchIndex(): SearchIndex {
|
||||
const client = algoliasearch(ALGOLIA_APPLICATION_ID, ALGOLIA_API_KEY);
|
||||
return client.initIndex('npm-search');
|
||||
}
|
||||
|
||||
export type NpmPackageDescriptor = {
|
||||
name: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export type NpmHostedPluginsSearchArgs = {
|
||||
query?: string;
|
||||
};
|
||||
|
||||
export async function getNpmHostedPlugins(
|
||||
args: NpmHostedPluginsSearchArgs = {},
|
||||
): Promise<NpmPackageDescriptor[]> {
|
||||
const index = provideSearchIndex();
|
||||
args = Object.assign(
|
||||
{
|
||||
query: '',
|
||||
filters: 'keywords:flipper-plugin',
|
||||
hitsPerPage: 50,
|
||||
},
|
||||
args,
|
||||
);
|
||||
const {hits} = await index.search<NpmPackageDescriptor>(
|
||||
args.query || '',
|
||||
args,
|
||||
);
|
||||
return hits;
|
||||
}
|
||||
Reference in New Issue
Block a user