UNPKG

shartjs

Version:

When your app crashes, it farts. That's it.

116 lines (112 loc) 4 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { initShart: () => initShart }); module.exports = __toCommonJS(index_exports); var import_path2 = require("path"); var import_fs = require("fs"); var import_os = require("os"); var import_chalk = __toESM(require("chalk"), 1); var import_execa = require("execa"); // src/dirname.ts var import_path = __toESM(require("path"), 1); var import_url = require("url"); var import_meta = {}; var __dirnameShim; if (typeof __dirname !== "undefined") { __dirnameShim = __dirname; } else { const __filename = (0, import_url.fileURLToPath)(import_meta.url); __dirnameShim = import_path.default.dirname(__filename); } var __dirnameSafe = __dirnameShim; // src/index.ts async function playSound(filePath) { const os = (0, import_os.platform)(); try { if (os === "darwin") { await (0, import_execa.execa)("afplay", [filePath]); } else if (os === "win32") { await (0, import_execa.execa)("powershell", [ "-c", `Start-Process -FilePath "${filePath}" -WindowStyle Hidden` ]); } else { const players = ["paplay", "aplay", "mpg123", "mplayer", "play"]; let played = false; for (const cmd of players) { try { await (0, import_execa.execa)(cmd, [filePath]); played = true; break; } catch { } } if (!played) { console.error("\u{1F507} No compatible audio player found."); } } } catch (err) { console.error("\u{1F4A9} Failed to play fart sound:", err); } } async function playFart() { const fartDir = (0, import_path2.join)(__dirnameSafe, "..", "farts"); const files = (0, import_fs.readdirSync)(fartDir).filter((file) => file.endsWith(".wav")); if (files.length === 0) { console.error("\u{1F4A8} No fart files found."); return; } const selected = files[Math.floor(Math.random() * files.length)]; const fartPath = (0, import_path2.join)(fartDir, selected); await playSound(fartPath); } function printMessage(err) { console.error(import_chalk.default.redBright.bold("\u{1F4A9} UNHANDLED ERROR \u{1F4A9}")); console.error(import_chalk.default.red(err?.stack || err?.message || err)); } function initShart() { process.on("uncaughtException", async (err) => { await playFart(); printMessage(err); process.exit(1); }); process.on("unhandledRejection", async (reason) => { await playFart(); printMessage(reason); process.exit(1); }); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { initShart });