owenlebec
Version:
Mon CV en ligne
68 lines (56 loc) • 1.69 kB
JavaScript
;
import inquirer from "inquirer";
import chalk from "chalk";
import data from "./data.json" assert { type: "json" };
const response = chalk.white;
const options = {
type: "list",
name: "resumeOptions",
message: "What would you like to know?",
choices: [...Object.keys(data), "🚪 See you!"]
};
function showResume() {
console.log("Hi there 👋 my name's Owen and welcome to my resume");
handleResume();
}
function handleResume() {
inquirer.prompt(options).then(answer => {
if (answer.resumeOptions === "🚪 See you!") {
console.log(response("Thank you for your time! 👋"));
return;
}
const option = data[answer.resumeOptions];
if (option) {
console.log(response(new inquirer.Separator()));
option.forEach(info => {
let formattedInfo = info.replace(/<blue>(.*?)<blue>/g, (match, p1) => blue(p1));
formattedInfo = formattedInfo.replace(/<bold>(.*?)<bold>/g, (match, p1) => bold(p1));
console.log(response("| " + formattedInfo));
});
console.log(response(new inquirer.Separator()));
}
inquirer
.prompt({
type: "list",
name: "exitBack",
message: "Go back or Exit?",
choices: ["⬅️ Back", "🚪 Exit"]
})
.then(choice => {
if (choice.exitBack === "⬅️ Back") {
handleResume();
} else {
console.log(response("Thank you for your time! 👋"));
return;
}
});
}).catch(err => console.log('Oops,', err));
}
function blue(text) {
return chalk.bold.blue(text);
}
function bold(text) {
return chalk.bold.white(text);
}
showResume();