flaschengeist-frontend/src/boot/plugins.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

import { boot } from 'quasar/wrappers';
import { RouteConfig } from 'vue-router';
import { Module } from 'vuex';
interface PluginRouteConfig extends RouteConfig {
example?: unknown;
}
interface EssentialLink {
title: string;
link: string;
icon?: string;
}
interface Plugin {
router: PluginRouteConfig[];
2020-10-13 09:27:27 +00:00
store?: Module<never, never>;
mainLink: PluginMainLink;
}
2020-10-13 09:27:27 +00:00
interface PluginMainLink extends PluginChildLink {
children: PluginChildLink[] | [];
}
interface PluginChildLink {
name: string;
title: string;
link: string;
icon: string;
}
export { PluginRouteConfig, Plugin, PluginChildLink, PluginMainLink };
// "async" is optional;
// more info on params: https://quasar.dev/quasar-cli/cli-documentation/boot-files#Anatomy-of-a-boot-file
2020-10-13 09:27:27 +00:00
export default boot(({ Vue, router }) => {
const plugins = require.context('src/plugins', true, /.+\/plugin.ts$/);
const pluginMainLinks: PluginMainLink[] = [];
plugins.keys().forEach((fileName: string) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
router.addRoutes(plugins(fileName).default.router);
2020-10-13 09:27:27 +00:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
pluginMainLinks.push(plugins(fileName).default.mainLink);
});
2020-10-13 09:27:27 +00:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Vue.prototype.$flaschengeist_plugins = pluginMainLinks;
console.log(plugins);
});