-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (71 loc) · 2.86 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
//file that builds the html template with all the user input
const generateHTML = require('./src/generateHTML');
//team prompts
const { managerPrompts, engineerPrompts, internPrompts } = require('./lib/prompts');
//modules needed for app
const fs = require('fs');
const inquirer = require('inquirer');
//team sub classes
const Manager = require('./lib/Manager');
const Engineer = require('./lib/Engineer');
const Intern = require('./lib/Intern');
//holds the user input to build the html template
const teamArray = [];
//function that initiates the build/manager prompts and sends the manager input into the teamArray, and then initiates the addEmployee function/prompts
const initTeamBuild = () => {
inquirer.prompt(managerPrompts)
.then(managerInput => {
const { name, id, email, officeNumber } = managerInput;
const manager = new Manager(name, id, email, officeNumber);
teamArray.push(manager);
addEmployee();
})
};
//addEmployee function will complete the rest of the prompts and push that user input into the teamArray with an if else statement, or it will generateHTML build.
const addEmployee = () => {
inquirer.prompt({
type: 'list',
name: 'addMore',
message: "Would you like to add more employees to your team?",
choices: [
{ name: 'No, my team is finished.', value: 'finished' },
{ name: 'Yes, add an engineer.', value: 'engineer' },
{ name: 'Yes, add an intern.', value: 'intern' },
],
default: 'finished'
}).then(answers => {
if (answers.addMore === 'engineer') {
inquirer.prompt(engineerPrompts)
.then(engineerInput => {
const { name, id, email, github } = engineerInput;
const engineer = new Engineer(name, id, email, github);
teamArray.push(engineer);
addEmployee();
})
} else if (answers.addMore === 'intern') {
inquirer.prompt(internPrompts)
.then(internInput => {
const { name, id, email, school } = internInput;
const intern = new Intern(name, id, email, school);
teamArray.push(intern);
addEmployee();
})
} else {
console.log('Thank you! Your team information has been received.');
let finalOutput = generateHTML(teamArray);
createHTML(finalOutput);
}
})
};
//function called to initialize app
initTeamBuild();
//function will take the finalOutput and write the html file.
const createHTML = (template) => {
fs.writeFile('example.html', template, (error) => {
if (error) {
console.log(error);
} else {
console.log('Your Team profile was successfully created!');
}
})
};