-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
extractIcons.js
46 lines (42 loc) · 1.29 KB
/
extractIcons.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
const fs = require("fs");
const path = require("path");
function extractIconsFromCSS(cssFilePath, outputJsonPath, prefix, iconRegex) {
// Đọc nội dung của file CSS
fs.readFile(cssFilePath, "utf8", (err, data) => {
if (err) {
console.error("Error reading CSS file:", err);
return;
}
const icons = [];
let match;
while ((match = iconRegex.exec(data)) !== null) {
const iconName = match[1];
const iconClass = `${prefix} ${prefix}-${iconName}`;
icons.push({ name: iconName, class: iconClass });
}
// Xuất ra file JSON
fs.writeFile(
outputJsonPath,
"export default " + JSON.stringify(icons, null, 2) + ";",
(err) => {
if (err) {
console.error("Error writing JSON file:", err);
} else {
console.log("Icons extracted successfully to", outputJsonPath);
}
}
);
});
}
extractIconsFromCSS(
path.join(__dirname, "public/tabler-icons", "tabler-icons.css"),
path.join(__dirname, "resources/js/icon", "tabler-icons.js"),
"ti",
/\.ti-([a-zA-Z0-9-]+):before\s*/g
);
extractIconsFromCSS(
path.join(__dirname, "public/bootstrap-icons", "bootstrap-icons.css"),
path.join(__dirname, "/resources/js/icon", "bootstrap-icons.js"),
"bi",
/\.bi-([a-zA-Z0-9-]+)::before\s*/g
);