#!/usr/bin/env bun // Regenerate crates/wispplace-core/src/mime_table.rs: the extension -> type map // that the TypeScript CLI's `mime-types` (3.0.2) `lookup` used, so deployed // files keep their Content-Type and gzip decision. // // usage (from the repo root): bun cli-rs/scripts/mime-table.ts // MIME_TYPES_DIR overrides where mime-types is loaded from. import { writeFileSync } from 'node:fs' import { join } from 'node:path' const dir = process.env.MIME_TYPES_DIR ?? join(import.meta.dir, '../../cli/node_modules/mime-types') const { types } = await import(join(dir, 'index.js')) const { version } = await import(join(dir, 'package.json')) const rows = Object.entries(types as Record) .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)) .map(([ext, type]) => ` (${JSON.stringify(ext)}, ${JSON.stringify(type)}),`) const out = `// @generated by cli-rs/scripts/mime-table.ts from mime-types ${version}. Do not edit. /// Extension (lowercase, no dot) to MIME type, sorted by extension. pub static TYPES: &[(&str, &str)] = &[ ${rows.join('\n')} ]; ` writeFileSync(join(import.meta.dir, '../crates/wispplace-core/src/mime_table.rs'), out) console.log(`${rows.length} extensions from mime-types ${version}`)