Skip to content

Commit

Permalink
Added install method
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Dec 5, 2018
1 parent ec8b69b commit 9864228
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 1 addition & 4 deletions docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ Vue.use(VueRouter)
Vue.use(VueClipboard)
Vue.use(BootstrapVue)
Vue.use(VueHighlightJS)
Vue.use(Collection)

Vue.component('ApiTable', ApiTable)
Vue.component('SampleCard', SampleCard)
Vue.component('PalettePresenter', PalettePresenter)

Object.keys(Collection.components).forEach(key => {
Vue.component(key, Collection.components[key])
})

Collection.config.set('project.name', 'Demo Project')

/* eslint-disable no-new */
Expand Down
14 changes: 10 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { basename, extname } from 'path'
export { default as config } from './config'
export { default as ContentPlaceholder } from './components/ContentPlaceholder.vue'
export { default as DonateForm } from './components/DonateForm.vue'
Expand All @@ -17,13 +18,18 @@ class Collection {
return require('./config.js').default
}
static get components() {
const context = require.context("./components/", true, /\.(js)|(vue)$/);
return context.keys().reduce((components, key) => {
const name = key.split('.vue').shift().split('.js').shift().split('./').pop()
components[name] = context(key).default;
const context = require.context("./components/", true, /\.(js)|(vue)$/, 'lazy');
return context.keys().reduce((components, path) => {
const name = basename(path, extname(path))
const filename = basename(path)
components[name] = () => import(`./components/${filename}`);
return components
}, {});
}
static install (Vue, options) {
const components = Collection.components
Object.keys(components).forEach(key => Vue.component(key, components[key]))
}
}

export default Collection

0 comments on commit 9864228

Please sign in to comment.