Skip to content

chore(update-icons): sync update icon/icon.less #3620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions script/update-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const VERSION = process.argv[process.argv.indexOf('--version') + 1]; // 在 --ve

const iconOnlinePath = `https://tdesign.gtimg.com/icon/${VERSION}/fonts/index.css`;

const iconFile = path.join(__dirname, '..', 'src/common/style/icons.less'); // 组件的 .less 文件
const commonIconFile = path.join(__dirname, '..', 'src/common/style/icons.less'); // 组件的 .less 文件
const dataFile = path.join(__dirname, '..', 'src/icon/_example/data.js'); // 示例的 .js 文件

const iconFile = path.join(__dirname, '..', 'src/icon/icon.less');
// 定义一个函数来保存文件
const saveFile = (filename, content) => {
fs.writeFile(filename, content, (err) => {
Expand Down Expand Up @@ -36,12 +36,17 @@ const getIconCss = () => {
const iconsJs = `const icons = [\n '${keys.join("',\n '")}'\n]; \nexport default icons;\n`;

// 将 iconObject 转换为 LESS 格式的字符串
const iconLess = `@icons: {\n ${Object.entries(iconObject)
const commonIconLess = `@icons: {\n ${Object.entries(iconObject)
.map(([key, value]) => `${key}: '${value}';`)
.join('\n ')}\n}`;

const iconLess = fs.readFileSync(iconFile, 'utf-8');
const pattern = /https:\/\/tdesign\.gtimg\.com\/icon\/([\d.]+)\//g;
const newIconLess = iconLess.replaceAll(pattern, `https://tdesign.gtimg.com/icon/${VERSION}/`);

saveFile(iconFile, newIconLess);
saveFile(dataFile, iconsJs);
saveFile(iconFile, iconLess);
saveFile(commonIconFile, commonIconLess);
});
};

Expand Down