1+ import fs from 'fs' ;
2+ import path from 'path' ;
3+
4+ interface DocsConfig {
5+ navigation : {
6+ tabs : Array < {
7+ tab : string ;
8+ pages ?: string [ ] ;
9+ groups ?: Array < {
10+ group : string ;
11+ pages : Array < string | { group : string ; pages : string [ ] } > ;
12+ } > ;
13+ versions ?: Array < {
14+ version : string ;
15+ openapi ?: string ;
16+ groups ?: Array < {
17+ group : string ;
18+ pages : string [ ] ;
19+ } > ;
20+ } > ;
21+ } > ;
22+ } ;
23+ }
24+
25+ function extractAllPages ( config : DocsConfig ) : Set < string > {
26+ const pages = new Set < string > ( ) ;
27+
28+ function processPages ( pageList : Array < string | { group : string ; pages : string [ ] | Array < string | { group : string ; pages : string [ ] } > } > ) : void {
29+ for ( const item of pageList ) {
30+ if ( typeof item === 'string' ) {
31+ pages . add ( item ) ;
32+ } else if ( item . group && item . pages ) {
33+ processPages ( item . pages as any ) ;
34+ }
35+ }
36+ }
37+
38+ for ( const tab of config . navigation . tabs ) {
39+ if ( tab . pages ) {
40+ processPages ( tab . pages as any ) ;
41+ }
42+
43+ if ( tab . groups ) {
44+ for ( const group of tab . groups ) {
45+ processPages ( group . pages as any ) ;
46+ }
47+ }
48+
49+ if ( tab . versions ) {
50+ for ( const version of tab . versions ) {
51+ if ( version . openapi ) {
52+ pages . add ( version . openapi . replace ( / ^ \/ / , '' ) ) ;
53+ }
54+ if ( version . groups ) {
55+ for ( const group of version . groups ) {
56+ processPages ( group . pages as any ) ;
57+ }
58+ }
59+ }
60+ }
61+ }
62+
63+ return pages ;
64+ }
65+
66+ function validatePageExists ( pagePath : string ) : boolean {
67+ // Check if the path already has a file extension (.json, .mdx, etc.)
68+ const ext = path . extname ( pagePath ) ;
69+ if ( ext === '.json' || ext === '.mdx' ) {
70+ return fs . existsSync ( pagePath ) ;
71+ }
72+
73+ // Otherwise check for .mdx or .json extensions
74+ const mdxPath = `${ pagePath } .mdx` ;
75+
76+ return fs . existsSync ( mdxPath ) ;
77+ }
78+
79+ async function main ( ) : Promise < void > {
80+ try {
81+ const docsConfig : DocsConfig = JSON . parse ( fs . readFileSync ( 'docs.json' , 'utf8' ) ) ;
82+ const allPages = extractAllPages ( docsConfig ) ;
83+
84+ console . log ( `Found ${ allPages . size } page references in docs.json` ) ;
85+
86+ const missingPages : string [ ] = [ ] ;
87+ const existingPages : string [ ] = [ ] ;
88+
89+ for ( const page of allPages ) {
90+ if ( validatePageExists ( page ) ) {
91+ existingPages . push ( page ) ;
92+ } else {
93+ missingPages . push ( page ) ;
94+ }
95+ }
96+
97+ console . log ( `✅ ${ existingPages . length } pages found` ) ;
98+
99+ if ( missingPages . length > 0 ) {
100+ console . error ( `❌ ${ missingPages . length } missing pages:` ) ;
101+ for ( const page of missingPages . sort ( ) ) {
102+ console . error ( ` - ${ page } ` ) ;
103+ }
104+ process . exit ( 1 ) ;
105+ } else {
106+ console . log ( '🎉 All pages referenced in docs.json exist!' ) ;
107+ }
108+
109+ } catch ( error ) {
110+ console . error ( 'Error validating docs:' , error ) ;
111+ process . exit ( 1 ) ;
112+ }
113+ }
114+
115+ if ( require . main === module ) {
116+ main ( ) ;
117+ }
0 commit comments