MCPcopy Create free account
hub / github.com/PenguLoader/PenguLoader / loadPlugin

Function loadPlugin

plugins/src/preload/loader.ts:40–73  ·  view source on GitHub ↗
(entry: string)

Source from the content-addressed store, hash-verified

38}
39
40async function loadPlugin(entry: string) {
41 let stage = 'load';
42 try {
43 // Acquire plugin
44 const url = `https://plugins/${entry}`;
45 const plugin: Plugin = await import(url);
46
47 // Init immediately
48 if (typeof plugin.init === 'function') {
49 stage = 'initialize';
50 const pluginName = entry.substring(0, entry.indexOf('/'));
51 const initContext = { rcp, socket };
52 // If it's not top-level JS
53 if (pluginName) {
54 const meta = { name: pluginName };
55 initContext['meta'] = meta;
56 }
57 await plugin.init(initContext);
58 }
59
60 // Register load
61 if (typeof plugin.load === 'function') {
62 window.addEventListener('load', plugin.load);
63 } else if (typeof plugin.default === 'function') {
64 window.addEventListener('load', plugin.default);
65 }
66
67 const msg = `Loaded plugin "${entry}".`;
68 console.info('%c Pengu ', 'background: #183461; color: #fff', msg);
69 } catch (err) {
70 const msg = `Failed to ${stage} plugin "${entry}".\n`;
71 console.error('%c Pengu ', 'background: #183461; color: #fff', msg, err);
72 }
73}
74
75// Load all plugins asynchronously
76const waitable = Promise.all(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected