1
- import { EXAMPLES } from "@/example-data/examples" ;
1
+ import fs from "node:fs" ;
2
+ import path from "node:path" ;
3
+ import { z } from "zod" ;
4
+
5
+ const ExampleMetaSchema = z
6
+ . object ( {
7
+ slug : z . string ( ) ,
8
+ name : z . string ( ) ,
9
+ description : z . string ( ) ,
10
+ template : z . string ( ) . optional ( ) ,
11
+ maintainedByCoreTeam : z . boolean ( ) ,
12
+ } )
13
+ . strict ( ) ;
14
+
15
+ type ExampleMeta = z . infer < typeof ExampleMetaSchema > ;
16
+
17
+ // Collect metadata from each example
18
+ const EXAMPLES : ExampleMeta [ ] = [ ] ;
19
+
20
+ // Get all directories in the examples folder
21
+ const examplesDir = path . join ( process . cwd ( ) + "../../../examples" ) ;
22
+ const examples = fs
23
+ . readdirSync ( examplesDir , { withFileTypes : true } )
24
+ . filter (
25
+ ( dirent ) =>
26
+ dirent . isDirectory ( ) &&
27
+ ! dirent . name . startsWith ( "." ) &&
28
+ dirent . name !== "node_modules"
29
+ )
30
+ . filter ( ( dirent ) => dirent . name !== "with-nextjs" )
31
+ // @ts -expect-error
32
+ . sort ( ( a , b ) => a . name - b . name )
33
+ . map ( ( dirent ) => dirent . name ) ;
34
+
35
+ for ( const example of examples ) {
36
+ const metaPath = path . join ( examplesDir , example , "meta.json" ) ;
37
+
38
+ // Check if meta.json exists
39
+ if ( fs . existsSync ( metaPath ) ) {
40
+ try {
41
+ const metaContent = fs . readFileSync ( metaPath , "utf8" ) ;
42
+ const metaJson = JSON . parse ( metaContent ) ;
43
+ EXAMPLES . push ( { ...metaJson , slug : example } ) ;
44
+ } catch ( error ) {
45
+ // @ts -expect-error
46
+ throw new Error ( error ) ;
47
+ }
48
+ }
49
+ }
50
+
51
+ // Validate examples against schema
52
+ const validatedExamples = z . array ( ExampleMetaSchema ) . parse ( EXAMPLES ) ;
2
53
3
54
export function ExamplesTable ( {
4
55
coreMaintained,
5
56
} : {
6
57
coreMaintained ?: boolean ;
7
58
} ) : JSX . Element {
8
59
return (
9
- < div className = "max-w-full overflow-auto " >
60
+ < div className = "overflow-auto max-w-full" >
10
61
< table >
11
62
< thead >
12
63
< tr >
@@ -19,20 +70,22 @@ export function ExamplesTable({
19
70
coreMaintained
20
71
? meta . maintainedByCoreTeam
21
72
: ! meta . maintainedByCoreTeam
22
- ) . map ( ( example ) => (
23
- < tr key = { example . slug } >
24
- < td >
25
- < a
26
- href = { `https://github.com/vercel/turborepo/tree/main/examples/${ example . slug } ` }
27
- rel = "noopener noreferrer"
28
- target = "_blank"
29
- >
30
- { example . slug }
31
- </ a >
32
- </ td >
33
- < td className = "sm:text-wrap" > { example . description } </ td >
34
- </ tr >
35
- ) ) }
73
+ ) . map ( ( example ) => {
74
+ return (
75
+ < tr key = { example . slug } >
76
+ < td >
77
+ < a
78
+ href = { `https://github.com/vercel/turborepo/tree/main/examples/${ example . slug } ` }
79
+ rel = "noopener noreferrer"
80
+ target = "_blank"
81
+ >
82
+ { example . name }
83
+ </ a >
84
+ </ td >
85
+ < td className = "sm:text-wrap" > { example . description } </ td >
86
+ </ tr >
87
+ ) ;
88
+ } ) }
36
89
</ tbody >
37
90
</ table >
38
91
</ div >
0 commit comments