2020-10-12 21:49:05 +00:00
|
|
|
import { boot } from 'quasar/wrappers';
|
|
|
|
import { RouteConfig } from 'vue-router';
|
2020-10-16 06:45:40 +00:00
|
|
|
import { Module, Store } from 'vuex';
|
2020-10-18 23:45:06 +00:00
|
|
|
import { StateInterface } from 'src/store';
|
2020-10-31 14:09:02 +00:00
|
|
|
import { FG_Plugin } from 'src/plugins';
|
|
|
|
import routes from 'src/router/routes';
|
2020-10-12 21:49:05 +00:00
|
|
|
|
2020-10-14 20:27:20 +00:00
|
|
|
const config = {
|
|
|
|
// Do not change required Modules !!
|
2020-10-31 14:09:02 +00:00
|
|
|
requiredModules: ['User'],
|
2020-10-14 20:27:20 +00:00
|
|
|
// here you can import plugins.
|
2020-10-31 16:33:40 +00:00
|
|
|
loadModules: ['Balance']
|
2020-10-14 20:27:20 +00:00
|
|
|
};
|
2020-10-12 21:49:05 +00:00
|
|
|
|
2020-10-14 20:27:20 +00:00
|
|
|
// do not change anything here !!
|
|
|
|
|
|
|
|
// combine routes from source to target
|
2020-10-31 14:09:02 +00:00
|
|
|
|
|
|
|
function combineRoutes(
|
2020-10-13 18:17:00 +00:00
|
|
|
target: RouteConfig[],
|
2020-10-31 14:09:02 +00:00
|
|
|
source: FG_Plugin.PluginRouteConfig[],
|
|
|
|
mainPath: '/' | '/main' = '/'
|
2020-10-13 18:17:00 +00:00
|
|
|
): RouteConfig[] {
|
2020-10-31 14:09:02 +00:00
|
|
|
target.forEach(target => {
|
|
|
|
if (target.path === mainPath) {
|
|
|
|
console.log('target', target.path);
|
|
|
|
source.forEach((sourceMainConfig: FG_Plugin.PluginRouteConfig) => {
|
|
|
|
console.log('sourceMainconfig', sourceMainConfig);
|
|
|
|
const targetMainConfig = target.children?.find(
|
|
|
|
(targetMainConfig: RouteConfig) => {
|
|
|
|
return sourceMainConfig.path === targetMainConfig.path;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (targetMainConfig) {
|
|
|
|
const sourceChildren: RouteConfig[] = [];
|
|
|
|
sourceMainConfig.children?.forEach(child => {
|
|
|
|
sourceChildren.push(<RouteConfig>child);
|
|
|
|
});
|
|
|
|
if (targetMainConfig.children) {
|
|
|
|
targetMainConfig.children = Object.assign(
|
|
|
|
targetMainConfig.children,
|
|
|
|
sourceChildren
|
2020-10-18 23:45:06 +00:00
|
|
|
);
|
2020-10-13 18:17:00 +00:00
|
|
|
} else {
|
2020-10-31 14:09:02 +00:00
|
|
|
targetMainConfig.children = sourceChildren;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (target.children === undefined) {
|
|
|
|
target.children = [];
|
2020-10-13 18:17:00 +00:00
|
|
|
}
|
2020-10-31 14:09:02 +00:00
|
|
|
target.children.push(<RouteConfig>sourceMainConfig);
|
2020-10-13 18:17:00 +00:00
|
|
|
}
|
2020-10-31 14:09:02 +00:00
|
|
|
});
|
2020-10-13 18:17:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2020-10-14 20:27:20 +00:00
|
|
|
// combine Links of Plugins from source to target
|
2020-10-31 14:09:02 +00:00
|
|
|
function combineMainLinks(
|
|
|
|
target: FG_Plugin.PluginMainLink[],
|
|
|
|
source: FG_Plugin.PluginRouteConfig
|
|
|
|
): FG_Plugin.PluginMainLink[] {
|
|
|
|
const targetPluginMainLink:
|
|
|
|
| FG_Plugin.PluginMainLink
|
|
|
|
| undefined = target.find(
|
|
|
|
(targetPluginMainLink: FG_Plugin.PluginMainLink) => {
|
2020-10-13 18:17:00 +00:00
|
|
|
console.log(targetPluginMainLink.title, source.title);
|
|
|
|
return targetPluginMainLink.title == source.title;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (targetPluginMainLink) {
|
2020-10-31 14:09:02 +00:00
|
|
|
source.children?.forEach(
|
|
|
|
(sourcePluginChildLink: FG_Plugin.PluginRouteConfig) => {
|
|
|
|
targetPluginMainLink.children.push(<FG_Plugin.PluginChildLink>{
|
|
|
|
title: sourcePluginChildLink.title,
|
|
|
|
icon: sourcePluginChildLink.icon,
|
|
|
|
link: sourcePluginChildLink.name,
|
2020-10-31 16:33:09 +00:00
|
|
|
name: sourcePluginChildLink.name,
|
|
|
|
permissions: sourcePluginChildLink.meta?.permissions
|
2020-10-31 14:09:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2020-10-13 18:17:00 +00:00
|
|
|
} else {
|
2020-10-31 14:09:02 +00:00
|
|
|
const mainLink: FG_Plugin.PluginMainLink = <FG_Plugin.PluginMainLink>{
|
|
|
|
title: source.title,
|
|
|
|
icon: source.icon,
|
|
|
|
link: source.name,
|
2020-10-31 16:33:09 +00:00
|
|
|
name: source.name,
|
|
|
|
permissions: source.meta?.permissions
|
2020-10-31 14:09:02 +00:00
|
|
|
};
|
|
|
|
source.children?.forEach(child => {
|
|
|
|
if (mainLink.children === undefined) {
|
|
|
|
mainLink.children = [];
|
|
|
|
}
|
|
|
|
mainLink.children.push(<FG_Plugin.PluginChildLink>{
|
|
|
|
title: child.title,
|
|
|
|
icon: child.icon,
|
|
|
|
link: child.name,
|
2020-10-31 16:33:09 +00:00
|
|
|
name: child.name,
|
|
|
|
permissions: child.meta?.permissions
|
2020-10-31 14:09:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
target.push(mainLink);
|
2020-10-13 18:17:00 +00:00
|
|
|
}
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2020-10-31 14:09:02 +00:00
|
|
|
function loadShortCuts(
|
|
|
|
target: FG_Plugin.ShortCutLink[],
|
|
|
|
source: FG_Plugin.PluginRouteConfig[]
|
|
|
|
): FG_Plugin.ShortCutLink[] {
|
|
|
|
source.forEach(route => {
|
|
|
|
if (route.shortcut) {
|
|
|
|
target.push(<FG_Plugin.ShortCutLink>{
|
|
|
|
link: route.name,
|
2020-10-31 16:33:09 +00:00
|
|
|
icon: route.icon,
|
|
|
|
permissions: route.meta?.permissions
|
2020-10-31 14:09:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (route.children) {
|
|
|
|
target = loadShortCuts(target, route.children);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2020-10-14 20:27:20 +00:00
|
|
|
// loade plugins
|
2020-10-31 14:09:02 +00:00
|
|
|
function loadPlugin(
|
|
|
|
loadedPlugins: FG_Plugin.LoadedPlugins,
|
2020-10-14 20:27:20 +00:00
|
|
|
modules: string[],
|
|
|
|
plugins: Plugin[],
|
2020-10-16 06:45:40 +00:00
|
|
|
store: Store<any>
|
2020-10-31 14:09:02 +00:00
|
|
|
): FG_Plugin.LoadedPlugins {
|
2020-10-14 20:27:20 +00:00
|
|
|
modules.forEach(requiredModule => {
|
2020-10-31 14:09:02 +00:00
|
|
|
const plugin = <FG_Plugin.Plugin | undefined>plugins.find(plugin => {
|
2020-10-13 18:17:00 +00:00
|
|
|
return plugin.name == requiredModule;
|
|
|
|
});
|
|
|
|
if (plugin) {
|
2020-10-31 14:09:02 +00:00
|
|
|
if (plugin.mainRoutes) {
|
|
|
|
loadedPlugins.routes = combineRoutes(
|
|
|
|
loadedPlugins.routes,
|
|
|
|
plugin.mainRoutes,
|
|
|
|
'/main'
|
|
|
|
);
|
|
|
|
plugin.mainRoutes.forEach(route => {
|
|
|
|
loadedPlugins.mainLinks = combineMainLinks(
|
|
|
|
loadedPlugins.mainLinks,
|
|
|
|
route
|
|
|
|
);
|
|
|
|
});
|
|
|
|
loadedPlugins.shortcuts = loadShortCuts(
|
|
|
|
loadedPlugins.shortcuts,
|
|
|
|
plugin.mainRoutes
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (plugin.outRoutes) {
|
|
|
|
loadedPlugins.routes = combineRoutes(
|
|
|
|
loadedPlugins.routes,
|
|
|
|
plugin.outRoutes
|
|
|
|
);
|
|
|
|
loadedPlugins.shortcutsOut = loadShortCuts(
|
|
|
|
loadedPlugins.shortcutsOut,
|
|
|
|
plugin.outRoutes
|
|
|
|
);
|
|
|
|
}
|
2020-10-13 18:17:00 +00:00
|
|
|
if (plugin.store) {
|
2020-10-16 06:45:40 +00:00
|
|
|
console.log(plugin.store);
|
|
|
|
console.log(plugin.store.keys());
|
|
|
|
plugin.store.forEach((store_plugin, store_namespace) => {
|
|
|
|
store.registerModule(store_namespace, store_plugin);
|
2020-10-13 18:17:00 +00:00
|
|
|
});
|
|
|
|
}
|
2020-10-14 20:27:20 +00:00
|
|
|
loadedPlugins.plugins.push({
|
|
|
|
name: plugin.name,
|
|
|
|
version: plugin.version
|
|
|
|
});
|
2020-10-13 18:17:00 +00:00
|
|
|
} else {
|
|
|
|
console.exception(`Don't find required Plugin ${requiredModule}`);
|
|
|
|
}
|
|
|
|
});
|
2020-10-14 20:27:20 +00:00
|
|
|
return loadedPlugins;
|
|
|
|
}
|
2020-10-13 18:17:00 +00:00
|
|
|
|
2020-10-14 20:27:20 +00:00
|
|
|
// "async" is optional;
|
|
|
|
// more info on params: https://quasar.dev/quasar-cli/cli-documentation/boot-files#Anatomy-of-a-boot-file
|
2020-10-18 23:45:06 +00:00
|
|
|
export default boot<Store<StateInterface>>(({ Vue, router, store }) => {
|
2020-10-14 20:27:20 +00:00
|
|
|
const plugins: Plugin[] = [];
|
2020-10-31 14:09:02 +00:00
|
|
|
let loadedPlugins: FG_Plugin.LoadedPlugins = {
|
|
|
|
routes,
|
2020-10-14 20:27:20 +00:00
|
|
|
plugins: [],
|
|
|
|
mainLinks: [],
|
|
|
|
shortcuts: [],
|
|
|
|
shortcutsOut: []
|
|
|
|
};
|
|
|
|
|
|
|
|
// get all plugins
|
|
|
|
const pluginsContext = require.context('src/plugins', true, /.+\/plugin.ts$/);
|
|
|
|
pluginsContext.keys().forEach((fileName: string) => {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
|
|
plugins.push(pluginsContext(fileName).default);
|
2020-10-12 21:49:05 +00:00
|
|
|
});
|
2020-10-14 20:27:20 +00:00
|
|
|
|
|
|
|
// load plugins
|
|
|
|
loadedPlugins = loadPlugin(
|
|
|
|
loadedPlugins,
|
|
|
|
config.requiredModules,
|
|
|
|
plugins,
|
|
|
|
store
|
|
|
|
);
|
|
|
|
loadedPlugins = loadPlugin(loadedPlugins, config.loadModules, plugins, store);
|
|
|
|
|
|
|
|
console.log(loadedPlugins.routes);
|
|
|
|
|
|
|
|
// add new routes for plugins
|
|
|
|
router.addRoutes(loadedPlugins.routes);
|
|
|
|
|
|
|
|
// save plugins in VM-variable
|
2020-10-13 21:13:42 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
2020-10-14 20:27:20 +00:00
|
|
|
Vue.prototype.$flaschengeistPlugins = loadedPlugins;
|
2020-10-12 21:49:05 +00:00
|
|
|
});
|