UNPKG

@rxan/figletify

Version:

A Pretty CLI tool to generate ASCII / Figlet Text

67 lines (60 loc) 1.58 kB
#!/usr/bin/env node import chalkAnimation from "chalk-animation"; import inquirer from "inquirer"; import figlet from "figlet"; import pc from "picocolors"; import { writeFileSync } from "fs"; const sleep = async (ms = 2000) => new Promise((resolve) => setTimeout(resolve, ms)); let text; let shouldWrite; async function welcome() { const rainbow = chalkAnimation.rainbow("Welcome to Figletify!"); await sleep(); rainbow.stop(); } async function askText() { const answers = await inquirer.prompt([ { name: "text", type: "input", message: "What text would you like to print?", default() { return "Figletify"; }, }, { name: "shouldWrite", type: "confirm", message: "Would you like to write the text to a file?", default() { return false; }, }, ]); text = answers.text; shouldWrite = answers.shouldWrite; console.log(pc.bgYellow("Loading Figlet Text...")); } async function figletify() { figlet(text, (err, data) => { if (err) { console.log(pc.bgRed("Error loading Figlet Text...")); process.exit(1); } console.log(data); if (shouldWrite) { writeFileSync("figlet.txt", data); const rainbow = chalkAnimation.rainbow( "Text written to file! figlet.txt" ); rainbow.start(); sleep(5000); rainbow.stop(); } }); } await welcome(); await askText(); await figletify(); await console.log(pc.bgGreen("Thank you for using Figletify!"));