-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (56 loc) · 1.64 KB
/
index.js
File metadata and controls
59 lines (56 loc) · 1.64 KB
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
import inquirer from 'inquirer';
import fs from 'fs/promises';
import generateSVG from './lib/utils.js';
const question = [
{
type: "input",
name: "txt",
message: "Insert text up to 3 characters: ",
validate: function (input) {
const done = this.async();
setTimeout(function() {
if (input.length !== 3) {
// Pass the return value in the done callback
done('You need to provide a 3 character string');
} else {
// Pass the return value in the done callback
done(null, true);
}
}, 2000);
},
default: "SVG",
},
{
type: "input",
name: "color",
message: "Insert preffered color name OR hexdecimal number for text: ",
default: "red",
},
{
type: "rawlist",
name: "shape",
message: "Select shape from the list: ",
choices:
[
"circle",
"triangle",
"square"
],
default: "circle"
},
{
type: "input",
name: "bgcolor",
message: "Insert preffered color name OR hexadecimal number for shape background: ",
default: "blue",
}
];
const writeSVG = async (file, data) => {
await fs.appendFile(file, data);
}
const main = async () => {
const data = await inquirer.prompt(question);
writeSVG(`./examples/${data.shape}-logo-ngsvg-${Math.floor((1 + Math.random()) * 0x100000000).toString(16).substring(1)}.svg`, generateSVG(data));
console.log(data);
}
main();