-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
110 lines (97 loc) · 4.56 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
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 util = require("util");
const fs = require("fs");
// promisify file writing and directory creator
const mkdirAsync=util.promisify(fs.mkdir);
const writeFileAsync=util.promisify(fs.writeFile);
const OUTPUT_DIR = path.resolve(__dirname, "output");
const outputPath = path.join(OUTPUT_DIR, "team.html");
const render = require("./lib/htmlRenderer");
const Choice = require("inquirer/lib/objects/choice");
const Choices = require("inquirer/lib/objects/choices");
// Write code to use inquirer to gather information about the development team members,
// and to create objects for each team member (using the correct classes as blueprints!)
// declaring my questions for inquirer
const GenQs = [
{ type:"list",
message:"Select Role",
name:"role",
choices:[
"Manager",
"Engineer",
"Intern"
]
},
{ message:"Provide the Name: ",
name:"name",
},
{ message:"Please Provide the e-mail: ",
name:"email",
},
{ message:"Please Provide employee id#: ",
name:"id",
},
];
// specific questions according Roles
const MgrQ=[{message:"Please provide the Office Number: ", name:"officeNumber"}];
const EngQ=[{message:"Please provide a Github username: ", name:"gitHub"}];
const IntQ=[{message:"Please provide the School Name: ", name:"school"}];
// question for asking if there are more employees to add
const askContinue= [{ type:"confirm", message:" Do you want to continue adding employees? ", name:"confirmation"}];
// Calling an Async function ass my main function
const start = async () =>{
const employees=[];
let again=true;
// Looping the questions with a while
while (again){
// extacting values from the inquirer array using destructuring for general questions
const {role, name, email, id} = await inquirer.prompt(GenQs);
// HINT: each employee type (manager, engineer, or intern) has slightly different
// information; write your code to ask different questions via inquirer depending on
// employee type.
//check if the role is manager
if (role === 'Manager'){
const {officeNumber} = await inquirer.prompt(MgrQ);
// pushing to the array creating a new member
employees.push(new Manager(name, id, email, officeNumber));
} else if (role === 'Engineer'){
const {gitHub} = await inquirer.prompt(EngQ);
// pushing to the array creating a new member
employees.push(new Engineer(name, id, email, gitHub));
} else {
const {school} = await inquirer.prompt(IntQ);
// pushing to the array creating a new member
employees.push(new Intern(name, id, email, school));
}
// remainder-- use the same name property content from the inquirer for destructuring
const {confirmation}= await inquirer.prompt(askContinue);
again=confirmation;
}
// After the user has input all employees desired, call the `render` function (required
// above) and pass in an array containing all employee objects; the `render` function will
// generate and return a block of HTML including templated divs for each employee!
const html= render(employees);
// After you have your html, you're now ready to create an HTML file using the HTML
// returned from the `render` function. Now write it to a file named `team.html` in the
// `output` folder. You can use the variable `outputPath` above target this location.
// Hint: you may need to check if the `output` folder exists and create it if it
// does not.
//checking if my output folder exists
if (!fs.existsSync(outputPath)) {
const error = await mkdirAsync(OUTPUT_DIR);
error && console.error(error);
}
const error = await writeFileAsync(outputPath, html);
error && console.error(error);
};
start();
// HINT: make sure to build out your classes first! Remember that your Manager, Engineer,
// and Intern classes should all extend from a class named Employee; see the directions
// for further information. Be sure to test out each class and verify it generates an
// object with the correct structure and methods. This structure will be crucial in order
// for the provided `render` function to work! ```