random bun scripts that dont fit anywhere else
at main 1.1 kB view raw
1#!/usr/bin/env bun 2 3import { readFileSync } from "node:fs"; 4import { resolve } from "node:path"; 5import { minify as terserMinify } from "terser"; 6 7const main = async () => { 8 // Get the file path from command line arguments 9 const filePath = process.argv[2]; 10 11 if (!filePath) { 12 console.error("Error: Please provide a file path as an argument"); 13 process.exit(1); 14 } 15 16 try { 17 // Read the JavaScript file 18 const fullPath = resolve(process.cwd(), filePath); 19 const fileContent = readFileSync(fullPath, "utf8"); 20 21 // Minify the JavaScript using terser 22 const result = await terserMinify(fileContent, { 23 mangle: true, 24 compress: true, 25 }); 26 27 if (!result.code) { 28 throw new Error("Minification failed"); 29 } 30 31 const minified = result.code; 32 33 // Create the bookmarklet by prefixing with "javascript:" 34 const bookmarklet = `javascript:${encodeURIComponent(minified)}`; 35 36 console.log(bookmarklet); 37 } catch (error) { 38 console.error(`Error: ${(error as Error).message}`); 39 process.exit(1); 40 } 41}; 42 43main();