Skip to content

Commit 78a30fb

Browse files
authored
feat: updated mime-db to 1.52.0 (#808)
1 parent 7912cd0 commit 78a30fb

File tree

5 files changed

+2189
-181
lines changed

5 files changed

+2189
-181
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"build": "run-s build:clean build:code build:types",
5858
"generate:api-docs": "esno ./scripts/apidoc.ts",
5959
"generate:locales": "esno ./scripts/generateLocales.ts",
60+
"copy:mime-types": "esno ./scripts/copyMimeTypes.ts",
6061
"docs:build": "run-s docs:prepare docs:build:run",
6162
"docs:build:run": "vitepress build docs",
6263
"docs:build:ci": "run-s build docs:build",
@@ -108,6 +109,7 @@
108109
"eslint-plugin-prettier": "~4.0.0",
109110
"esno": "~0.14.1",
110111
"lint-staged": "~12.3.7",
112+
"mime-db": "~1.52.0",
111113
"npm-run-all": "~4.1.5",
112114
"picocolors": "~1.0.0",
113115
"prettier": "2.6.2",

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/copyMimeTypes.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import type { Options } from 'prettier';
4+
import { format } from 'prettier';
5+
import options from '../.prettierrc.cjs';
6+
7+
const rootPath = path.resolve(__dirname, '..');
8+
const mimeDbPath = path.resolve(rootPath, 'node_modules/mime-db/db.json');
9+
const mimeDbLicencePath = path.resolve(
10+
rootPath,
11+
'node_modules/mime-db/LICENSE'
12+
);
13+
const mimeTypesTsPath = path.resolve(
14+
rootPath,
15+
'src/locales/en/system/mimeTypes.ts'
16+
);
17+
const prettierTsOptions: Options = { ...options, parser: 'typescript' };
18+
fs.readFile(mimeDbPath, 'utf8', (err, data) => {
19+
if (err) {
20+
throw err;
21+
}
22+
23+
const licence = fs.readFileSync(mimeDbLicencePath, { encoding: 'utf8' });
24+
const mimeTypeFileContent = `// This file is generated by scripts/copyMimeTypes.ts\n// Do not edit this file directly. Instead, update mime-db and run \`pnpm run copy:mime-types\`\n\n/*\n${
25+
licence as string
26+
}*/\n\nexport default ${data as string};\n`;
27+
28+
fs.writeFile(
29+
mimeTypesTsPath,
30+
format(mimeTypeFileContent, prettierTsOptions),
31+
(err) => {
32+
if (err) {
33+
throw err;
34+
}
35+
36+
console.log(`Mime types copied to ${mimeTypesTsPath as string}`);
37+
}
38+
);
39+
});

0 commit comments

Comments
 (0)