-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82ed2b9
commit 1140866
Showing
7 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { PluginManagementStorage } from "./storage"; | ||
import { PluginInfo, PluginEntryFunction, PluginInterface } from "./types"; | ||
import { StorexHubApi_v0 } from "../public-api"; | ||
|
||
export class PluginManager { | ||
constructor(private options: { | ||
pluginManagementStorage: PluginManagementStorage | ||
}) { | ||
|
||
} | ||
|
||
async setup(createAPI: () => Promise<StorexHubApi_v0>) { | ||
const enabledPlugins = await this.options.pluginManagementStorage.getInfoForEnabledPlugins() | ||
for (const pluginInfo of enabledPlugins) { | ||
(async () => { | ||
const plugin = await this._loadPlugin(pluginInfo, createAPI) | ||
if (!plugin) { | ||
return | ||
} | ||
|
||
await plugin.start() | ||
})() | ||
} | ||
} | ||
|
||
async _loadPlugin(pluginInfo: PluginInfo, createAPI: () => Promise<StorexHubApi_v0>): Promise<PluginInterface | null> { | ||
let pluginModule: any | ||
try { | ||
pluginModule = require(pluginInfo.mainPath) | ||
} catch (e) { | ||
console.error(`ERROR - Could not require plugin ${pluginInfo.identifier} at path ${pluginInfo.mainPath}:`) | ||
console.error(e) | ||
return null | ||
} | ||
|
||
const entryFunction: PluginEntryFunction = pluginModule[pluginInfo.entryFunction] | ||
if (!entryFunction) { | ||
console.error(`ERROR - Could not find entry function '${pluginInfo.entryFunction}' in plugin ${pluginInfo.identifier}`) | ||
return null | ||
} | ||
|
||
let plugin: PluginInterface | ||
try { | ||
plugin = await entryFunction({ api: await createAPI() }) | ||
} catch (e) { | ||
console.error(`ERROR during initialization plugin '${pluginInfo.identifier}':`) | ||
console.error(e) | ||
return null | ||
} | ||
|
||
return plugin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { StorexHubApi_v0 } from "../../../public-api"; | ||
import { PluginEntryFunction } from "../../types"; | ||
|
||
export async function main(input: { api: StorexHubApi_v0 }) { | ||
|
||
export const main: PluginEntryFunction = async (input: { api: StorexHubApi_v0 }) => { | ||
return { | ||
start: async () => { console.log('starting plugin!') }, | ||
stop: async () => { console.log('stopping plugin!') } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters