Skip to content

Commit 5cf3385

Browse files
Adding configuration to filter route in dev
1 parent 3633756 commit 5cf3385

File tree

10 files changed

+66
-27
lines changed

10 files changed

+66
-27
lines changed

.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VUE_APP_SHOW_ALL_EXAMPLES=false
2+
VUE_APP_FILTER_ROUTE=

.env.development

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
VUE_APP_SHOW_ALL_EXAMPLES=false
2+
VUE_APP_FILTER_ROUTE=

.env.local

-1
This file was deleted.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ test/tmp
1010
/examples/src
1111
/examples/libs/
1212
/coverage
13+
14+
.env.local

example/App.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ export default {
152152
name: "app",
153153
components,
154154
data() {
155-
const componentList = Object.keys(components)
156-
.map(key => components[key])
155+
const componentList = Object.values(components)
156+
.filter(component => component.show)
157157
.sort((a, b) => a.order - b.order);
158158
return {
159159
componentList

example/components/headerslot.vue

+7-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<button class="btn btn-secondary" @click="replace">Replace</button>
2929
</div>
3030
</template>
31-
3231
</draggable>
3332
</div>
3433

@@ -44,26 +43,26 @@ export default {
4443
display: "Header slot",
4544
order: 13,
4645
components: {
47-
draggable,
46+
draggable
4847
},
4948
data() {
5049
return {
5150
list: [
5251
{ name: "John 1", id: 0 },
5352
{ name: "Joao 2", id: 1 },
54-
{ name: "Jean 3", id: 2 },
53+
{ name: "Jean 3", id: 2 }
5554
],
56-
dragging: false,
55+
dragging: false
5756
};
5857
},
5958
methods: {
60-
add: function () {
59+
add: function() {
6160
this.list.push({ name: "Juan " + id, id: id++ });
6261
},
63-
replace: function () {
62+
replace: function() {
6463
this.list = [{ name: "Edgard", id: id++ }];
65-
},
66-
},
64+
}
65+
}
6766
};
6867
</script>
6968
<style scoped></style>

example/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createApp } from "vue";
22
import App from "./App.vue";
3-
import { createRouter, createWebHistory } from 'vue-router'
3+
import { createRouter, createWebHistory } from "vue-router";
44

55
import routes from "./route";
66
import rawDisplayer from "./components/infra/raw-displayer";
@@ -19,4 +19,4 @@ const app = createApp(App);
1919
app.use(store);
2020
app.use(router);
2121
app.component("rawDisplayer", rawDisplayer);
22-
router.isReady().then(() => app.mount('#app'));
22+
router.isReady().then(() => app.mount("#app"));

example/route.js

+47-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,63 @@
11
function getRouteFromDirectory(ctx) {
22
return ctx.keys().map(key => ({
33
path: key.substring(1).replace(".vue", ""),
4-
component: ctx(key).default,
4+
component: ctx(key).default
55
}));
66
}
77

8-
const showAll = process.env.VUE_APP_SHOW_ALL_EXAMPLES === "true";
9-
window.console.log(process.env.VUE_APP_SHOW_ALL_EXAMPLES);
8+
const showDebug = process.env.VUE_APP_SHOW_ALL_EXAMPLES === "true";
9+
window.console.log(showDebug);
10+
11+
function getRouteFilterFromConfiguration(configuration) {
12+
const routeFromConfiguration = configuration
13+
.split(",")
14+
.filter(value => value !== "");
15+
if (routeFromConfiguration == []) {
16+
return () => true;
17+
}
18+
19+
window.console.log(
20+
`Using route filter VUE_APP_FILTER_ROUTE: "${configuration}"`
21+
);
22+
return name => routeFromConfiguration.includes(name);
23+
}
24+
25+
const filterRoute = getRouteFilterFromConfiguration(
26+
process.env.VUE_APP_FILTER_ROUTE
27+
);
1028

1129
const routes = [
1230
...getRouteFromDirectory(require.context("./components/", false, /\.vue$/)),
13-
...(!showAll
31+
...(!showDebug
1432
? []
1533
: getRouteFromDirectory(
1634
require.context("./debug-components/", false, /\.vue$/)
17-
)),
18-
{
19-
path: "/",
20-
redirect: "/simple",
21-
},
35+
))
2236
];
37+
routes.forEach(
38+
route => (route.component.show = filterRoute(route.component.display))
39+
);
2340

24-
window.console.log(routes);
41+
const filteredRoutes = routes.filter(route => route.component.show);
2542

43+
if (filteredRoutes.length === 0) {
44+
throw new Error(
45+
`No routes to match "${
46+
process.env.VUE_APP_FILTER_ROUTE
47+
}". Available route: ${routes
48+
.map(route => `"${route.component.display}"`)
49+
.join(", ")} .Please check env variable: VUE_APP_FILTER_ROUTE`
50+
);
51+
}
52+
53+
const redirect = filteredRoutes.some(r => r.path === "/simple")
54+
? "/simple"
55+
: filteredRoutes[0].path;
56+
57+
const allRoutes = [
58+
...filteredRoutes,
59+
{ path: "/", redirect },
60+
{ path: "/:pathMatch(.*)*", redirect }
61+
];
2662

27-
export default routes;
63+
export default allRoutes;

example/store.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { createStore } from "vuex";
44
const store = createStore({
55
namespaced: true,
66
modules: {
7-
nested,
8-
},
7+
nested
8+
}
99
});
1010

1111
export default store;

src/util/tags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const tags = [
115115
"ul",
116116
"var",
117117
"video",
118-
"wbr",
118+
"wbr"
119119
];
120120

121121
function isHtmlTag(name) {

0 commit comments

Comments
 (0)