代码拉取完成,页面将自动刷新
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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。