index.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { App } from "vue"
  2. import { pipe } from "fp-ts/function"
  3. import * as A from "fp-ts/Array"
  4. import { RouteLocationNormalized, Router } from "vue-router"
  5. export type HoppModule = {
  6. /**
  7. * Define this function to get access to Vue App instance and augment
  8. * it (installing components, directives and plugins). Also useful for
  9. * early generic initializations. This function should be called first
  10. */
  11. onVueAppInit?: (app: App) => void
  12. /**
  13. * Called when the router is done initializing.
  14. * Used if a module requires access to the router instance
  15. */
  16. onRouterInit?: (app: App, router: Router) => void
  17. /**
  18. * Called when the root component (App.vue) is running setup.
  19. * This function is generally called last in the lifecycle.
  20. * This function executes with a component setup context, so you can
  21. * run composables within this and it should just be scoped to the
  22. * root component
  23. */
  24. onRootSetup?: () => void
  25. /**
  26. * Called by the router to tell all the modules before a route navigation
  27. * is made.
  28. */
  29. onBeforeRouteChange?: (
  30. to: RouteLocationNormalized,
  31. from: RouteLocationNormalized,
  32. router: Router
  33. ) => void
  34. /**
  35. * Called by the router to tell all the modules that a route navigation has completed
  36. */
  37. onAfterRouteChange?: (to: RouteLocationNormalized, router: Router) => void
  38. }
  39. /**
  40. * All the modules Hoppscotch loads into the app
  41. */
  42. export const HOPP_MODULES = pipe(
  43. import.meta.glob("@modules/*.ts", { eager: true }),
  44. Object.values,
  45. A.map(({ default: defaultVal }) => defaultVal as HoppModule)
  46. )