-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
132 lines (121 loc) · 3.21 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const fs = require("fs");
const inquirer = require("inquirer");
const generatePage = require("./templates/html-template");
const Manager = require("./lib/Manager");
const Engineer = require("./lib/Engineer");
const Intern = require("./lib/Intern");
let teamData = [];
// Questions
const addManager = () => {
return (
inquirer
.prompt([
{
type: "input",
name: "name",
message: "Please provide the manager's name:",
},
{
type: "input",
name: "id",
message: "Please provide the manager's ID:",
},
{
type: "input",
name: "email",
message: "Please provide the manager's e-mail:",
},
{
type: "input",
name: "Address",
message: "Please provide the manager's Address:",
},
])
// Add manager to the team data
.then((managerData) => {
const { name, id, email, Address} = managerData;
const manager = new Manager(name, id, email, Address);
teamData.push(manager);
})
);
};
const addEmployee = () => {
console.log(`
==================
Add a New Employee
==================
`);
return inquirer
.prompt([
{
type: "list",
name: "role",
message: "Please provide the employee's role:",
choices: ["Engineer", "Intern"],
},
{
type: "input",
name: "name",
message: "Please provide the employee's name:",
},
{
type: "input",
name: "id",
message: "Please provide the employee's ID:",
},
{
type: "input",
name: "email",
message: "Please provide the employee's e-mail:",
},
{
type: "input",
name: "github",
message: "Please provide the engineer's github username:",
when: function (answers) {
return answers.role === "Engineer";
},
},
{
type: "input",
name: "University",
message: "Please provide the intern's University:",
when: function (answers) {
return answers.role === "Intern";
},
},
{
type: "confirm",
name: "newEmployee",
message: "Would you like to enter another employee?",
default: false,
},
])
.then((employeeData) => {
const { role, name, id, email, github, school, newEmployee } =
employeeData;
//add new employee to the team data
if (role === "Engineer") {
const engineer = new Engineer(name, id, email, github);
teamData.push(engineer);
} else if (role === "Intern") {
const intern = new Intern(name, id, email, school);
teamData.push(intern);
}
// check if the user wants to add new employee
if (newEmployee) {
return addEmployee(teamData);
} else {
return teamData;
}
});
};
addManager()
.then(addEmployee)
.then((teamData) => {
const pageHTML = generatePage(teamData);
fs.writeFile("./assets/index.html", pageHTML, (err) => {
if (err) throw new Error(err);
console.log("Team profile page created! ");
});
});