feat: eager load apps
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import path from 'node:path';
|
||||||
|
import fs from 'node:fs';
|
||||||
import {
|
import {
|
||||||
IAction,
|
IAction,
|
||||||
IApp,
|
IApp,
|
||||||
@@ -8,8 +10,22 @@ import {
|
|||||||
import { omit, cloneDeep } from 'lodash';
|
import { omit, cloneDeep } from 'lodash';
|
||||||
import addReconnectionSteps from './add-reconnection-steps';
|
import addReconnectionSteps from './add-reconnection-steps';
|
||||||
|
|
||||||
async function getDefaultExport(path: string) {
|
type TApps = Record<string, Promise<{ default: IApp }>>;
|
||||||
return (await import(path)).default;
|
const apps = fs
|
||||||
|
.readdirSync(
|
||||||
|
path.resolve(__dirname, `../apps/`),
|
||||||
|
{ withFileTypes: true }
|
||||||
|
)
|
||||||
|
.reduce((apps, dirent) => {
|
||||||
|
if (!dirent.isDirectory()) return apps;
|
||||||
|
|
||||||
|
apps[dirent.name] = import(path.resolve(__dirname, '../apps', dirent.name));
|
||||||
|
|
||||||
|
return apps;
|
||||||
|
}, {} as TApps);
|
||||||
|
|
||||||
|
async function getDefaultExport(appKey: string) {
|
||||||
|
return (await apps[appKey]).default;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stripFunctions<C>(data: C): C {
|
function stripFunctions<C>(data: C): C {
|
||||||
@@ -17,7 +33,7 @@ function stripFunctions<C>(data: C): C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getApp = async (appKey: string, stripFuncs = true) => {
|
const getApp = async (appKey: string, stripFuncs = true) => {
|
||||||
let appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`));
|
let appData: IApp = cloneDeep(await getDefaultExport(appKey));
|
||||||
|
|
||||||
if (appData.auth) {
|
if (appData.auth) {
|
||||||
appData = addReconnectionSteps(appData);
|
appData = addReconnectionSteps(appData);
|
||||||
|
Reference in New Issue
Block a user