Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url';
import * as prettier from 'prettier';

const TYPES_MARKER = '/* TYPES GO HERE */';
const TYPES_TEMPLATE = `const types = ${TYPES_MARKER} as const satisfies Readonly<{ [key: string]: string[] }>;

// Make readonly
Object.freeze(types);

export default types;`;

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

Expand Down Expand Up @@ -97,10 +105,10 @@ async function writeTypesFile(name: string, types: Record<string, string[]>) {
const filepath = path.join(dirpath, `${name}.ts`);
await mkdir(dirpath, { recursive: true });

let source = `const types : {[key: string]: string[]} = ${JSON.stringify(types)};
Object.freeze(types);
export default types;`;
// Generate source content
let source = TYPES_TEMPLATE.replace(TYPES_MARKER, JSON.stringify(types));

// Format
source = await prettier.format(source, {
parser: 'typescript',
...PRETTIER_OPTIONS,
Expand Down
7 changes: 5 additions & 2 deletions types/other.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const types: { [key: string]: string[] } = {
const types = {
'application/prs.cww': ['cww'],
'application/prs.xsf+xml': ['xsf'],
'application/vnd.1000minds.decision-model+xml': ['1km'],
Expand Down Expand Up @@ -713,6 +713,9 @@ const types: { [key: string]: string[] } = {
'video/x-sgi-movie': ['movie'],
'video/x-smv': ['smv'],
'x-conference/x-cooltalk': ['ice'],
};
} as const satisfies Readonly<{ [key: string]: string[] }>;

// Make readonly
Object.freeze(types);

export default types;
7 changes: 5 additions & 2 deletions types/standard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const types: { [key: string]: string[] } = {
const types = {
'application/andrew-inset': ['ez'],
'application/appinstaller': ['appinstaller'],
'application/applixware': ['aw'],
Expand Down Expand Up @@ -361,6 +361,9 @@ const types: { [key: string]: string[] } = {
'video/ogg': ['ogv'],
'video/quicktime': ['qt', 'mov'],
'video/webm': ['webm'],
};
} as const satisfies Readonly<{ [key: string]: string[] }>;

// Make readonly
Object.freeze(types);

export default types;