@@ -6,6 +6,7 @@ import mimeScore, { FACET_SCORES } from 'mime-score';
66import { mkdir , writeFile } from 'node:fs/promises' ;
77import path from 'node:path' ;
88import { fileURLToPath } from 'node:url' ;
9+ import * as prettier from 'prettier' ;
910
1011const MIME_DB_URL =
1112 'https://raw.githubusercontent.com/jshttp/mime-db/master/db.json' ;
@@ -23,6 +24,8 @@ type MimeScoreEntry = Omit<MimeEntry, 'extensions'> & {
2324 score : number ;
2425} ;
2526
27+ const PRETTIER_OPTIONS = await prettier . resolveConfig ( __dirname ) ;
28+
2629function normalizeTypes ( types : MimeDatabase ) {
2730 const cloned : Record < string , MimeScoreEntry > = { } ;
2831 const byExtension : Record < string , MimeScoreEntry > = { } ;
@@ -94,12 +97,16 @@ async function writeTypesFile(name: string, types: Record<string, string[]>) {
9497 const filepath = path . join ( dirpath , `${ name } .ts` ) ;
9598 await mkdir ( dirpath , { recursive : true } ) ;
9699
97- await writeFile (
98- filepath ,
99- `const types : {[key: string]: string[]} = ${ JSON . stringify ( types ) } ;
100- Object.freeze(types);
101- export default types;` ,
102- ) ;
100+ let source = `const types : {[key: string]: string[]} = ${ JSON . stringify ( types ) } ;
101+ Object.freeze(types);
102+ export default types;` ;
103+
104+ source = await prettier . format ( source , {
105+ parser : 'typescript' ,
106+ ...PRETTIER_OPTIONS ,
107+ } ) ;
108+
109+ await writeFile ( filepath , source ) ;
103110}
104111
105112async function main ( ) {
0 commit comments