1+ import { existsSync , readdirSync , readFileSync } from 'node:fs' ;
12import { resolve as pResolve } from 'node:path' ;
2- import { FsUtility } from './fs-utility' ;
33
44/**
55 * Reads all content type schema files from a directory
66 * @param dirPath - Path to content types directory
77 * @param ignoredFiles - Files to ignore (defaults to schema.json, .DS_Store, __master.json, __priority.json)
8- * @returns Array of content type schemas
8+ * @returns Array of content type schemas (empty if the path is missing or has no eligible files)
99 */
1010export function readContentTypeSchemas (
1111 dirPath : string ,
1212 ignoredFiles : string [ ] = [ 'schema.json' , '.DS_Store' , '__master.json' , '__priority.json' , 'field_rules_uid.json' ] ,
13- ) : Record < string , unknown > [ ] | null {
14- const fsUtil = new FsUtility ( ) ;
15- const files = fsUtil . readdir ( dirPath ) ;
13+ ) : Record < string , unknown > [ ] {
14+ if ( ! existsSync ( dirPath ) ) {
15+ return [ ] ;
16+ }
17+
18+ const files = readdirSync ( dirPath ) ;
1619
1720 if ( ! files || files . length === 0 ) {
18- return null ;
21+ return [ ] ;
1922 }
2023
2124 const contentTypes : Record < string , unknown > [ ] = [ ] ;
@@ -33,7 +36,8 @@ export function readContentTypeSchemas(
3336
3437 try {
3538 const filePath = pResolve ( dirPath , file ) ;
36- const contentType = fsUtil . readFile ( filePath ) ;
39+ const raw = readFileSync ( filePath , 'utf8' ) ;
40+ const contentType = JSON . parse ( raw ) as Record < string , unknown > ;
3741 if ( contentType ) {
3842 contentTypes . push ( contentType as Record < string , unknown > ) ;
3943 }
0 commit comments