Move plugin manager logic out of UI component
Summary: Moving some things around for the upcoming update support. Reviewed By: jknoxville Differential Revision: D18347572 fbshipit-source-id: b614fe3a87f8e7fdc0c11c0d3bfe4787c0914d17
This commit is contained in:
committed by
Facebook Github Bot
parent
4c0c212258
commit
05c007be16
@@ -9,46 +9,8 @@
|
||||
|
||||
import {Store} from '../reducers/index';
|
||||
import {Logger} from '../fb-interfaces/Logger';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {homedir} from 'os';
|
||||
import {
|
||||
registerInstalledPlugins,
|
||||
PluginMap,
|
||||
PluginDefinition,
|
||||
} from '../reducers/pluginManager';
|
||||
|
||||
export const PLUGIN_DIR = path.join(homedir(), '.flipper', 'thirdparty');
|
||||
|
||||
export async function readInstalledPlugins(): Promise<PluginMap> {
|
||||
const pluginDirExists = await fs.pathExists(PLUGIN_DIR);
|
||||
|
||||
if (!pluginDirExists) {
|
||||
return new Map();
|
||||
}
|
||||
const dirs = await fs.readdir(PLUGIN_DIR);
|
||||
const plugins = await Promise.all<[string, PluginDefinition]>(
|
||||
dirs.map(
|
||||
name =>
|
||||
new Promise(async (resolve, reject) => {
|
||||
if (!(await fs.lstat(path.join(PLUGIN_DIR, name))).isDirectory()) {
|
||||
return resolve(undefined);
|
||||
}
|
||||
|
||||
const packageJSON = await fs.readFile(
|
||||
path.join(PLUGIN_DIR, name, 'package.json'),
|
||||
);
|
||||
|
||||
try {
|
||||
resolve([name, JSON.parse(packageJSON.toString())]);
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
return new Map(plugins.filter(Boolean));
|
||||
}
|
||||
import {registerInstalledPlugins} from '../reducers/pluginManager';
|
||||
import {readInstalledPlugins} from '../utils/pluginManager';
|
||||
|
||||
function refreshInstalledPlugins(store: Store) {
|
||||
readInstalledPlugins().then(plugins =>
|
||||
|
||||
Reference in New Issue
Block a user