read infos from package.json
Summary: Adding the properties from a plugin's `package.json` as static properties to the class. The name from `package.json` is used as it's `id`. This allows us in the future to add meta information about a plugin to it's package.json and still use the data inside the app. Reviewed By: priteshrnandgaonkar Differential Revision: D13417288 fbshipit-source-id: 3d0a62d4cb0115153cce1aaee677b9680fefebf4
This commit is contained in:
committed by
Facebook Github Bot
parent
e23da69db9
commit
6ffc027051
@@ -32,6 +32,7 @@ export default (store: Store, logger: Logger) => {
|
||||
window.Flipper = Flipper;
|
||||
|
||||
const disabled = checkDisabled();
|
||||
|
||||
const initialPlugins: Array<
|
||||
Class<FlipperPlugin<> | FlipperDevicePlugin<>>,
|
||||
> = [...getBundledPlugins(), ...getDynamicPlugins()]
|
||||
@@ -113,10 +114,27 @@ export function requirePlugin(
|
||||
pluginDefinition: PluginDefinition,
|
||||
): ?Class<FlipperPlugin<> | FlipperDevicePlugin<>> => {
|
||||
try {
|
||||
const plugin = requireFunction(pluginDefinition.out);
|
||||
let plugin = requireFunction(pluginDefinition.out);
|
||||
if (plugin.default) {
|
||||
plugin = plugin.default;
|
||||
}
|
||||
if (!plugin.prototype instanceof FlipperBasePlugin) {
|
||||
throw new Error(`Plugin ${plugin.name} is not a FlipperBasePlugin`);
|
||||
}
|
||||
|
||||
// set values from package.json as static variables on class
|
||||
Object.keys(pluginDefinition).forEach(key => {
|
||||
if (key === 'name') {
|
||||
plugin.id = plugin.id || pluginDefinition.name;
|
||||
} else if (key === 'id') {
|
||||
throw new Error(
|
||||
'Field "id" not allowed in package.json. The plugin\'s name will be used as ID"',
|
||||
);
|
||||
} else {
|
||||
plugin[key] = plugin[key] || pluginDefinition[key];
|
||||
}
|
||||
});
|
||||
|
||||
return plugin;
|
||||
} catch (e) {
|
||||
console.error(pluginDefinition, e);
|
||||
|
||||
Reference in New Issue
Block a user