-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
150 lines (143 loc) · 3.86 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//const Employee = require("./Lib/employee");
const Engineer = require("./Lib/engineer");
const Intern = require("./Lib/intern");
const Manager = require("./Lib/manager");
const fs = require("fs");
const inquirer = require("inquirer");
const path = require("path");
const createCards = require("./generateHTML");
//empty array to push objects into after user inputs data
const allEmployees = [];
//created function to write to HTML file which I invoke during an if/else statement in newTeammatePrompt()
function writeToFile(fileName, data) {
fs.writeFileSync(path.join(__dirname, fileName), data, (err) =>
err ? console.log(err) : console.log("Success!")
);
}
//first prompt that gets asked is for the manager so they can build their team
newManager = () => {
inquirer
.prompt([
{
type: "input",
name: "managerName",
message: "Please enter your name",
},
{
type: "input",
name: "mgrID",
message: "Please enter your ID number",
},
{
type: "input",
name: "mgrEmail",
message: "Please enter your email",
},
{
type: "input",
name: "offNum",
message: "Please enter your office phone number",
},
])
.then((answers) => {
const nManager = new Manager(
answers.managerName,
answers.mgrID,
answers.mgrEmail,
answers.offNum
);
allEmployees.push(nManager);
newTeammatePrompt();
});
};
//separate prompt to be invoked after the each team member is built to check if they want to continuing adding or be finished
newTeammatePrompt = () => {
inquirer
.prompt([
{
type: "list",
name: "addMember",
message: "Would you like to add anyone to your team?",
choices: ["Yes", "No"],
},
])
.then((answers) => {
if (answers.addMember === "Yes") {
newTeammate();
} else {
console.log("team all built!", allEmployees);
const fileName = "src/teamDEMO.html";
writeToFile(fileName, createCards(allEmployees)); //creates HTML if "would you like to add a team member === no"
}
});
};
//Once newTeammatePrompt ==== yes, this prompt is invoked & goes through series of questions based of off Engineer or Intern
newTeammate = () => {
inquirer
.prompt([
{
type: "list",
name: "role",
message: "Who would you like to add?",
choices: ["Engineer", "Intern"],
},
{
type: "input",
name: "empName",
message: "Please enter name",
},
{
type: "input",
name: "empID",
message: "Please enter ID number",
},
{
type: "input",
name: "empEmail",
message: "Please enter email",
},
{
type: "input",
name: "gitHub",
message: "Please enter your engineers GitHub username",
when: function (answers) {
return answers.role === "Engineer";
},
},
{
type: "input",
name: "intSchool",
message: "Please enter your interns school",
when: function (answers) {
return answers.role === "Intern";
},
},
])
.then((answers) => {
if (answers.role === "Engineer") {
const nEng = new Engineer(
answers.empName,
answers.empID,
answers.empEmail,
answers.gitHub
);
allEmployees.push(nEng);
} else if (answers.role === "Intern") {
const nIntern = new Intern(
answers.empName,
answers.empID,
answers.empEmail,
answers.intSchool
);
allEmployees.push(nIntern);
}
newTeammatePrompt();
});
};
//function to start application
function init() {
console.log("Please build your team");
newManager();
}
// Function call to initialize app
init();