(entry: string)
| 38 | } |
| 39 | |
| 40 | async 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 |
| 76 | const waitable = Promise.all( |
nothing calls this directly
no outgoing calls
no test coverage detected