refactor: split icon collections (#34453)

This commit is contained in:
Stephen Zhou
2026-04-02 15:58:15 +08:00
committed by GitHub
parent 1873b22e96
commit 52b1bc5b09
457 changed files with 2105 additions and 70 deletions

View File

@@ -6,6 +6,7 @@ import { camelCase, template } from 'es-toolkit/compat'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const iconsDir = path.resolve(__dirname, '../app/components/base/icons')
const svgAssetsDir = path.resolve(__dirname, '../../packages/iconify-collections/assets')
const generateDir = async (currentPath) => {
try {
@@ -32,8 +33,8 @@ const processSvgStructure = (svgStructure, replaceFillOrStrokeColor) => {
})
}
}
const generateSvgComponent = async (fileHandle, entry, pathList, replaceFillOrStrokeColor) => {
const currentPath = path.resolve(iconsDir, 'src', ...pathList.slice(2))
const generateSvgComponent = async (fileHandle, entry, relativeSegments, replaceFillOrStrokeColor) => {
const currentPath = path.resolve(iconsDir, 'src', ...relativeSegments)
try {
await access(currentPath)
@@ -86,8 +87,8 @@ export { default as <%= svgName %> } from './<%= svgName %>'
await appendFile(path.resolve(currentPath, 'index.ts'), `${indexingRender({ svgName: fileName })}\n`)
}
const generateImageComponent = async (entry, pathList) => {
const currentPath = path.resolve(iconsDir, 'src', ...pathList.slice(2))
const generateImageComponent = async (entry, relativeSegments) => {
const currentPath = path.resolve(iconsDir, 'src', ...relativeSegments)
try {
await access(currentPath)
@@ -107,7 +108,7 @@ const generateImageComponent = async (entry, pathList) => {
}
`.trim())
await writeFile(path.resolve(currentPath, `${fileName}.module.css`), `${componentCSSRender({ assetPath: path.posix.join('~@/app/components/base/icons/assets', ...pathList.slice(2), entry) })}\n`)
await writeFile(path.resolve(currentPath, `${fileName}.module.css`), `${componentCSSRender({ assetPath: path.posix.join('~@/app/components/base/icons/assets', ...relativeSegments, entry) })}\n`)
const componentRender = template(`
// GENERATE BY script
@@ -141,8 +142,8 @@ export { default as <%= fileName %> } from './<%= fileName %>'
await appendFile(path.resolve(currentPath, 'index.ts'), `${indexingRender({ fileName })}\n`)
}
const walk = async (entry, pathList, replaceFillOrStrokeColor) => {
const currentPath = path.resolve(...pathList, entry)
const walk = async (basePath, entry, relativeSegments, replaceFillOrStrokeColor) => {
const currentPath = path.resolve(basePath, ...relativeSegments, entry)
let fileHandle
try {
@@ -153,14 +154,14 @@ const walk = async (entry, pathList, replaceFillOrStrokeColor) => {
const files = await readdir(currentPath)
for (const file of files)
await walk(file, [...pathList, entry], replaceFillOrStrokeColor)
await walk(basePath, file, [...relativeSegments, entry], replaceFillOrStrokeColor)
}
if (stat.isFile() && /.+\.svg$/.test(entry))
await generateSvgComponent(fileHandle, entry, pathList, replaceFillOrStrokeColor)
await generateSvgComponent(fileHandle, entry, relativeSegments, replaceFillOrStrokeColor)
if (stat.isFile() && /.+\.png$/.test(entry))
await generateImageComponent(entry, pathList)
await generateImageComponent(entry, relativeSegments)
}
finally {
fileHandle?.close()
@@ -169,7 +170,7 @@ const walk = async (entry, pathList, replaceFillOrStrokeColor) => {
(async () => {
await rm(path.resolve(iconsDir, 'src'), { recursive: true, force: true })
await walk('public', [iconsDir, 'assets'])
await walk('vender', [iconsDir, 'assets'], true)
await walk('image', [iconsDir, 'assets'])
await walk(svgAssetsDir, 'public', [], false)
await walk(svgAssetsDir, 'vender', [], true)
await walk(path.resolve(iconsDir, 'assets'), 'image', [], false)
})()