Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated mime-db to 1.52.0 #808

Merged
merged 6 commits into from
Apr 8, 2022
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"build": "run-s build:clean build:code build:types",
"generate:api-docs": "esno ./scripts/apidoc.ts",
"generate:locales": "esno ./scripts/generateLocales.ts",
"copy:mime-types": "esno ./scripts/copyMimeTypes.ts",
"docs:build": "run-s docs:prepare docs:build:run",
"docs:build:run": "vitepress build docs",
"docs:build:ci": "run-s build docs:build",
Expand Down Expand Up @@ -108,6 +109,7 @@
"eslint-plugin-prettier": "~4.0.0",
"esno": "~0.14.1",
"lint-staged": "~12.3.7",
"mime-db": "~1.52.0",
"npm-run-all": "~4.1.5",
"picocolors": "~1.0.0",
"prettier": "2.6.2",
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions scripts/copyMimeTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from 'node:fs';
import path from 'node:path';
import type { Options } from 'prettier';
import { format } from 'prettier';
import options from '../.prettierrc.cjs';

const rootPath = path.resolve(__dirname, '..');
const mimeDbPath = path.resolve(rootPath, 'node_modules/mime-db/db.json');
const mimeDbLicencePath = path.resolve(
rootPath,
'node_modules/mime-db/LICENSE'
);
const mimeTypesTsPath = path.resolve(
rootPath,
'src/locales/en/system/mimeTypes.ts'
);
const prettierTsOptions: Options = { ...options, parser: 'typescript' };
fs.readFile(mimeDbPath, 'utf8', (err, data) => {
if (err) {
throw err;
}

const licence = fs.readFileSync(mimeDbLicencePath, { encoding: 'utf8' });
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${
licence as string
}*/\n\nexport default ${data as string};\n`;

fs.writeFile(
mimeTypesTsPath,
format(mimeTypeFileContent, prettierTsOptions),
(err) => {
if (err) {
throw err;
}

console.log(`Mime types copied to ${mimeTypesTsPath as string}`);
}
);
});
Loading