1+ import * as fs from 'fs/promises' ;
2+ import * as path from 'path' ;
3+
4+ const rootDir = path . join ( process . cwd ( ) , 'pages' ) ;
5+ const errors : string [ ] = [ ] ;
6+
7+ async function checkDirectory ( dirPath : string ) : Promise < void > {
8+ const entries = await fs . readdir ( dirPath , { withFileTypes : true } ) ;
9+
10+ for ( const entry of entries ) {
11+ if ( entry . name . startsWith ( '_' ) || entry . name . startsWith ( '.' ) ) continue ;
12+
13+ const fullPath = path . join ( dirPath , entry . name ) ;
14+
15+ if ( entry . isDirectory ( ) ) {
16+ // Skip if it's the root directory
17+ if ( fullPath === rootDir ) continue ;
18+
19+ // Check if breadcrumb file exists for this directory
20+ const breadcrumbFile = path . join ( dirPath , `${ entry . name } .mdx` ) ;
21+ try {
22+ await fs . access ( breadcrumbFile ) ;
23+ } catch {
24+ const relativePath = path . relative ( rootDir , dirPath ) ;
25+ errors . push ( `Missing breadcrumb file for directory: ${ relativePath } /${ entry . name } ` ) ;
26+ }
27+
28+ // Recursively check subdirectories
29+ await checkDirectory ( fullPath ) ;
30+ }
31+ }
32+ }
33+
34+ async function main ( ) {
35+ try {
36+ await checkDirectory ( rootDir ) ;
37+
38+ if ( errors . length > 0 ) {
39+ console . error ( 'Breadcrumb check failed:' ) ;
40+ errors . forEach ( error => console . error ( `- ${ error } ` ) ) ;
41+ process . exit ( 1 ) ;
42+ } else {
43+ console . log ( 'All directories have breadcrumb files.' ) ;
44+ }
45+ } catch ( error ) {
46+ console . error ( 'Error checking breadcrumbs:' , error ) ;
47+ process . exit ( 1 ) ;
48+ }
49+ }
50+
51+ main ( ) ;
0 commit comments