-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
150 lines (138 loc) · 4.02 KB
/
app.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
// Keep these lines; they're important!
const Manager = require("./lib/Manager");
const Engineer = require("./lib/Engineer");
const Intern = require("./lib/Intern");
const inquirer = require("inquirer");
const path = require("path");
const fs = require("fs");
const tools = require("./lib/tools");
const outputPath = path.resolve(__dirname, "output", "team.html");
const render = require("./lib/htmlRenderer");
// Mine
// const main = require("./templates/mainHTML");
// Recursive definitely going to use
const employees = [];
function validateString(string){
if (string === ""){
console.log("\nPlease enter valid input.")
}
return string !== "";
}
function validateEmail(email){
if (!email.includes("@")) {
console.log("\nPlease enter an email with an '@'.")
}
return email.includes("@");
}
var questions = [
{
type: 'list',
name: 'title',
message: 'What type of employee would you like to add?',
choices: [new inquirer.Separator(), 'Manager', new inquirer.Separator()],
},
{
type: 'input',
name: 'first_name',
message: "What's their first name?",
validate: validateString
},
{
type: 'input',
name: 'last_name',
message: "What's their last name?",
validate: validateString
},
{
type: 'input',
name: 'email',
message: "What's their email?",
validate: validateEmail
},
{
type: 'input',
name: 'id',
message: "What is their employee id?",
validate: validateString
},
{
type: 'input',
name: 'github',
message: "What's their GitHub handle?",
validate: validateString,
when: function( answers ) {
return answers.title === "Engineer";
}
},
{
type: 'input',
name: 'school',
message: "What is the school they are currently attending?",
validate: validateString,
when: function( answers ) {
return answers.title === "Intern";
}
},
{
type: 'input',
name: 'officeNumber',
message: "What's their office number?",
validate: validateString,
when: function( answers ) {
return answers.title === "Manager";
}
},
{
type: 'confirm',
name: 'anotherOne',
message: 'Want to add another team member?',
default: true
},
];
//! Handle errors (like when someone doesn't enter something)
function ask() {
inquirer.prompt(questions).then(answers => {
let nameTitleCase = `${tools.titleCase(answers.first_name)} ${tools.titleCase(answers.last_name)}`
answers.name = nameTitleCase;
const {name, id, email} = answers;
switch (answers.title) {
case 'Manager':
let manager = new Manager(name, id, email, answers.officeNumber)
employees.push(manager);
finishQuestionaire(answers);
break;
case 'Engineer':
let engineer = new Engineer(name, id, email, answers.github)
employees.push(engineer);
finishQuestionaire(answers)
break;
case 'Intern':
let intern = new Intern(name, id, email , answers.school)
employees.push(intern);
finishQuestionaire(answers);
break;
}
});
}
function finishQuestionaire(answers) {
if (answers.anotherOne) {
questions[0] = {
type: 'list',
name: 'title',
message: 'What type of employee would you like to add?',
choices: [new inquirer.Separator(), 'Manager', 'Engineer', 'Intern', new inquirer.Separator()],
},
delete answers.anotherOne
ask();
} else {
delete answers.anotherOne
fs.writeFileSync(outputPath, render(employees), err => {
if (err) throw err;
});
}
}
ask();
// Mine
// fs.writeFile("./output/output.html", main, err => {
// if (err) throw err;
// })