Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
208 lines (198 loc) · 6.76 KB
/
Copy pathindex.js
File metadata and controls
208 lines (198 loc) · 6.76 KB
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
// NPM Packages
const inquirer = require('inquirer');
const colors = require('colors');
// Employee Classes
const Manager = require('./lib/manager');
const Engineer = require('./lib/engineer');
const Intern = require('./lib/intern');
// HTML Generator
const generateHTML = require('./src/generateHTML');
// Colorized Fonts and Other Default Language
const welcomeMsg = `* * * * WELCOME TO YOUR AUTOMATED TEAM PROFILE GENERATOR. * * * *\n`.underline.green;
const error = `\r\n>> ERR: `.red.bold;
const noInfoEntered = `No information was entered.`;
// Array to Hold Team
const teamArr = [];
// Welcome and Instructions
const welcome = () => {
return inquirer.prompt([
{
type: 'input',
name: 'welcome',
message: welcomeMsg + '\nYou will be asked to input information about your team, starting with your Team Manager. \nThese questions will help to complete your customized MyTeam HTML doc. \nLet\'s begin! Press ENTER to continue. \n',
},
])
.then(addManager)
};
// Questions Awaiting User Input
// Manager Questions
const addManager = () => {
return inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'Input Team Manager\'s name.',
validate: name => {
if (name) {
return true;
} else {
console.log (error + noInfoEntered + `Please enter the Team Manager\'s name.`);
return false;
}
},
},
{
type: 'input',
name: 'id',
message: ({ name }) => `Input ${name}\'s employee ID.`,
validate: id => {
if (id) {
return true;
} else {
({ name }) => console.log (error + noInfoEntered + `Please enter ${name}\'s employee ID.`);
return false;
}
},
},
{
type: 'input',
name: 'email',
message: ({ name }) => `Input ${name}\'s email address.`,
validate: email => {
valid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email);
if (valid) {
return true;
} else {
console.log(error + `An email address is required. Please enter a valid email address.`)
return false;
};
},
},
{
type: 'input',
name: 'officeNumber',
message: ({ name }) => `Input ${name}\'s office number.`,
validate: officeNumber => {
if (officeNumber) {
return true;
} else {
({ name }) => console.log (error + noInfoEntered + `Please enter ${name}\'s office number.`);
return false;
}
},
},
{
type: 'list',
name: 'queryMoreReports',
message: 'Would you like to add more team members?',
choices: ['Yes', 'No'],
},
])
.then(answers => {
const {name, id, email, officeNumber} = answers;
const manager = new Manager(name, id, email, officeNumber);
teamArr.push(manager);
(answers.queryMoreReports === 'Yes') ? addReports(): generateHTML(teamArr);
})
};
// Direct Report Questions
const addReports = () => {
return inquirer.prompt([
{
type: 'list',
name: 'title',
message: 'Team member\'s title (select one):',
choices: ['Engineer', 'Intern'],
},
{
type: 'input',
name: 'name',
message: ({ title }) => `Input ${title}\'s name.`,
validate: nameInput => {
if (nameInput) {
return true;
} else {
({ title }) => console.log (error + noInfoEntered + `Please enter the ${title}\'s name.`);
return false;
}
},
},
{
type: 'input',
name: 'id',
message: ({ name }) => `Input ${name}\'s employee ID.`,
validate: id => {
if (id) {
return true;
} else {
({ name }) => console.log (error + noInfoEntered + `Please enter ${name}\'s employee ID.`);
return false;
}
},
},
{
type: 'input',
name: 'email',
message: ({ name }) => `Input ${name}\'s email address.`,
validate: email => {
valid = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)
if (valid) {
return true;
} else {
console.log(error + `An email address is required. Please enter a valid email address.`)
return false;
};
},
},
{
type: 'input',
name: 'github',
message: ({ name }) => `Input ${name}\'s GitHub username.`,
when: (input) => input.title === 'Engineer',
validate: github => {
if (github) {
return true;
} else {
({ name }) => console.log (error + noInfoEntered + `Please enter ${name}\'s GitHub username.`);
return false;
}
},
},
{
type: 'input',
name: 'school',
message: ({ name }) => `Input ${name}\'s school.`,
when: (input) => input.title === 'Intern',
validate: school => {
if (school) {
return true;
} else {
({ name }) => console.log (error + noInfoEntered + `Please enter ${name}\'s school.`);
return false;
}
},
},
{
type: 'list',
name: 'queryMoreReports',
message: 'Would you like to add more team members?',
choices: ['Yes', 'No'],
},
])
.then(answers => {
if (answers.title === 'Engineer') {
const {name, id, email, github} = answers;
const engineer = new Engineer (name, id, email, github);
teamArr.push(engineer);
} else if (answers.title === 'Intern') {
const {name, id, email, school} = answers;
const intern = new Intern (name, id, email, school);
teamArr.push(intern);
};
(answers.queryMoreReports === 'Yes') ? addReports() : generateHTML(teamArr);
})
};
// Function to Initialize App
const init = () => welcome()
// Initialize App
init();