@@ -6,6 +6,7 @@ import mimeScore, { FACET_SCORES } from 'mime-score';
6
6
import { mkdir , writeFile } from 'node:fs/promises' ;
7
7
import path from 'node:path' ;
8
8
import { fileURLToPath } from 'node:url' ;
9
+ import * as prettier from 'prettier' ;
9
10
10
11
const MIME_DB_URL =
11
12
'https://raw.githubusercontent.com/jshttp/mime-db/master/db.json' ;
@@ -23,6 +24,8 @@ type MimeScoreEntry = Omit<MimeEntry, 'extensions'> & {
23
24
score : number ;
24
25
} ;
25
26
27
+ const PRETTIER_OPTIONS = await prettier . resolveConfig ( __dirname ) ;
28
+
26
29
function normalizeTypes ( types : MimeDatabase ) {
27
30
const cloned : Record < string , MimeScoreEntry > = { } ;
28
31
const byExtension : Record < string , MimeScoreEntry > = { } ;
@@ -94,12 +97,16 @@ async function writeTypesFile(name: string, types: Record<string, string[]>) {
94
97
const filepath = path . join ( dirpath , `${ name } .ts` ) ;
95
98
await mkdir ( dirpath , { recursive : true } ) ;
96
99
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 ) ;
103
110
}
104
111
105
112
async function main ( ) {
0 commit comments