-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
286 lines (264 loc) · 7.33 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// require statements
const Manager = require('./lib/Manager');
const Engineer = require('./lib/Engineer');
const Intern = require('./lib/Intern');
const Employee = require('./lib/Employee');
const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
const util = require('util');
const writeAsyncFile = util.promisify(fs.writeFile);
const makeHTML = require('./lib/htmlRender');
const LogColors = require('./logColors');
// path statements for output paths and file names
const outputDir = path.resolve(__dirname, 'dist');
const outputPath = path.join(outputDir, 'index.html');
// create a constant for changing colors in the command line
const log = new LogColors();
// array for team members
const teamArray = [];
// intro CLI text
const introQ = {
type: 'confirm',
message: `
Welcome to the Team Profile Generator!
This program creates a team profile website that will show basic information about each team member. The website is generated using the answers to your questions and uses HTML and CSS Bootstrap.
You will be prompted to provide information about the team manager and will add team members individually.
After you've entered information on all team members, you will receive instructions on how to access the team profile website.
Do you wish to continue?`,
name: 'startQ',
};
// manager CLI questions
const managerQ = [
{
type: 'input',
message: "What is the team manager's full name?",
name: 'managerName',
default() {
return "FirstName LastName";
},
},
{
type: 'input',
message: "What is the team manager's ID number?",
name: 'managerId',
default() {
return "1001";
},
validate: function (num) {
numbers = /^[0-9]+$/.test(num);
if (numbers) {
return true;
} else {
log.red(`Error: please enter only numbers, no letters or special characters.`);
return false;
}
},
},
{
type: 'input',
message: "What is the team manager's email?",
name: 'managerEmail',
default() {
return "name@company.com";
},
validate: function (emailInput) {
emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailInput);
if (emailFormat) {
return true;
} else {
log.red(`Error: please enter a valid email address.`);
return false;
}
},
},
{
type: 'input',
message: "What is the team manager's office number?",
name: 'managerOfficeNumber',
default() {
return "312-555-2323";
},
},
];
// ask if more team members need to be added
const introTeamQ = {
type: 'confirm',
message: 'Do you want to add anyone to this team? Select "Y" to add an Engineer or Intern, or select "N" if you do not need to add any additional team members.',
name: 'teamQ',
};
// ask which type of team member needs to be added
const teamMemberType = {
type: 'list',
message: 'What type of team member are you adding?',
choices: [
'Intern',
'Engineer'
],
name: 'teamMemberRole',
};
// engineer questions
const engineerQ = [
{
type: 'input',
message: "What is the engineer's full name?",
name: 'engineerName',
default() {
return "FirstName LastName";
},
},
{
type: 'input',
message: "What is the engineer's ID number?",
name: 'engineerId',
default() {
return "5101";
},
validate: function (num) {
numbers = /^[0-9]+$/.test(num);
if (numbers) {
return true;
} else {
log.red("Error: please enter only numbers for the ID number.");
return false;
}
},
},
{
type: 'input',
message: "What is the engineer's email?",
name: 'engineerEmail',
default() {
return "name@company.com";
},
validate: function (emailInput) {
emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailInput);
if (emailFormat) {
return true;
} else {
log.red("Error: please enter a valid email address.");
return false;
}
},
},
{
type: 'input',
message: "What is engineer's GitHub username?",
name: 'engineerGithub',
default() {
return "coolGitHubUser";
},
},
];
// intern questions
const internQ = [
{
type: 'input',
message: "What is the intern's full name?",
name: 'internName',
default() {
return "FirstName LastName"
}
},
{
type: 'input',
message: "What is the intern's ID number?",
name: 'internId',
default() {
return "9001"
},
validate: function (num) {
numbers = /^[0-9]+$/.test(num);
if (numbers) {
return true;
} else {
log.red("Error: please enter only numbers for the ID number.");
return false;
}
},
},
{
type: 'input',
message: "What is the intern's email?",
name: 'internEmail',
default() {
return "name@school.edu"
},
validate: function (emailInput) {
emailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailInput);
if (emailFormat) {
return true;
} else {
log.red("Error: please enter a valid email address.");
return false;
}
},
},
{
type: 'input',
message: "Where is the intern attending school?",
name: 'internSchool',
default() {
return "Northwestern University"
}
},
];
// function to start inquirer questions
function askIntroQ() {
inquirer.prompt(introQ).then((startApp) => {
if (startApp.startQ === true) {
log.green("Great! Let's get information on the team manager.");
askManagerQ();
} else {
log.yellow(`Application closed. Type "node index.js" to run application again.`);
}
});
}
// function to ask about additional team members, then either loop through to keep adding team members or stop and create the HTML for the team members
function getTeamSize() {
inquirer.prompt(introTeamQ).then((buildTeam) => {
if (buildTeam.teamQ === true) {
addTeamMember();
}
else {
htmlRender(teamArray);
}
});
}
// function to get manager questions then prompt for team questions
function askManagerQ() {
inquirer.prompt(managerQ).then((createManager) => {
let manager = new Manager(createManager.managerName, createManager.managerId, createManager.managerEmail, createManager.managerOfficeNumber);
teamArray.push(manager);
getTeamSize();
});
}
// create a new engineer or intern
function addTeamMember() {
inquirer.prompt(teamMemberType).then((roleChoice) => {
if (roleChoice.teamMemberRole === 'Engineer') {
log.magenta("Let's build an engineer profile!");
inquirer.prompt(engineerQ).then((buildEngineer) => {
let engineer = new Engineer(buildEngineer.engineerName, buildEngineer.engineerId, buildEngineer.engineerEmail, buildEngineer.engineerGithub);
teamArray.push(engineer);
getTeamSize();
});
} else {
log.magenta("Let's build an intern profile!");
inquirer.prompt(internQ).then((buildIntern) => {
let intern = new Intern(buildIntern.internName, buildIntern.internId, buildIntern.internEmail, buildIntern.internSchool);
teamArray.push(intern);
getTeamSize();
});
}
});
}
// async function to create html file and end program
async function htmlRender(file) {
const indexHTML = makeHTML(file);
await writeAsyncFile(outputPath, indexHTML).then(function () {
log.green(`Thank you for using the team profile generator!`);
});
}
// start asking questions
askIntroQ();