hackages
Version:
CLI tool for learning software development concepts through test-driven development
112 lines (111 loc) • 3.92 kB
JavaScript
import prompts from "prompts";
import chalk from "chalk";
import { printSuccess } from "./console.js";
export async function promptForLearningGoal() {
// Random examples to help users understand how to express their learning goals
const examples = [
"OOP in TypeScript",
"OOP in Python",
"Singleton Design Pattern in JavaScript",
"Async/Await in TypeScript",
"Async/Await in Python",
"Array methods in JavaScript",
"Generics in TypeScript",
"Closures in JavaScript",
"Decorators in TypeScript",
"Event handling in JavaScript",
"Modules in TypeScript",
"Promises in JavaScript",
"Type guards in TypeScript",
"Higher-order functions in JavaScript",
"Interfaces in TypeScript",
"DOM manipulation in JavaScript",
"Error handling in TypeScript"
];
const randomExample = examples[Math.floor(Math.random() * examples.length)];
const response = await prompts({
type: "text",
name: "goal",
message: `💡 I would like to become better at:\n Example: ${randomExample}`,
validate: (value) => value.trim().length > 0 || "Please enter a learning goal!",
});
return response.goal || "";
}
export async function promptForTechnology(goalIncludesTech, detectedTech) {
// Always show technology selection, even if detected
let message = "🛠️ Which language would you like to use for this exercise?";
let initial = 0;
if (goalIncludesTech && detectedTech) {
printSuccess(`✅ Detected language: ${detectedTech}\n`);
message = "🛠️ Please confirm your technology choice:";
// Set initial selection to detected technology
if (detectedTech === "TypeScript") {
initial = 1;
}
}
const response = await prompts({
type: "select",
name: "tech",
message,
choices: [
{
title: detectedTech === "JavaScript" ? "JavaScript (Your selection)" : "JavaScript",
value: "JavaScript"
},
{
title: detectedTech === "TypeScript" ? "TypeScript (Your selection)" : "TypeScript",
value: "TypeScript"
},
{ title: chalk.gray("Go (coming soon)"), disabled: true },
{ title: chalk.gray("Python (coming soon)"), disabled: true },
],
initial,
});
const selectedTech = response.tech || "JavaScript";
printSuccess(`✅ Selected: ${selectedTech}\n`);
return selectedTech;
}
export async function promptForSkillLevel() {
const response = await prompts({
type: "select",
name: "level",
message: "📊 Select your skill level:",
choices: [
{
title: "Beginner",
description: "Just getting started",
value: "Beginner",
},
{
title: "Intermediate",
description: "Some experience",
value: "Intermediate",
},
{
title: "Advanced",
description: "Experienced developer",
value: "Advanced",
},
],
initial: 0,
});
const skillLevel = response.level || "Beginner";
printSuccess(`✅ Level: ${skillLevel}\n`);
return skillLevel;
}
export async function promptForMotivation() {
const response = await prompts({
type: "text",
name: "motivation",
message: "🔥 What motivates you to learn this? (optional)",
});
return response.motivation || "";
}
export async function promptForTimeCommitment() {
const response = await prompts({
type: "text",
name: "time",
message: "⏰ How much time can you dedicate today? (optional)",
});
return response.time || "";
}