import { pascalCase } from './utils/index'
// NOTE
// `require.context` must be treated as a whole. by
// NO means you should split them up, as is required
// by the rollup plugin, rollup-plugin-require-context
// SEE https://github.com/elcarim5efil/rollup-plugin-require-context
const reqs = require.context('../components', true, /\/[^_]+\.vue$/)

export default {
  install (Vue) {
    const keys = reqs.keys()
    for (let i = 0; i < keys.length; i++) {
      const module = getModule(reqs(keys[i]))

      // turn components' names to Pascal Case
      // so that we can use markups like `<CSelect />`
      // which would meet the needs of those PascalCase fans
      // TODO
      // we will turn all `name` fields in SFC into pacal case in the future
      module.name && Vue.component(pascalCase(module.name), module)
    }
  }
}

function getModule (module) {
  return (module.__esModule && module.default) || module
}

@@ -497,17 +497,134 @@
 ys%5Bi%5D))%0A
-%0A
+      if (typeof module.install === 'function') %7B%0A        Vue.use(module)%0A      %7D else if (module && module.name) %7B%0A  
       //
@@ -662,16 +662,18 @@
 al Case%0A
+  
       //
@@ -721,24 +721,26 @@
 t /%3E%60%0A      
+  
 // which wou
@@ -792,16 +792,18 @@
     
+  
 // TODO%0A
     
@@ -798,16 +798,18 @@
 // TODO%0A
+  
       //
@@ -887,22 +887,9 @@
     
-module.name &&
+ 
  Vue
@@ -928,24 +928,32 @@
 e), module)%0A
+      %7D%0A
     %7D%0A  %7D%0A%7D%0A

support `Vue.use` when install components