opencode/packages/cli-rs/script/gen/mime.ts

19 lines
867 B
TypeScript

// Generates the extension-to-MIME table used for `run -f` attachments.
import { createRequire } from "node:module"
const require = createRequire(new URL("../../../util/package.json", import.meta.url).pathname)
const types: Record<string, string> = require("mime-types").types
const entries = Object.entries(types).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
const lines = [
"// Generated by script/gen/mime.ts from the `mime-types` package. Do not edit.",
"",
"/// `(extension, type)`, sorted by extension.",
"pub const TYPES: &[(&str, &str)] = &[",
...entries.map(([extension, type]) => ` (${JSON.stringify(extension)}, ${JSON.stringify(type)}),`),
"];",
"",
]
const file = new URL("../../crates/util/src/mime/types.rs", import.meta.url).pathname
await Bun.write(file, lines.join("\n"))
console.log(`mime: ${entries.length} extensions`)