(type: LoadTask, filename: string)
| 21 | |
| 22 | type LoadTask = 'model' | 'addon' | 'service'; |
| 23 | const getLoader = (type: LoadTask, filename: string) => async function loader(pending: Record<string, string>, fail: string[], ctx: Context) { |
| 24 | for (const [name, i] of Object.entries(pending)) { |
| 25 | const p = locateFile(i, [`${filename}.ts`, `${filename}.js`]); |
| 26 | if (p && !fail.includes(i)) { |
| 27 | const loadType = type.replace(/^(.)/, (t) => t.toUpperCase()); |
| 28 | try { |
| 29 | const m = unwrapExports(require(p)); |
| 30 | if (m.apply) ctx.loader.reloadPlugin(p, name); |
| 31 | else logger.info(`${loadType} init: %s`, i); |
| 32 | } catch (e) { |
| 33 | fail.push(i); |
| 34 | app.injectUI( |
| 35 | 'Notification', `${loadType} load fail: {0}`, |
| 36 | { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION, |
| 37 | ); |
| 38 | logger.info(`${loadType} load fail: %s`, i); |
| 39 | logger.error(e); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | export const addon = getLoader('addon', 'index'); |
| 46 | export const model = getLoader('model', 'model'); |
no test coverage detected