-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
250 lines (232 loc) · 7.61 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Team Profile Generator
console.log(`Team Profile Generator!`);
// Declaring Constants
const fs = require(`fs`);
const inquirer = require(`inquirer`);
const render = require(`./src/page-template.js`);
const path = require(`path`);
const Manager = require(`./lib/Manager`);
const Engineer = require(`./lib/Engineer`);
const Intern = require(`./lib/Intern`);
const outputDirectory = path.resolve(__dirname,`dist`);
const outputPath = path.join(outputDirectory,`generatedTeamProfile.html`);
const team = [];
const IDs = [];
generateTeamPage = team => {
fs.writeFileSync(outputPath, render(team), `utf-8`);
}
askQuestions = () => {
inquirer.prompt([
{
name: `managerName`,
type: `input`,
message: `What is the Manager's Name?`,
validate: name => {
if (name === ``) {
return `Please enter at least one character`;
} else {
return true;
}
}
},{
name: `managerID`,
type: `input`,
message: `What is the Manager's Employee ID?`,
validate: ID => {
const isNumber = ID.match(/^[1-9]\d*$/);
if (isNumber) {
if (IDs.includes(ID)) {
return `This ID is already registered. Please enter a different ID.`
} else {
return true;
}
} else {
return `Please enter a posiive number greater than zero.`;
}
}
},{
name: `managerEmail`,
type: `input`,
message: `What is the Manager's Email Address?`,
validate: email => {
const validEmail = email.match(/\S+@\S+\.\S+/);
if (validEmail) {
return true;
} else {
return `Please enter a valid email address.`;
}
}
},{
name: `officeNumber`,
type: `input`,
message: `What is the Office Number?`,
validate: officeNumber => {
if (officeNumber === ``) {
return `Please enter an Office Number`;
} else {
const isNumber = officeNumber.match(/^[1-9]\d*$/);
if (isNumber) {
return true;
} else {
return `Please enter a posiive number greater than zero.`;
}
}
}
}
]).then(response => {
const manager = new Manager(response.managerName,response.managerID,response.managerEmail,response.officeNumber);
IDs.push(response.managerID);
team.push(manager);
teamQuestions();
})
}
teamQuestions = () => {
inquirer.prompt([
{
type: `list`,
name: `members`,
message: `Would you like to add a Team Member?`,
choices: [
`Add an Engineer`,
`Add an Intern`,
`I do not want to add any more Team Members`
]
}
]).then(choice => {
switch(choice.members) {
case `Add an Engineer`:
addEngineer();
break;
case `Add an Intern`:
addIntern();
break;
default:
console.log(`Generating Team Page...`);
generateTeamPage(team);
setTimeout(() => {
console.log(`Generated!`);
},1000)
}
})
}
addEngineer = () => {
inquirer.prompt([
{
name: `engineerName`,
type: `input`,
message: `What is the Engineer's Name?`,
validate: name => {
if (name === ``) {
return `Please enter at least one character`;
} else {
return true;
}
}
},{
name: `engineerID`,
type: `input`,
message: `What is the Engineer's Employee ID?`,
validate: ID => {
const isNumber = ID.match(/^[1-9]\d*$/);
if (isNumber) {
if (IDs.includes(ID)) {
return `This ID is already registered. Please enter a different ID.`
} else {
return true;
}
} else {
return `Please enter a posiive number greater than zero.`;
}
}
},{
name: `engineerEmail`,
type: `input`,
message: `What is the Engineer's Email Address?`,
validate: email => {
const validEmail = email.match(/\S+@\S+\.\S+/);
if (validEmail) {
return true;
} else {
return `Please enter a valid email address.`;
}
}
},{
name: `github`,
type: `input`,
message: `What is the Engineers Github username?`,
validate: github => {
if (github === ``) {
return `Please enter at least one character`;
} else {
return true;
}
}
}
]).then(response => {
const engineer = new Engineer(response.engineerName,response.engineerID,response.engineerEmail,response.github);
IDs.push(response.engineerID);
team.push(engineer);
teamQuestions();
})
}
addIntern = () => {
inquirer.prompt([
{
name: `internName`,
type: `input`,
message: `What is the Intern's Name?`,
validate: name => {
if (name === ``) {
return `Please enter at least one character`;
} else {
return true;
}
}
},{
name: `internID`,
type: `input`,
message: `What is the Intern's Employee ID?`,
validate: ID => {
const isNumber = ID.match(/^[1-9]\d*$/);
if (isNumber) {
if (IDs.includes(ID)) {
return `This ID is already registered. Please enter a different ID.`
} else {
return true;
}
} else {
return `Please enter a posiive number greater than zero.`;
}
}
},{
name: `internEmail`,
type: `input`,
message: `What is the Intern's Email Address?`,
validate: email => {
const validEmail = email.match(/\S+@\S+\.\S+/);
if (validEmail) {
return true;
} else {
return `Please enter a valid email address.`;
}
}
},{
name: `school`,
type: `input`,
message: `What School is the Intern attending?`,
validate: school => {
if (school === ``) {
return `Please enter at least one character`;
} else {
return true;
}
}
}
]).then(response => {
const intern = new Intern(response.internName,response.internID,response.internEmail,response.school);
IDs.push(response.internID);
team.push(intern);
teamQuestions();
})
}
askQuestions();