(routerMap: Map<string, RouterMapConfig>)
| 48 | export const DEFAULT_LOCAL_PLUGIN_PATH = '/plugin-frontend/' |
| 49 | |
| 50 | export const ApiparkPluginDriver = (routerMap: Map<string, RouterMapConfig>): ApiparkPluginDriverType => { |
| 51 | return { |
| 52 | builtIn: { |
| 53 | component: (coreObj?: CoreObj, pluginConfig?: PluginConfigType) => { |
| 54 | if (!coreObj || !pluginConfig) return coreObj |
| 55 | for (const pluginRouter of pluginConfig.router) { |
| 56 | routerMap.get(pluginConfig.name) && |
| 57 | coreObj.pluginProvider.setRouterConfig(pluginRouter.type === 'root', { |
| 58 | ...routerMap.get(pluginConfig.name)!, |
| 59 | key: pluginConfig.name, |
| 60 | path: pluginRouter.path |
| 61 | }) |
| 62 | } |
| 63 | return coreObj |
| 64 | } |
| 65 | }, |
| 66 | remote: { |
| 67 | normal: (coreObj?: CoreObj, pluginConfig?: PluginConfigType) => { |
| 68 | if (!coreObj || !pluginConfig) return coreObj |
| 69 | const routerToChanged: RouteConfig[] = coreObj.routerConfig.find( |
| 70 | (router: RouteConfig) => router.path === '/' && router?.pathMatch !== 'full' |
| 71 | )!.children as RouteConfig[] |
| 72 | const remoteRouter: RouteConfig[] = routerToChanged.find( |
| 73 | (item: RouteConfig) => item?.data?.['type'] === 'remotePlugin' |
| 74 | ) as RouteConfig[] |
| 75 | if (!remoteRouter) { |
| 76 | routerMap.get('remote') && |
| 77 | coreObj.pluginProvider.setRouterConfig(false, { |
| 78 | ...routerMap.get('remote')!, |
| 79 | key: 'remote', |
| 80 | path: 'remote', |
| 81 | type: 'remotePlugin', |
| 82 | children: [ |
| 83 | { |
| 84 | path: ':moduleName', |
| 85 | component: routerMap.get('remote')!.component |
| 86 | } |
| 87 | ] |
| 88 | }) |
| 89 | } |
| 90 | return coreObj |
| 91 | } |
| 92 | }, |
| 93 | intelligent: { |
| 94 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 95 | normal: (coreObj?: CoreObj, pluginConfig?: PluginConfigType) => { |
| 96 | if (!coreObj || !pluginConfig) return coreObj |
| 97 | if (['logsettings', 'resourcesettings'].indexOf(pluginConfig.name) !== -1) { |
| 98 | const routerToChanged: RouteConfig[] = coreObj.routerConfig.find( |
| 99 | (router: RouteConfig) => router.path === '/' && router?.pathMatch !== 'full' |
| 100 | )!.children as RouteConfig[] |
| 101 | const remoteRouter: RouteConfig[] = routerToChanged.find( |
| 102 | (item: RouteConfig) => item?.data?.['key'] === pluginConfig.name |
| 103 | ) as RouteConfig[] |
| 104 | if (!remoteRouter) { |
| 105 | routerMap.get(pluginConfig.name) && |
| 106 | routerToChanged.unshift({ |
| 107 | ...routerMap.get(pluginConfig.name)!, |
no test coverage detected