Skip to content

Commit

Permalink
feat(Icon): update version to 0.2.1 (#2962)
Browse files Browse the repository at this point in the history
* feat(Icon): update version to 0.2.1

* test: update snapshots
  • Loading branch information
anlyyao authored Jul 9, 2024
1 parent 2757607 commit 56a9a3e
Show file tree
Hide file tree
Showing 5 changed files with 647 additions and 567 deletions.
59 changes: 44 additions & 15 deletions script/update-icons.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
const path = require('path');
const fs = require('fs');
const { get } = require('./qrcode/httpRequest');

const iconFile = path.join(__dirname, '..', 'src/icon/icon.less');
const dataFile = path.join(__dirname, '..', 'src/icon/_example/data.js');
fs.readFile(iconFile, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const regex = new RegExp(`\\..*-icon-(.*):before`, 'g');
const icons = data.match(regex);
const iconList = icons.map((icon) => icon.replace(regex, '$1'));
const iconsData = `const icons = ${JSON.stringify(iconList, null, 2)}; \nexport default icons;\n`;
fs.writeFile(dataFile, iconsData, (err) => {
const VERSION = process.argv[process.argv.indexOf('--version') + 1]; // 在 --version 后面

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

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

// 定义一个函数来保存文件
const saveFile = (filename, content) => {
fs.writeFile(filename, content, (err) => {
if (err) {
console.error(err);
console.error(`Error writing file: ${filename}`, err);
} else {
console.log(`File saved: ${filename}`);
}
});
console.log('update icons success!');
});
};

const getIconCss = () => {
get(iconOnlinePath).then((e) => {
const regex = new RegExp(`\\.t-icon-(.*):before \\{\\s+content: "(.*)";`, 'g');
const icons = e.match(regex);

const iconList = icons.map((icon) => {
return { [icon.replace(regex, '$1')]: icon.replace(regex, '$2') };
});

const iconObject = Object.assign({}, ...iconList);
const keys = Object.keys(iconObject);

// 将 keys 数组转换为 JS 格式的字符串
const iconsJs = `const icons = [\n '${keys.join("',\n '")}'\n]; \nexport default icons;\n`;

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

saveFile(dataFile, iconsJs);
saveFile(iconFile, iconLess);
});
};

getIconCss();

// node script/update-icons.js --version 0.2.1
Loading

0 comments on commit 56a9a3e

Please sign in to comment.