1
+ import {
2
+ createExample ,
3
+ createRouterObj ,
4
+ createRouterObjAdvanced ,
5
+ extractUniqueFolderNames ,
6
+ organizeFilesByFolder ,
7
+ sortExamples
8
+ } from "@/util.js" ;
9
+ import { createReplComponent } from "@/ReplFactory.js" ;
10
+
11
+ const path = "/src/views/others/" ;
12
+
13
+ // Import single file components
14
+ const singleFileComponents = import . meta. glob ( '/src/views/others/*.vue' , {
15
+ eager : true ,
16
+ query : "?raw" ,
17
+ import : "default" ,
18
+ } ) ;
19
+
20
+ // Generate examples and router objects for single file components
21
+ let exampleList = Object . keys ( singleFileComponents ) . map ( key => {
22
+ const filename = key . replace ( path , "" ) . replace ( ".vue" , "" ) ;
23
+ return createExample ( filename ) ;
24
+ } ) ;
25
+
26
+ let othersRouterList = exampleList . map ( ( { name } ) => createRouterObj ( name , singleFileComponents , path ) ) ;
27
+
28
+ // Import components from folders
29
+ const folderComponents = import . meta. glob ( '/src/views/others/*/*.vue' , {
30
+ eager : true ,
31
+ query : "?raw" ,
32
+ import : "default" ,
33
+ } ) ;
34
+
35
+ // Extract folder names and generate examples for them
36
+ const folderNames = extractUniqueFolderNames ( folderComponents ) ;
37
+ exampleList = [ ...exampleList , ...folderNames . map ( createExample ) ] ;
38
+
39
+ // Organize folder components and generate router objects
40
+ const organizedFolders = organizeFilesByFolder ( folderComponents ) ;
41
+ Object . entries ( organizedFolders ) . forEach ( ( [ folderName , folderFiles ] ) => {
42
+ // Rename `${folderName}.vue` to `App.vue` if exists
43
+ const folderVue = `${ folderName } .vue` ;
44
+ if ( folderFiles [ folderVue ] ) {
45
+ folderFiles [ "App.vue" ] = folderFiles [ folderVue ] ;
46
+ delete folderFiles [ folderVue ] ;
47
+ }
48
+ const component = createReplComponent ( null , folderFiles ) ;
49
+ othersRouterList . push ( createRouterObjAdvanced ( folderName , component ) ) ;
50
+ } ) ;
51
+
52
+ // Sort examples if needed
53
+ const orderedList = [ ] ;
54
+ exampleList = sortExamples ( orderedList , exampleList ) ;
55
+
56
+ export const OthersButtonExamples = {
57
+ name : "Others" ,
58
+ examples : exampleList ,
59
+ link : "https://vuejs.org/guide/essentials/class-and-style.html" ,
60
+ } ;
61
+
62
+ export { othersRouterList } ;
0 commit comments