2023-09-01 12:09:58 +00:00
|
|
|
import type { InitModule, InitModuleContext } from '~/types'
|
2022-07-21 19:36:08 +00:00
|
|
|
|
2022-05-03 00:30:43 +00:00
|
|
|
import store, { key } from '~/store'
|
2022-10-18 21:48:47 +00:00
|
|
|
import router from '~/router'
|
|
|
|
|
2022-06-30 02:30:32 +00:00
|
|
|
import { createApp, defineAsyncComponent, h } from 'vue'
|
2022-10-18 21:48:47 +00:00
|
|
|
|
2022-04-18 18:39:30 +00:00
|
|
|
import useLogger from '~/composables/useLogger'
|
2022-04-23 07:26:25 +00:00
|
|
|
import useTheme from '~/composables/useTheme'
|
2022-05-01 19:57:22 +00:00
|
|
|
|
2023-01-30 19:41:20 +00:00
|
|
|
import '~/style/_main.scss'
|
|
|
|
|
2022-10-18 21:48:47 +00:00
|
|
|
import '~/api'
|
|
|
|
|
2022-05-01 19:57:22 +00:00
|
|
|
// NOTE: Set the theme as fast as possible
|
2022-04-23 07:26:25 +00:00
|
|
|
useTheme()
|
2022-04-18 00:40:34 +00:00
|
|
|
|
2022-04-18 18:39:30 +00:00
|
|
|
const logger = useLogger()
|
|
|
|
logger.info('Loading environment:', import.meta.env.MODE)
|
|
|
|
logger.debug('Environment variables:', import.meta.env)
|
2022-04-17 22:43:58 +00:00
|
|
|
|
|
|
|
const app = createApp({
|
2022-04-19 19:40:25 +00:00
|
|
|
name: 'Root',
|
|
|
|
data: () => ({ ready: false }),
|
|
|
|
mounted () {
|
|
|
|
this.ready = true
|
2023-09-01 12:09:58 +00:00
|
|
|
logger.info('Everything loaded!')
|
2022-04-17 23:24:50 +00:00
|
|
|
},
|
2022-04-19 19:40:25 +00:00
|
|
|
render () {
|
|
|
|
if (this.ready) {
|
|
|
|
return h(defineAsyncComponent(() => import('~/App.vue')))
|
2022-04-17 23:24:50 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 19:40:25 +00:00
|
|
|
return null
|
2022-04-17 23:24:50 +00:00
|
|
|
}
|
2022-04-17 22:43:58 +00:00
|
|
|
})
|
|
|
|
|
2022-04-18 16:17:51 +00:00
|
|
|
app.use(router)
|
2022-05-03 00:30:43 +00:00
|
|
|
app.use(store, key)
|
2022-04-17 22:43:58 +00:00
|
|
|
|
2023-09-01 12:09:58 +00:00
|
|
|
const modules: Record<string | 'axios', { install?: InitModule }> = import.meta.glob('./init/*.ts', { eager: true })
|
|
|
|
const moduleContext: InitModuleContext = {
|
|
|
|
app,
|
|
|
|
router,
|
|
|
|
store
|
2022-04-17 22:43:58 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 12:09:58 +00:00
|
|
|
// NOTE: Other modules may depend on network requests and we need to ensure
|
|
|
|
// that all axios interceptors are set before any requests are made
|
|
|
|
// and that the instance url is set before any requests are made
|
|
|
|
const IMPORTANT_MODULES_QUEUE = ['axios', 'instance']
|
|
|
|
const waitForImportantModules = async () => {
|
|
|
|
for (const moduleName of IMPORTANT_MODULES_QUEUE) {
|
|
|
|
const path = `./init/${moduleName}.ts`
|
|
|
|
if (!(path in modules)) {
|
|
|
|
logger.error(`Failed to load important module: ${path}`)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
await modules[path].install?.(moduleContext)
|
|
|
|
delete modules[path]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
waitForImportantModules()
|
|
|
|
// NOTE: We load the modules in parallel
|
|
|
|
.then(() => Promise.all(Object.values(modules).map(module => module.install?.(moduleContext))))
|
|
|
|
.catch(error => logger.error('Failed to load modules:', error))
|
|
|
|
// NOTE: We need to mount the app after all modules are loaded
|
|
|
|
.finally(() => app.mount('#app'))
|
2022-05-01 15:06:01 +00:00
|
|
|
|
2022-05-06 19:41:36 +00:00
|
|
|
// TODO (wvffle): Rename filters from useSharedLabels to filters from backend
|