MCPcopy Create free account
hub / github.com/TheOdinProject/javascript-exercises / getPathForExercise

Function getPathForExercise

plopFile.js:58–90  ·  view source on GitHub ↗
(dirPath = [])

Source from the content-addressed store, hash-verified

56 description: "Create a basic JavaScript exercise.",
57 prompts: async function (inquirer) {
58 async function getPathForExercise(dirPath = []) {
59 const exerciseDirs = await getDirsWithExercises(dirPath.join("/"));
60
61 // Will only be empty when entering a new dir on a recursive call
62 // Recursive call only happens when new dir required which can bypass this question
63 const { dir } = exerciseDirs.length
64 ? await inquirer.prompt({
65 type: "list",
66 name: "dir",
67 message: "Which directory should this exercise go in?",
68 choices: [NEW_DIR_OPTION, ...exerciseDirs],
69 })
70 : { dir: NEW_DIR_OPTION };
71
72 if (dir === NEW_DIR_OPTION) {
73 const { newDirName } = await inquirer.prompt({
74 type: "input",
75 name: "newDirName",
76 message: "What is the name of the new directory?",
77 });
78 dirPath.push(newDirName);
79 } else {
80 dirPath.push(dir);
81 }
82
83 const { needMoreDirs } = await inquirer.prompt({
84 type: "confirm",
85 name: "needMoreDirs",
86 message: "Does this exercise need to be nested in a subdirectory?",
87 });
88
89 return needMoreDirs ? await getPathForExercise(dirPath) : dirPath;
90 }
91
92 const pathForExercise = await getPathForExercise();
93 const { exerciseName } = await inquirer.prompt({

Callers 1

plopFile.jsFile · 0.85

Calls 1

getDirsWithExercisesFunction · 0.85

Tested by

no test coverage detected