Files
mixtape/zero.Web.UI/App/components/globals.js
T

47 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-10-15 14:10:13 +02:00
// Globally register all base components for convenience, because they
// will be used very frequently. Components are registered using the
// PascalCased version of their file name.
2020-04-06 13:24:46 +02:00
import Vue from 'vue';
2020-10-15 14:10:13 +02:00
//const directories = ['buttons', 'forms', 'messages', 'tables', 'tabs'];
2020-05-06 15:22:51 +02:00
2020-10-15 14:10:13 +02:00
// TODO this file will import all vue component files with subdirectories
// if it contains a file "overlay.vue" it will create an "ui-overlay" component
// if another folder contains a file "overlay.vue" it is not used anymore or overridden.
// we don't want to add all files but only files where we define global component access in its settings
2020-04-06 13:24:46 +02:00
2020-10-15 14:10:13 +02:00
// https://webpack.js.org/guides/dependency-management/#require-context
const requireComponent = require.context(
// Look for files in the current directory
'.',
// Do look in subdirectories
true,
// .vue files
/[\w-]+\.vue$/
);
2020-04-06 13:24:46 +02:00
2020-10-15 14:10:13 +02:00
// For each matching file name...
requireComponent.keys().forEach((path) =>
2020-04-06 13:24:46 +02:00
{
let pathParts = path.split('/');
2020-10-15 14:10:13 +02:00
let fileName = pathParts[pathParts.length - 1];
// Get the component config
const componentConfig = requireComponent(path);
// Get the PascalCase version of the component name
const componentName = 'ui' + fileName
// Remove the "./_" from the beginning
2020-04-06 13:24:46 +02:00
.replace(/^\.\/_/, '')
2020-10-15 14:10:13 +02:00
// Remove the file extension from the end
2020-04-06 13:24:46 +02:00
.replace(/\.\w+$/, '')
2020-10-15 14:10:13 +02:00
// Split up kebabs
2020-04-06 13:24:46 +02:00
.split('-')
2020-10-15 14:10:13 +02:00
// Upper case
2020-04-06 13:24:46 +02:00
.map((kebab) => kebab.charAt(0).toUpperCase() + kebab.slice(1))
2020-10-15 14:10:13 +02:00
// Concatenated
2020-04-06 13:24:46 +02:00
.join('');
2020-10-15 14:10:13 +02:00
// Globally register the component
Vue.component(componentName, componentConfig.default || componentConfig);
});