-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (49 loc) · 1.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const path = require("path");
// Required modules
const Manager = require("./lib/Manager");
const Engineer = require("./lib/Engineer");
const Intern = require("./lib/Intern");
const { managerPrompts, engineerPrompts, internPrompts, menuPrompt } = require("./utils/userPrompts");
const render = require("./src/page-template");
const { writeToFile, createTeam } = require("./utils/helpers");
// Functions to generate employees
function generateManager() {
return managerPrompts().then(({ name, id, email, officeNumber }) => {
const manager = new Manager(name, id, email, officeNumber);
createTeam.addToTeam(manager);
});
}
function generateEngineer() {
return engineerPrompts().then(({ name, id, email, github }) => {
const engineer = new Engineer(name, id, email, github);
createTeam.addToTeam(engineer);
});
}
function generateIntern() {
return internPrompts().then(({ name, id, email, school }) => {
const intern = new Intern(name, id, email, school);
createTeam.addToTeam(intern);
});
}
// Prompt user to add an employee or save and exit the program
async function showMainMenu() {
const outputPath = path.resolve(__dirname, "output", "team.html");
const menuMap = {
engineer: generateEngineer,
intern: generateIntern,
exit: () => writeToFile(outputPath, render(createTeam.getTeam())),
};
const { option } = await menuPrompt();
const selectedOption = menuMap[option];
await selectedOption();
if (option === "exit") return;
showMainMenu();
}
// Function to initialise the program
(function init() {
console.log(
"--------------------------------------------------------\nPlease fill in the following details to create your team\n--------------------------------------------------------"
);
// Prompt user to create a manager first, and then show the menu to add another employee
generateManager().then(showMainMenu);
})();