Plugin architecture (#4861)
* wip * Refactor, tasks, processors, routes loading * Move Slack settings config to plugin * Fix translations in plugins * Move Slack auth to plugin * test * Move other slack-related files into plugin * Forgot to save * refactor
This commit is contained in:
37
app/utils/plugins.ts
Normal file
37
app/utils/plugins.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
interface Plugin {
|
||||
id: string;
|
||||
config: {
|
||||
name: string;
|
||||
description: string;
|
||||
requiredEnvVars?: string[];
|
||||
};
|
||||
settings: React.FC;
|
||||
icon: React.FC;
|
||||
}
|
||||
|
||||
export function loadPlugins(): { [id: string]: Plugin } {
|
||||
const plugins = {};
|
||||
|
||||
function importAll(r: any, property: string) {
|
||||
r.keys().forEach((key: string) => {
|
||||
const id = key.split("/")[1];
|
||||
plugins[id] = plugins[id] || {
|
||||
id,
|
||||
};
|
||||
|
||||
const plugin = r(key);
|
||||
plugins[id][property] = "default" in plugin ? plugin.default : plugin;
|
||||
});
|
||||
}
|
||||
importAll(
|
||||
require.context("../../plugins", true, /client\/Settings\.[tj]sx?$/),
|
||||
"settings"
|
||||
);
|
||||
importAll(
|
||||
require.context("../../plugins", true, /client\/Icon\.[tj]sx?$/),
|
||||
"icon"
|
||||
);
|
||||
importAll(require.context("../../plugins", true, /plugin\.json?$/), "config");
|
||||
|
||||
return plugins;
|
||||
}
|
||||
Reference in New Issue
Block a user