forked from mushikago/fluenticons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.js
97 lines (88 loc) · 2.38 KB
/
generator.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
const iconsFolder = "./static/icons/";
const fs = require("fs");
const axios = require("axios");
let filledIcons = [];
let outlinedIcons = [];
fs.readdirSync(iconsFolder).forEach(file => {
let type = file.includes("filled") === true ? "filled" : "outlined";
let IconName = pascalize(file.replace("ic_fluent_", "").split("_24")[0]);
if (type === "filled") {
filledIcons.push({
name: IconName,
componentName: `FluentIcon${capitalizeString(type)}${IconName}`,
svgFileName: file
});
} else {
outlinedIcons.push({
name: IconName,
componentName: `FluentIcon${capitalizeString(type)}${IconName}`,
svgFileName: file
});
}
let ComponentName = `${pascalize(
file.replace("ic_fluent_", "").split("_24")[0]
)}.vue`;
let content = `<template>
${readFile(`./static/icons/${file}`, "utf8")}
</template>
<script>
export default {
name: 'FluentIcon${capitalizeString(type)}${IconName}',
};
</script>`;
if (type === "filled") {
createFile(
`../components/FluentIcon/Filled/${ComponentName}`,
IconName,
content
);
} else {
createFile(
`../components/FluentIcon/Outlined/${ComponentName}`,
IconName,
content
);
}
});
createFile(
"./filled.json",
"filled.json",
JSON.stringify(filledIcons, null, 2)
);
createFile(
"./outlined.json",
"outlined.json",
JSON.stringify(outlinedIcons, null, 2)
);
// function to capitalize a string
function capitalizeString(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// function to get synonyms of a given word from datamuse.com
async function getSynonyms(word) {
const { data } = await axios.get(
`https://api.datamuse.com/words?rel_syn=${word}`
);
return data.map(item => item.word);
}
// function to create and save a file on given path
function createFile(filePath, fileName, content) {
fs.writeFile(filePath, content, function(err) {
if (err) {
return console.log(err);
}
console.log(`${fileName} was saved!`);
});
}
// function to read a file and return its contents as a string
function readFile(file) {
return fs.readFileSync(file, "utf8");
}
function pascalize(string) {
const words = string.split("_");
const capitalized = words.map(word => capitalize(word));
return capitalized.join("");
}
function capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}