Skip to content

Commit

Permalink
refactor: small refact on app bootstrap files
Browse files Browse the repository at this point in the history
  • Loading branch information
João Antônio Hamerski Copetti committed Feb 4, 2024
1 parent 3ea2b47 commit 28630b8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 44 deletions.
16 changes: 0 additions & 16 deletions src/boot.ts

This file was deleted.

49 changes: 49 additions & 0 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type { App } from 'vue'
import { createPinia } from 'pinia'
import { autoAnimatePlugin } from '@formkit/auto-animate/vue'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'

export default class Bootstrap {
protected app

constructor(app: App) {
this.app = app
}

addAutoAnimate() {
this.app.use(autoAnimatePlugin)

return this
}

addPinia() {
const pinia = createPinia()

this.app.use(pinia)

return this
}

addFontAwesome() {
this.app.component('FWIcon', FontAwesomeIcon)

return this
}

addGlobalComponents() {
const components = import.meta.glob('./**/App*.vue', {
eager: true,
})

Object.entries(components).forEach(([path, definition]: [string, any]) => {
const componentName = path
.split('/')
.pop()!
.replace(/\.\w+$/, '')

this.app.component(componentName, definition.default)
})

return this
}
}
18 changes: 0 additions & 18 deletions src/components/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/libs/fontawesome.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { App } from 'vue'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { library } from '@fortawesome/fontawesome-svg-core'

import { faGithubAlt } from '@fortawesome/free-brands-svg-icons/faGithubAlt'
Expand Down Expand Up @@ -39,9 +37,3 @@ library.add(
faCircleXmark,
faCircleCheck,
)

const registerFontAwesomeComponent = (app: App<Element>) => {
app.component('FWIcon', FontAwesomeIcon)
}

export default registerFontAwesomeComponent
13 changes: 11 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { createApp } from 'vue'
import { initResources } from './boot'
import './css/main.css'
import './libs/fontawesome'

import App from './App.vue'
import Bootstrap from './bootstrap'

const app = createApp(App)
const bootstrap = new Bootstrap(app)

initResources(app)
// prettier-ignore
bootstrap
.addPinia()
.addGlobalComponents()
.addAutoAnimate()
.addFontAwesome()

app.mount('#app')

0 comments on commit 28630b8

Please sign in to comment.