Skip to content

Commit e526816

Browse files
authored
fix: format types files with prettier (#321)
1 parent 0516005 commit e526816

File tree

3 files changed

+1066
-10
lines changed

3 files changed

+1066
-10
lines changed

scripts/build.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import mimeScore, { FACET_SCORES } from 'mime-score';
66
import { mkdir, writeFile } from 'node:fs/promises';
77
import path from 'node:path';
88
import { fileURLToPath } from 'node:url';
9+
import * as prettier from 'prettier';
910

1011
const 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+
2629
function 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

105112
async function main() {

0 commit comments

Comments
 (0)