UNPKG

@sern/cli

Version:

Official CLI for @sern/handler

78 lines (76 loc) 2.57 kB
import { fromCwd } from '../chunk-H6QGMA6W.js'; import { magentaBright, cyanBright, bold, underline, italic, greenBright, blueBright, redBright } from 'colorette'; import { readFileSync, readdirSync } from 'node:fs'; function getSern() { let files = []; try { const sern = fromCwd(".sern"); files = readdirSync(sern); } catch (error) { console.error(`${redBright("Error:")} Could not locate ${cyanBright(".sern")} directory`); process.exit(1); } finally { return files; } } function list() { const files = getSern(); if (!files.includes("command-data-remote.json")) { console.error(`No commands found Please run ${cyanBright("sern commands publish")} to publish your commands`); process.exit(1); } const commands = JSON.parse(readFileSync(".sern/command-data-remote.json", "utf-8")); const globalCommands = commands.global; delete commands.global; if (globalCommands) { console.log(bold("Global Commands")); for (const command of globalCommands) log(command); } console.log(" "); for (const guildId in commands) { const guildCommands = commands[guildId]; console.log(`${bold("Guild Commands")} [${underline(cyanBright(guildId))}]`); for (const command of guildCommands) log(command); } } var AppCommandsType = { 1: magentaBright("Slash"), 2: magentaBright("User"), 3: magentaBright("Message") }; var AppCommandOptionType = { 1: magentaBright("SubCommand"), 2: magentaBright("SubCommand Group"), 3: magentaBright("String"), 4: magentaBright("Integer"), 5: magentaBright("Boolean"), 6: magentaBright("User"), 7: magentaBright("Channel"), 8: magentaBright("Role"), 9: magentaBright("Mentionable"), 10: magentaBright("Number"), 11: magentaBright("Attachment") }; function log(command) { console.log(clean(` ${cyanBright(command.name)} ${italic(command.description)} (${greenBright(command.id)})`)); console.log(` Type: ${AppCommandsType[command.type]}`); if (command.options) { console.log(` Options:`); for (const option of command.options) { console.log(` ${blueBright(option.name)}: ${AppCommandOptionType[option.type]}`); if (option.options) { console.log(` Options:`); for (const subOption of option.options) { console.log(` ${cyanBright(subOption.name)}: ${AppCommandOptionType[subOption.type]}`); } } } } } var clean = (str) => str.split(" ").filter(Boolean).join(" "); export { list }; //# sourceMappingURL=out.js.map //# sourceMappingURL=list.js.map