Skip to content

Commit

Permalink
feat: updated mime-db to 1.52.0 (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisis authored Apr 8, 2022
1 parent 7912cd0 commit 78a30fb
Show file tree
Hide file tree
Showing 5 changed files with 2,189 additions and 181 deletions.
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

0 comments on commit 78a30fb

Please sign in to comment.