UNPKG

mood-logger

Version:

A fun, cross-platform CLI tool that tracks your coding moods, shows stats, gives you motivational or roast quotes, and even syncs with Git commits 😎

104 lines (87 loc) 3.32 kB
#!/usr/bin/env node // mood-logger main CLI file — cross-platform and universal import inquirer from "inquirer"; import chalk from "chalk"; import { fileURLToPath } from "url"; import path from "path"; import { execSync } from "child_process"; import { setTimeout as delay } from "timers/promises"; // === Resolve paths safely === const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Dynamic imports (relative to current file) import { moods } from path.join(__dirname, "../lib/moods.js"); import { quotes } from path.join(__dirname, "../lib/quotes.js"); import { renderChart } from path.join(__dirname, "../lib/chart.js"); import { saveMood, getMoodStats } from path.join(__dirname, "../lib/storage.js"); const args = process.argv.slice(2); // === Core Mood Logger === async function logMood() { const { selected } = await inquirer.prompt([ { type: "list", name: "selected", message: chalk.cyan("Hey! How are you feeling today?"), choices: moods.map((m) => m.name), }, ]); const mood = moods.find((m) => m.name === selected); saveMood(mood); console.log( chalk.greenBright(`\nMood logged: ${mood.emoji} ${mood.name.split(" ")[1]}`) ); console.log(chalk.yellow(mood.message)); console.log(chalk.gray(`Logged at: ${new Date().toLocaleTimeString()}`)); // Random quote const randomQuote = quotes[Math.floor(Math.random() * quotes.length)]; console.log(chalk.blueBright(`\n💬 Quote of the day: "${randomQuote}"`)); } // === Mood Stats === function showStats() { const stats = getMoodStats(); if (!stats) { console.log(chalk.red("No moods logged yet 😢")); return; } console.log(chalk.magenta("\nYour Mood History:\n")); renderChart(stats.data); const [emoji, count] = stats.mostUsed; console.log(chalk.cyan(`\nTotal logs: ${stats.total}`)); console.log(chalk.green(`Most frequent mood: ${emoji} (${count} times)`)); } // === Reminder Command === async function remindUser(timeArg) { const match = timeArg?.match(/(\\d+)([mh])/); if (!match) { console.log(chalk.red("❌ Use format: mood-logger remind 2h or 30m")); return; } const [, amount, unit] = match; const ms = unit === "h" ? amount * 3600000 : amount * 60000; console.log(chalk.yellow(`⏰ Reminder set! I’ll ask your mood in ${amount}${unit}.`)); await delay(ms); await logMood(); } // === Git Commit Mood Integration === async function gitMood() { console.log(chalk.magenta("🪵 Git Commit Mood Tracker")); await logMood(); try { const commitMsg = execSync("git log -1 --pretty=%B").toString().trim(); console.log(chalk.gray(`\nLast commit: "${commitMsg}"`)); console.log(chalk.green("Mood linked successfully to your commit ✅")); } catch { console.log(chalk.red("⚠️ No Git commit found. Run this inside a Git repo.")); } } // === Command Router === (async () => { try { if (args[0] === "stats") showStats(); else if (args[0] === "remind") await remindUser(args[1]); else if (args[0] === "git") await gitMood(); else await logMood(); } catch (err) { console.error(chalk.red(`\n❌ Something went wrong: ${err.message}`)); } })();