-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
210 lines (199 loc) · 5.87 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
// this brings in the inquirer to ask the questions
const inquirer = require('inquirer');
//this writes the file
const fs = require('fs');
//provieds access to some utility functions
const util = require('util');
//brings in the manager page
const Manager = require('./library/Manager')
//brings in the engineer page
const Engineer = require('./library/Engineer')
//brings in the intern page
const Intern = require('./library/Intern')
//brings in the buildtemp page
const generateHTML = require('./library/buildTemp')
//creates the first array from the questions and responses
const team = [];
//writes the file
const writeFileAsync = util.promisify(fs.writeFile);
//stops the user and asks if they want to add a teammeber of intern or engineer if neither it then renders the team page and starts the writting process
const continueBuild = () => {
inquirer.prompt([
{
type: 'list',
name: 'teamMember',
message: 'what team member do you want to build',
choices: ['Intern', 'Engineer', 'I dont not want to add more team members'],
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
}
])
.then((answer) => {
switch (answer.teamMember) {
case 'Intern':
return promptIntern();
case 'Engineer':
return promptEngineer();
default:
console.log("Writing your file!")
return renderTeamPage(team)
}
})
}
//this is the first promt of manager and it asks the questions and once finished runs the continue build function and creates a loop
const promptUserManager = () => {
inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'email',
message: 'what is your email?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'id',
message: 'What is your ID number?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'office',
message: 'what is your office number?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
}
]).then((response) => {
//this creates the new manager with the responses and pushes manager to the team array above
const manager = new Manager(response.name, response.email, response.id, response.office)
team.push(manager);
//this crreates the loop that doesnt end until you say you dont want to build anymore team members
continueBuild()
})
};
const init = () => {
promptUserManager()
};
//this creates the engineer and asks the questions and puts the response into the team array
const promptEngineer = () => {
return inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'id',
message: 'What is your Id?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'email',
message: 'What is your email?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'github',
message: 'what is your Git Hub username?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
}
])
.then((response) => {
console.log(response)
//this creates the new engineer and adds the responses and pushes them to the team array
const engineer = new Engineer(response.name, response.email, response.id, response.github)
team.push(engineer);
//here is the loop in action again
continueBuild()
})
};
//this creates the intern and asks the questions and pushes the responses to the team array
const promptIntern = () => {
return inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'id',
message: 'What is your Id?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'email',
message: 'What is your email?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
},
{
type: 'input',
name: 'school',
message: 'what is your School name?',
validate: (value) => {
if (value) { return true }
else { return 'please enter a value' }
},
}
])
.then((response) => {
// this creates the new intern and pushes the responses to the team array
console.log(response)
const intern = new Intern(response.name, response.email, response.id, response.school)
team.push(intern);
//here is the loop in action again
continueBuild()
})
};
//this function is called at the end of the continue build function and writes the responses to generate html function of the buildtemp file, pushinf the team array
function renderTeamPage(response) {
writeFileAsync('index.html', generateHTML(response))
.catch(err => console.error(err))
console.log('index.html', generateHTML(response))
}
init();