You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
5.0 KiB

7 years ago
  1. 'use strict'
  2. /* global siteConfig */
  3. import Vue from 'vue'
  4. import VueRouter from 'vue-router'
  5. import VueClipboards from 'vue-clipboards'
  6. import VueSimpleBreakpoints from 'vue-simple-breakpoints'
  7. import VeeValidate from 'vee-validate'
  8. import { ApolloClient } from 'apollo-client'
  9. import { createPersistedQueryLink } from 'apollo-link-persisted-queries'
  10. // import { BatchHttpLink } from 'apollo-link-batch-http'
  11. import { createHttpLink } from 'apollo-link-http'
  12. import { InMemoryCache } from 'apollo-cache-inmemory'
  13. import VueApollo from 'vue-apollo'
  14. import Vuetify from 'vuetify'
  15. import Velocity from 'velocity-animate'
  16. import Hammer from 'hammerjs'
  17. import moment from 'moment'
  18. import VueMoment from 'vue-moment'
  19. import VueTour from 'vue-tour'
  20. import VueTreeNavigation from 'vue-tree-navigation'
  21. import store from './store'
  22. // ====================================
  23. // Load Modules
  24. // ====================================
  25. import boot from './modules/boot'
  26. import localization from './modules/localization'
  27. // ====================================
  28. // Load Helpers
  29. // ====================================
  30. import helpers from './helpers'
  31. // ====================================
  32. // Initialize Global Vars
  33. // ====================================
  34. window.WIKI = null
  35. window.boot = boot
  36. window.Hammer = Hammer
  37. moment.locale(siteConfig.lang)
  38. // ====================================
  39. // Initialize Apollo Client (GraphQL)
  40. // ====================================
  41. const graphQLEndpoint = window.location.protocol + '//' + window.location.host + '/graphql'
  42. const graphQLLink = createPersistedQueryLink().concat(
  43. createHttpLink({
  44. includeExtensions: true,
  45. uri: graphQLEndpoint,
  46. credentials: 'include',
  47. fetch: (uri, options) => {
  48. // Strip __typename fields from variables
  49. let body = JSON.parse(options.body)
  50. // body = body.map(bd => {
  51. // return ({
  52. // ...bd,
  53. // variables: JSON.parse(JSON.stringify(bd.variables), (key, value) => { return key === '__typename' ? undefined : value })
  54. // })
  55. // })
  56. body = {
  57. ...body,
  58. variables: JSON.parse(JSON.stringify(body.variables), (key, value) => { return key === '__typename' ? undefined : value })
  59. }
  60. options.body = JSON.stringify(body)
  61. // Inject authentication token
  62. options.headers.Authorization = `Bearer TODO`
  63. return fetch(uri, options)
  64. }
  65. })
  66. )
  67. window.graphQL = new ApolloClient({
  68. link: graphQLLink,
  69. cache: new InMemoryCache(),
  70. connectToDevTools: (process.env.node_env === 'development')
  71. })
  72. // ====================================
  73. // Initialize Vue Modules
  74. // ====================================
  75. Vue.config.productionTip = false
  76. Vue.use(VueRouter)
  77. Vue.use(VueApollo)
  78. Vue.use(VueClipboards)
  79. Vue.use(VueSimpleBreakpoints)
  80. Vue.use(localization.VueI18Next)
  81. Vue.use(helpers)
  82. Vue.use(VeeValidate, { events: '' })
  83. Vue.use(Vuetify)
  84. Vue.use(VueMoment, { moment })
  85. Vue.use(VueTour)
  86. Vue.use(VueTreeNavigation)
  87. Vue.prototype.Velocity = Velocity
  88. // ====================================
  89. // Register Vue Components
  90. // ====================================
  91. Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
  92. Vue.component('editor', () => import(/* webpackChunkName: "editor" */ './components/editor.vue'))
  93. Vue.component('login', () => import(/* webpackMode: "eager" */ './components/login.vue'))
  94. Vue.component('nav-footer', () => import(/* webpackMode: "eager" */ './components/common/nav-footer.vue'))
  95. Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/common/nav-header.vue'))
  96. Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))
  97. Vue.component('setup', () => import(/* webpackChunkName: "setup" */ './components/setup.vue'))
  98. Vue.component('v-card-chin', () => import(/* webpackMode: "eager" */ './components/common/v-card-chin.vue'))
  99. Vue.component('page', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/app.vue'))
  100. let bootstrap = () => {
  101. // ====================================
  102. // Notifications
  103. // ====================================
  104. window.addEventListener('beforeunload', () => {
  105. store.dispatch('startLoading')
  106. })
  107. const apolloProvider = new VueApollo({
  108. defaultClient: window.graphQL
  109. })
  110. // ====================================
  111. // Bootstrap Vue
  112. // ====================================
  113. const i18n = localization.init()
  114. window.WIKI = new Vue({
  115. el: '#root',
  116. components: {},
  117. mixins: [helpers],
  118. provide: apolloProvider.provide(),
  119. store,
  120. i18n
  121. })
  122. // ----------------------------------
  123. // Dispatch boot ready
  124. // ----------------------------------
  125. window.boot.notify('vue')
  126. // ====================================
  127. // Load Icons
  128. // ====================================
  129. import(/* webpackChunkName: "icons" */ './svg/icons.svg').then(icons => {
  130. document.body.insertAdjacentHTML('beforeend', icons.default)
  131. })
  132. }
  133. window.boot.onDOMReady(bootstrap)