mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
use glob to load plugins.
This commit is contained in:
parent
6272e48b67
commit
e0366905ad
3
.gitignore
vendored
3
.gitignore
vendored
@ -31,3 +31,6 @@ coverage
|
|||||||
|
|
||||||
test-results/
|
test-results/
|
||||||
playwright-report/
|
playwright-report/
|
||||||
|
|
||||||
|
/src/page/plugins/*
|
||||||
|
!/src/page/plugins/.gitkeep
|
||||||
|
@ -320,22 +320,29 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// plugins must be available at:
|
// plugins must be available at:
|
||||||
// ./plugins/{name}/main-tabs.vue
|
// ./plugins/{name}/index.ts -> { Components, Tabs }
|
||||||
// ./plugins/{name}/main-components.vue
|
const plugins = import.meta.glob('./plugins/*/index.ts')
|
||||||
let plugins = [] as string[]
|
|
||||||
|
const pluginsTabs = shallowRef<Record<string, any>>({})
|
||||||
|
const pluginsComponents = shallowRef<Record<string, any>>({})
|
||||||
|
|
||||||
// dynamic plugins loader
|
// dynamic plugins loader
|
||||||
//;(function (r: any) {
|
onMounted(async () => {
|
||||||
// r.keys().forEach((key: string) => {
|
const resolvedPlugins = await Promise.all(
|
||||||
// const found = key.match(/\.\/(.*?)\//)
|
Object.entries(plugins).map(async ([path, component]) => {
|
||||||
// if (found) {
|
return [path, await component()]
|
||||||
// plugins.push(found[1])
|
}),
|
||||||
// console.log('loading a plugin:', found[1])
|
) as [string, { Components: any, Tabs: any }][]
|
||||||
// }
|
|
||||||
// })
|
|
||||||
//})(require.context('./plugins/', true, /(main-tabs|main-components)\.vue$/))
|
|
||||||
|
|
||||||
import { ref, computed, onMounted } from 'vue'
|
pluginsTabs.value = {}
|
||||||
|
pluginsComponents.value = {}
|
||||||
|
for (const [path, { Components, Tabs }] of resolvedPlugins) {
|
||||||
|
pluginsTabs.value[path] = Tabs
|
||||||
|
pluginsComponents.value[path] = Components
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
import { ref, shallowRef, computed, onMounted } from 'vue'
|
||||||
|
|
||||||
import type { AxiosProgressEvent } from 'axios'
|
import type { AxiosProgressEvent } from 'axios'
|
||||||
import NekoCanvas from '@/component/main.vue'
|
import NekoCanvas from '@/component/main.vue'
|
||||||
@ -347,22 +354,6 @@ import NekoMembers from './components/members.vue'
|
|||||||
import NekoMedia from './components/media.vue'
|
import NekoMedia from './components/media.vue'
|
||||||
import NekoChat from './components/chat.vue'
|
import NekoChat from './components/chat.vue'
|
||||||
|
|
||||||
const pluginsTabs = computed(() => {
|
|
||||||
let x = {} as Record<string, any>
|
|
||||||
for (let p of plugins) {
|
|
||||||
x[p] = () => import('./plugins/' + p + '/main-tabs.vue')
|
|
||||||
}
|
|
||||||
return x
|
|
||||||
})
|
|
||||||
|
|
||||||
const pluginsComponents = computed(() => {
|
|
||||||
let x = {} as Record<string, any>
|
|
||||||
for (let p of plugins) {
|
|
||||||
x[p] = () => import('./plugins/' + p + '/main-components.vue')
|
|
||||||
}
|
|
||||||
return x
|
|
||||||
})
|
|
||||||
|
|
||||||
const neko = ref<typeof NekoCanvas>()
|
const neko = ref<typeof NekoCanvas>()
|
||||||
|
|
||||||
const expanded = ref(!window.matchMedia('(max-width: 600px)').matches) // default to expanded on bigger screens
|
const expanded = ref(!window.matchMedia('(max-width: 600px)').matches) // default to expanded on bigger screens
|
||||||
|
Loading…
Reference in New Issue
Block a user