Skip to content

Commit

Permalink
fix: format types files with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Dec 17, 2024
1 parent c415f47 commit 614eb20
Show file tree
Hide file tree
Showing 3 changed files with 1,066 additions and 10 deletions.
19 changes: 13 additions & 6 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import mimeScore, { FACET_SCORES } from 'mime-score';
import { mkdir, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as prettier from 'prettier';

const MIME_DB_URL =
'https://raw.githubusercontent.com/jshttp/mime-db/master/db.json';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIR = __dirname.replace(/\/mime\/.*/, '/mime');

const prettierOptions = await prettier.resolveConfig(__dirname);

if (ROOT_DIR === __dirname) {
throw new Error('Could not find root directory');
}
Expand Down Expand Up @@ -94,12 +97,16 @@ async function writeTypesFile(name: string, types: Record<string, string[]>) {
const filepath = path.join(dirpath, `${name}.ts`);
await mkdir(dirpath, { recursive: true });

await writeFile(
filepath,
`const types : {[key: string]: string[]} = ${JSON.stringify(types)};
Object.freeze(types);
export default types;`,
);
let source = `const types : {[key: string]: string[]} = ${JSON.stringify(types)};
Object.freeze(types);
export default types;`;

source = await prettier.format(source, {
parser: 'typescript',
...prettierOptions,
});

await writeFile(filepath, source);
}

async function main() {
Expand Down
Loading

0 comments on commit 614eb20

Please sign in to comment.