Files
flipper/src/plugins/index.js
Daniel Büchele e9490ca3b4 comments and variable names
Summary:
renaming across the app:
- comments
- variable names
- constants

Reviewed By: passy

Differential Revision: D9861792

fbshipit-source-id: 72dea05d1427b1dc0f54a7865cc0ecffd69bdb27
2018-09-18 07:01:17 -07:00

85 lines
2.1 KiB
JavaScript

/**
* Copyright 2018-present Facebook.
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* @format
*/
import {GK} from 'flipper';
import React from 'react';
import ReactDOM from 'react-dom';
import * as Flipper from 'flipper';
import {FlipperPlugin, FlipperBasePlugin} from '../plugin.js';
import {remote} from 'electron';
const plugins = new Map();
// $FlowFixMe process.env not defined in electron API spec
const remoteEnv = remote.process.env;
// expose Flipper and exact globally for dynamically loaded plugins
window.React = React;
window.ReactDOM = ReactDOM;
window.Flipper = Flipper;
const addIfNotAdded = plugin => {
if (!plugins.has(plugin.name)) {
plugins.set(plugin.name, plugin);
}
};
let disabledPlugins = [];
try {
disabledPlugins = JSON.parse(remoteEnv.CONFIG || '{}').disabledPlugins || [];
} catch (e) {
console.error(e);
}
// Load dynamic plugins
try {
JSON.parse(remoteEnv.PLUGINS || '[]').forEach(addIfNotAdded);
} catch (e) {
console.error(e);
}
// DefaultPlugins that are included in the bundle.
// List of defaultPlugins is written at build time
let bundledPlugins = [];
try {
bundledPlugins = window.electronRequire('./defaultPlugins/index.json');
} catch (e) {}
bundledPlugins
.map(plugin => ({
...plugin,
out: './' + plugin.out,
}))
.forEach(addIfNotAdded);
const exportedPlugins: Array<Class<FlipperPlugin<>>> = Array.from(
plugins.values(),
)
.map(plugin => {
if (
(plugin.gatekeeper && !GK.get(plugin.gatekeeper)) ||
disabledPlugins.indexOf(plugin.name) > -1
) {
console.warn(
'Plugin %s will be ignored as user is not part of the gatekeeper "%s".',
plugin.name,
plugin.gatekeeper,
);
return null;
} else {
try {
return window.electronRequire(plugin.out);
} catch (e) {
console.error(plugin, e);
return null;
}
}
})
.filter(Boolean)
.filter(plugin => plugin.prototype instanceof FlipperBasePlugin)
.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
export default exportedPlugins;