-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
87 lines (68 loc) · 2.19 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
// Import required libraries and classes
const inquirer = require('inquirer');
const chalk = require('chalk');
const fs = require('fs');
const Triangle = require('./shapes/Triangle');
const Square = require('./shapes/Square');
const Circle = require('./shapes/Circle');
// Function to prompt user input using Inquirer
const promptUser = async () => {
// Define the questions for Inquirer
const questions = [
{
type: 'input',
name: 'text',
message: 'Enter up to three characters:',
validate: (input) => input.length <= 3 || 'Please enter up to three characters.',
},
{
type: 'input',
name: 'textColor',
message: 'Enter the text color (keyword or hexadecimal):',
},
{
type: 'list',
name: 'shape',
message: 'Choose a shape:',
choices: ['Triangle', 'Square', 'Circle'],
},
{
type: 'input',
name: 'shapeColor',
message: 'Choose a color:',
},
{
type: 'input',
name: 'filename',
message: 'Enter the filename to save the SVG:',
default: 'logo.svg',
},
];
// Wait for the user to answer the questions
const answers = await inquirer.prompt(questions);
const { text, textColor, shape, shapeColor, filename } = answers;
let shapeObj;
// Create a shape object based on the user's choice
switch (shape) {
case 'Triangle':
shapeObj = new Triangle();
break;
case 'Square':
shapeObj = new Square();
break;
case 'Circle':
shapeObj = new Circle();
break;
}
// Set the color of the shape
shapeObj.setColor(shapeColor);
// Generate the SVG content
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">${shapeObj.render()}
<text x="50%" y="50%" font-size="24" text-anchor="middle" dominant-baseline="central" fill="${textColor}">${text}</text> </svg>`;
// Save the SVG content to a file
fs.writeFileSync(filename, svg);
// Print a success message
console.log(chalk.green(`SVG saved to ${filename}`));
};
// Call the promptUser function to start the application
promptUser();