@@ -17,25 +17,25 @@ function sortObjectKeys<T>(obj: T): T {
17
17
}
18
18
19
19
export function sortFiles ( ) {
20
- const filePath = new URL (
21
- "../../inputfiles/overridingTypes.jsonc" ,
22
- import . meta. url ,
23
- ) ; // Replace with your JSONC file path
20
+ const files = [ "overridingTypes" , "removedTypes" , "addedTypes" ] ;
21
+ files . forEach ( ( file ) => {
22
+ const filePath = new URL ( `../../inputfiles/${ file } .jsonc` , import . meta. url ) ; // Replace with your JSONC file path
24
23
25
- // Read the JSONC file content
26
- const fileContent = fs . readFileSync ( filePath , "utf-8" ) ;
24
+ // Read the JSONC file content
25
+ const fileContent = fs . readFileSync ( filePath , "utf-8" ) ;
27
26
28
- // Parse the JSONC file while preserving comments
29
- const parsed = commentJson . parse ( fileContent , undefined , true ) ;
27
+ // Parse the JSONC file while preserving comments
28
+ const parsed = commentJson . parse ( fileContent , undefined , true ) ;
30
29
31
- // Sort the object keys alphabetically (recursively)
32
- const sortedObject = sortObjectKeys ( parsed ) ;
30
+ // Sort the object keys alphabetically (recursively)
31
+ const sortedObject = sortObjectKeys ( parsed ) ;
33
32
34
- // Stringify the sorted object back to JSONC format (preserving comments)
35
- const sortedJsonC = commentJson . stringify ( sortedObject , null , 2 ) ;
33
+ // Stringify the sorted object back to JSONC format (preserving comments)
34
+ const sortedJsonC = commentJson . stringify ( sortedObject , null , 2 ) ;
36
35
37
- // Write the sorted content back to the file
38
- fs . writeFileSync ( filePath , sortedJsonC , "utf-8" ) ;
36
+ // Write the sorted content back to the file
37
+ fs . writeFileSync ( filePath , sortedJsonC , "utf-8" ) ;
38
+ } ) ;
39
39
40
40
console . log ( "JSONC file keys sorted successfully." ) ;
41
41
}
0 commit comments