UNPKG

hackages

Version:

CLI tool for learning software development concepts through test-driven development

79 lines (78 loc) โ€ข 2.78 kB
import chalk from "chalk"; import prompts from "prompts"; import { testCommand } from "./test.js"; import { reviewCommand } from "./review.js"; import { exerciseFilesExist, getPreviousLearningSuggestions, handleNextLearning } from "../services/file-manager.js"; import { clearScreen, printHeader, printWarning } from "../utils/console.js"; async function showMenu() { console.log("\n" + chalk.bold.yellow("๐ŸŽฏ What would you like to do?")); // Check for previous learning suggestions const previousSuggestions = getPreviousLearningSuggestions(); const choices = [ { title: "๐Ÿงช Run Tests", description: "Validate your code implementation", value: "test", }, { title: "๐Ÿ“‹ Code Review", description: "Get feedback on your code and recommendations for next steps", value: "review", }, ]; // Add Next Learning option if previous feedback exists if (previousSuggestions) { choices.push({ title: "๐Ÿš€ Next Learning", description: "Continue with recommended learning steps", value: "next-learning", }); } choices.push({ title: "๐Ÿ‘‹ Exit", description: "End your learning session", value: "exit", }); const response = await prompts({ type: "select", name: "action", message: "Choose an action:", choices, initial: 0, }); // Handle Ctrl+C (user cancellation) if (!response.action) { console.log(chalk.bold.green("\n๐Ÿ‘‹ Happy learning! See you next time!")); return; } switch (response.action) { case "test": await testCommand(); await showMenu(); // Show menu again after running tests break; case "review": await reviewCommand(); await showMenu(); // Show menu again after code review break; case "next-learning": if (previousSuggestions) { await handleNextLearning(previousSuggestions); await showMenu(); // Show menu again after generating next exercise } break; case "exit": console.log(chalk.bold.green("๐Ÿ‘‹ Happy learning! See you next time!")); break; } } export async function interactiveCommand() { clearScreen(); printHeader("Hackages Lab - Continue Mode"); console.log(chalk.gray("Welcome back! Let's continue your learning journey.\n")); // Check if files exist if (!exerciseFilesExist()) { printWarning("โš ๏ธ No existing exercise found. Please run 'hackages' to create a new exercise."); return; } await showMenu(); }