import { App } from 'vue';

export default {
  install(app: App) {
    const components = import.meta.glob('../components/**/*.vue');

    for (const path in components) {
      if (Object.prototype.hasOwnProperty.call(components, path)) {
        const componentName = path
          .split('/')
          .slice(2) // 去掉 `../components/`
          .join('/')
          .replace('.vue', '');

        components[path]().then((module: any) => {
          app.component(componentName, module.default);
        });
      }
    }
  },
};
